views:

616

answers:

2

I have an issue with watin test that should browse for pdf and upload it to a web page. This test runs smoothly on my machine, always find pdf, click submit and wait 30 sec for upload completed.

But when I try to run this test on build machine (teamcity), happens that test hang at the point when it should wait for upload. The problem is that test don't timeout, even if I set timeout at nunit on 1 minute for whole test, or trying to reload page. The test just froze whole site at upload step.

Testing this functionality is really important, but since those tests with uploading hang whole build we have to do it manually and that isn't really out idea of test automation.

Does anyone have idea how to solve this upload problem? Or at least manage to timeout this test.

stack trace = at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
  at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
  at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
  at mshtml.DispHTMLBaseElement.click()
  at WatiN.Core.InternetExplorer.IEElement.ClickOnElement()
  at WatiN.Core.Element.Click()
  at WatiN.Core.FileUpload.Set(String fileName)
+1  A: 

I think the problem here is that your unit test depends on too many external resources, such as your the file system of your development machine, the network, etc.

Ask yourself what the importance of the test is: is there any business logic involved you can put into a separate class? Then you can write tests for this class. What you basically need is to test all the logic of the upload process without actually uploading a file or going to the network.

Gerrie Schenck
But WATiN is for regression testing, not unit testing. Your point is valid for unit testing, but regression tests are going to depend on external resources.
Leslie
+1  A: 

The issue was that WatiN used sendkeys to set the file(name) to upload. In WatiN 2.0 beta 1 this is changed to using some API calls. This solved the issue of hanging tests when automating a dialog which does require text input.

Jeroen van Menen