开发者

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

开发者_开发知识库

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


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: -

  • Install Visual NUnit
  • Install Gallio (which will integrate and is good for reporting)
  • Run your tests externally (which can be done through VS)

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!

EDIT Added link for Visual NUnit extension for VS2010


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());
    }
}


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜