21258

WatiN:How to use the automated test run result as I am unable to get the way of Reporting the result

Question:

I have automated a module with WATIN and now I want the test result to be displayed as PASS/FAIL status etc(REPORTING), Is there any functionality in Watin to do my required action.

Like I have a code like

public static void TestSelectPatientLink() { try { Link lnkSelectPatientb = ie.Link(Find.ByTitle("Search patient")); lnkSelectPatientb.Blur(); lnkSelectPatientb.ClickNoWait(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }

How to get the report as what happened when this code runs in VS 2010, Is it failing or passing, If it fails, the error etc, How to report these things.

**FYI I am using Nunit with WatiN

Answer1:

No, there isn't any functionality built into WatiN to support this, but GarethStephenson's post was correct. You can write an NUnit test that will give you a pass/fail.

First of all, for IE to work with NUnit you need to add the following to your app.config

<configSections> <sectionGroup name="NUnit"> <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/> </sectionGroup> </configSections> <NUnit> <TestRunner> <!-- Valid values are STA,MTA. Others ignored. --> <add key="ApartmentState" value="STA" /> </TestRunner> </NUnit>

Here's an example test. It loads up the google home page, grabs some elements and asserts they exist: -

using WatiN.Core; using NUnit.Framework; namespace ConsoleApplication1 { [TestFixture] public class AutomatedTests { [Test] public void DoGoogleTest() { using (IE browser = new IE()) { browser.GoTo("www.google.co.uk"); Div logoDiv = browser.Div("hplogo"); Assert.IsTrue(logoDiv.Exists, "Logo div does not exist"); TextField searchText = browser.TextField("lst-ib"); Assert.IsTrue(searchText.Exists, "Search text field does not exist"); Button searchBtn = browser.Button(Find.ByName("btnK")); Assert.IsTrue(searchBtn.Exists, "Search button does not exist"); Button nonExistantButton = browser.Button("garbagegarbagegarbage"); // This will cause the test to fail because the link doesn't (shouldn't!) exist. // Comment it out and the test should pass Assert.IsTrue(nonExistantButton.Exists, "Non-existant button does not exist"); } } } }

Unfortunately, NUnit doesn't automatically integrate with Visual Studios Test View/Test List windows. Your options are: -

<ul><li>Install <a href="http://www.bubblecloud.org/visualnunit" rel="nofollow">Visual NUnit</a></li> <li>Install <a href="http://www.gallio.org/" rel="nofollow">Gallio</a> (which will integrate and is good for reporting)</li> <li>Run your tests externally (<a href="http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/" rel="nofollow">which can be done through VS</a>)</li> </ul>

The above code gives me the result: -

ConsoleApplication1.AutomatedTests.DoGoogleTest: Non-existant button does not exist Expected: True But was: False

If you comment out the last line you get no errors reported.

If you need any more info then let me know. HTH!

<em><strong>EDIT</strong></em> Added link for Visual NUnit extension for VS2010

Answer2:

You could always convert that method into a Unit Test Method, using NUnit or the like.

[Test] public void TestSelectPatientLink() { try { Link lnkSelectPatientb = ie.Link(Find.ByTitle("Search patient")); lnkSelectPatientb.Blur(); lnkSelectPatientb.ClickNoWait(); } catch (Exception ex) { // Capture the error screen so you can see what went wrong ie.CaptureWebPageToFile("Error.jpg"); // Fail the test, use the unit testing framework's reporting to get your pass/fail Assert.Fail(ex.ToString()); } }

Answer3:

Subscribing to nunit events(testFinished, testStarted) may help. But it's requires developing addon for nunit Br /Vitalii

Recommend

  • Transfer Property ids (Array) to other TestCases in SoapUI/Groovy
  • How to use TestNG Listeners with Cucumber
  • SoapUI Groovy Script’s JSON Responses Is Empty When Using Testrunner
  • When I browse http://localhost:8004/elmah.axd, it generates 404 error
  • Configuring Log4NetLoggerFactoryAdapter Programmatically (Trying Again)
  • SoapUI defining a library of reusable methods
  • c# wcf hosted in windows service goes idle after 5 minutes
  • How to call .cshtml file directly with .cshtml extension from browser without using MVC
  • Need to understand - why CDATA section is treated as if the ?
  • No connection string named 'MyAppDbContext' could be found in the application config file
  • Elmah.MVC does not log errors in production environment
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • Aptana 3 remove bundle (jquery)
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Uncaught TypeError: $(…).select2 is not a function
  • req.body is undefined - nodejs
  • How to get a value (ex: baseURL) in every Karate feature?
  • SSO with signing and signature validation doesn't work
  • Symfony2: How to get request parameter
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • Is there a mandatory requirement to switch app.yaml?
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Proper folder structure for lots of source files
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How does Linux kernel interrupt the application?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal