开发者

Using WatiN through MbUnit to test ASP .Net MVC web application

开发者 https://www.devze.com 2022-12-11 07:18 出处:网络
I am trying to apply some WatiN UI tests to my new ASP .Net MVC application, running the WatiN tests through MbUnit, but am having some difficulties.

I am trying to apply some WatiN UI tests to my new ASP .Net MVC application, running the WatiN tests through MbUnit, but am having some difficulties.

If I follow the instructions (exactly) on this page, then the google homepage loads, up the text is inserted, the search is done and the test passes. (no problem here).

However, when I simply change the URL of the line...

var ie = new IE(new Uri("http://www.google.co.uk"));

to the website hosted on my PC through IIS (on Win7), (e.g. to http://localhost/myapp/) the homepage of my application loads fine, but the test-runner seems to still be waiting for confirmation that the page has loaded and then the test fails due to a timeout.

Here's the failed response from within the IDE...

*** Failures ***
Exception
WatiN.Core.Exceptions.TimeoutException: Timeout while Internet Explorer state not complete
   at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.ThrowTimeOutException(Exception lastException, String message)
   at WatiN.Core.开发者_高级运维UtilityClasses.TryFuncUntilTimeOut.HandleTimeOut()
   at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.Try[T](DoFunc`1 func)
   at WatiN.Core.WaitForCompleteBase.WaitUntil(DoFunc`1 waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
   at WatiN.Core.Native.InternetExplorer.WaitForComplete.WaitWhileIEReadyStateNotComplete(IWebBrowser2 ie)
   at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.DoWait()
   at WatiN.Core.DomContainer.WaitForComplete(IWait waitForComplete)
   at WatiN.Core.IE.WaitForComplete(Int32 waitForCompleteTimeOut)
   at WatiN.Core.DomContainer.WaitForComplete()
   at WatiN.Core.Browser.GoTo(Uri url)
   at WatiN.Core.IE.FinishInitialization(Uri uri)
   at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
   at WatiN.Core.IE..ctor(Uri uri)
   at FppRendersUI.Test.Program.DoSomething() in C:\Dev\MyCode.Test\Program.cs:line 18

Anybody else get this, or is it just me?


There should be no significant differences testing a website on locahost.

Two possible causes:

  1. If your webpage contains any significant AJAX then it's possible that the page never appears to be fully loaded so WatiN just keeps waiting.

  2. I have fixed one or two bugs in WatiN now and then related to detecting that a page has been fully loaded. You might try grabbing the WatiN trunk source and building a fresh copy of the latest code.

If none of that helps, WatiN also has "NoWait" variants of several actions like clicking. You can also override what it means to WatiN to wait for a page to be complete by registering a WaitForComplete handler.


I've had this happen to me when I had a reference to a resource that didn't load.

  • Do have a reference to a JS, CSS, or image file that doesn't exist?
  • If you look at the HTTP traffic with Fiddler do you see any connections timing out?


Make sure the program is running as an administrator. On Win7 it will load the page but Watin can't access the DOM unless Visual Studio or Gallio Icarus are started with administrator privileges.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号