Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing with WatiN and NUnit

It seems that the common theme among SO questions regarding WatiN have to do with actually getting the thing working and I'm no exception.

I've downloaded the latest release of WatiN (2.0.20.1089) and am trying to create the NUnit / WatiN equivalent of Hello, World:

using WatiN.Core;
using NUnit.Framework;

namespace Foo.Browser.Tests
{
    [TestFixture]
    public class BrowserTests
    {
        [Test]
        [STAThread]
        public void ExampleTest()
        {

            IE ie = new IE("http://www.google.com");

            ie.TextField(Find.ByName("q")).TypeText("WatiN");
            ie.Button(Find.ByValue("Google Search")).Click();
            Link link = ie.Link(Find.ByUrl("http://watin.sourceforge.net/"));

            Assert.That(link.Text == "WatiN Home");
        }

        [Test]
        public void FirefoxTest()
        {
            FireFox ff = new FireFox("http://www.google.com");

            ff.TextField(Find.ByName("q")).TypeText("WatiN");

            ff.Button(Find.ByValue("Google Search")).Click();
            Link link = ff.Link(Find.ByUrl("http://watin.sourceforge.net/"));

            Assert.That(link.Text == "WatiN Home");
        }
    }

This tips IE(8) over after an eventual timeout with the following stack trace:

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.IEWaitForComplete.WaitWhileFrameDocumentNotAvailable(IWebBrowser2 frame) at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForFramesToComplete(IHTMLDocument2 maindocument) at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForFramesToComplete(IHTMLDocument2 maindocument) at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForCompleteOrTimeout() at WatiN.Core.WaitForCompleteBase.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(String url) at Foo.Browser.Tests.BrowserTests.ExampleTest() in C:\Development\Foo\Foo.Browser.Tests\BrowserTests.cs:line 19

I have the requisite config file in my bin\debug folder (Foo.Browser.Tests.dll.config) as specified on the WatiN documentation page, so what else is it likely to be? Does anyone have any suggestions for what might be causing the problem?

like image 235
Phil.Wheeler Avatar asked Jan 19 '10 23:01

Phil.Wheeler


People also ask

How do you use unit testing in NUnit?

Creating the first testSave this file and execute the dotnet test command to build the tests and the class library and run the tests. The NUnit test runner contains the program entry point to run your tests. dotnet test starts the test runner using the unit test project you've created.

Which is better NUnit or MSTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.

How do I write a unit test case in NUnit?

To mark a method as a test case, we need to add a Test attribute. It tells the NUnit framework that it should run this method. It's a good approach to run our test methods with different arguments, without copy-pasting our test methods. We can define test method parameters by using the [TestCase] attribute.

What type of testing does NUnit support?

NUnit is an open-source unit testing framework for the . NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.


1 Answers

Phil,

Have a look at the InnerException of the thrown TimeoutExcepetion. This will most probably contain more info to solve your issue.

HTH Jeroen van Menen Lead dev WatiN

like image 135
Jeroen van Menen Avatar answered Nov 13 '22 13:11

Jeroen van Menen