Search code examples
.netnunitwatin

How to test a Web Service with Watin


I'm trying to write a test that invokes a web service and tests it's results.

[Test]
        public void should_display_correct_customer_when_DoCustomerSearch_is_invoked()
        {
            using (var browser = new IE("http://localhost:61245/WebServices/CustomerSearch.asmx?op=DoCustomerSearch"))
            {       
                browser.WaitForComplete();

                browser.TextField(Find.ByName("txtSearch")).TypeText("microsoft");
                browser.Button(Find.ByValue("Invoke")).Click();
                browser.Close();

                IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl("http://localhost:61245/WebServices/CustomerSearch.asmx/DoCustomerSearch"));

                poppedUpBrowser.WaitForComplete();
                Assert.IsTrue(poppedUpBrowser.ContainsText("Microsoft Corporation"));                
            } 
        }

When I invoke the service through the browser, the results are displayed but when watin runs through the same test, the results page has a 500 server error.

Any help appreciated please.


Solution

  • Are you trying to test Web Service through WatiN?

    There are better ways to do that: you should rather test your logic in unit / integration tests. Those tests will execute much faster than WatiN.

    The HTTP 500 is returned by your web service - there is probably an exception being thrown from your code - check your logs or attach a debugger.