Features

TestingBot does not recommend using PNUnit as the PNUnit project seems to be deprecated. Instead, you can use the NUnit parallel option which can run tests in parallel.

PUNit Automated Testing

PNUnit is an expansion to the NUnit framework. The "P" stands for "Parallel" and basically means that you can run several tests at the same time on our Selenium grid.

More information regarding PUNit is available on the PNUnit website.

It's really easy to convert your current NUnit Selenium tests to PNUnit Selenium Tests.

  • Modify your test to take parameters from a config file (browserName, version, platform, ...)
  • Create the config file (shown in the example below), specifying which browsers you want to test on.

Example code

Copy code
using NUnit.Framework;
using PNUnit.Framework;
using System;
using System.Web;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Test
{
  [TestFixture()]
  public class TestingBotTest
  {
    private IWebDriver driver;
    private string[] testParams;

    [SetUp]
    public void Init()
    {
      testParams = PNUnitServices.Get().GetTestParams();
      String params1 = String.Join(",", testParams);
      Console.WriteLine(params1);
      String browser = testParams[0];
      String version = testParams[1];
      String os = testParams[2];
      DesiredCapabilities capability =  new DesiredCapabilities();
      capability.SetCapability("browserName", browser);
      capability.SetCapability(CapabilityType.Version, version);
      capability.SetCapability("platform", os);
      capability.SetCapability("api_key", "api_key");
      capability.SetCapability("api_secret", "api_secret");

      Console.WriteLine("Capabilities" + capability.ToString());

      driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub/"), capability);
    }


    [Test]
    public void TestCase()
    {
      driver.Navigate().GoToUrl("https://www.google.com");
      StringAssert.Contains("Google", driver.Title);
      IWebElement query = driver.FindElement(By.Name("q"));
      query.SendKeys("TestingBot");
      query.Submit();
    }

    [TearDown]
    public void CleanUp()
    {
        bool passed = TestContext.CurrentContext.Result.Status == TestStatus.Passed;
        try
        {
            // Logs the result to TestingBot
            ((IJavaScriptExecutor)driver).ExecuteScript("tb:test-result=" + (passed ? "passed" : "failed"));
        }
        finally
        {
            // Terminates the remote webdriver session
            driver.Quit();
        }
    }
  }
}

Now we have to tell PNunit which parameters we want to send with the test:

Copy code
<TestGroup>
  <ParallelTests>
      <ParallelTest>
        <Name>Testing</Name>
        <Tests>
          <TestConf>
            <Name>TestFF-Win8</Name>
            <Assembly>SeleniumTest.dll</Assembly>
            <TestToRun>Test.TestingBotTest.TestCase</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
                <string>firefox</string> <!--browserName -->
                <string>latest</string> <!-- version -->
                <string>WIN8</string><!-- os -->
            </TestParams>
          </TestConf>
          <TestConf>
            <Name>TestChrome-Win7</Name>
            <Assembly>SeleniumTest.dll</Assembly>
            <TestToRun>Test.TestingBotTest.TestCase</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
                <string>chrome</string> <!--browserName -->
                <string>latest</string> <!-- version -->
                <string>VISTA</string><!-- os -->
            </TestParams>
        </Tests>
      </ParallelTest>
    </ParallelTests>
  </TestGroup>

Specify Browsers & Devices

To let TestingBot know on which browser/platform/device you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.

Copy code
DesiredCapabilities capability =  new DesiredCapabilities();
capability.SetCapability("browserName", browser);
capability.SetCapability(CapabilityType.Version, version);
capability.SetCapability("platform", os);
capability.SetCapability("api_key", "api_key");
capability.SetCapability("api_secret", "api_secret");

To see how to do this, please select a combination of browser, version and platform in the drop-down menus below.

Copy code

Testing Internal Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.

The example below shows how to easily run a PNUnit test with our Tunnel:

1. Download our tunnel and start the tunnel:

Copy code
java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to 'hub.testingbot.com/wd/hub' like the example above - change it to point to your tunnel's IP address.
Assuming you run the tunnel on the same machine you run your tests, change to 'localhost:4445/wd/hub'. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.

This way your test will go securely through the tunnel to TestingBot and back:

Copy code
using NUnit.Framework;
using PNUnit.Framework;
using System;
using System.Web;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Test
{
  [TestFixture()]
  public class TestingBotTest
  {
    private IWebDriver driver;
    private string[] testParams;

    [SetUp]
    public void Init()
    {
      testParams = PNUnitServices.Get().GetTestParams();
      String params1 = String.Join(",", testParams);
      Console.WriteLine(params1);
      String browser = testParams[0];
      String version = testParams[1];
      String os = testParams[2];
      DesiredCapabilities capability =  new DesiredCapabilities();
      capability.SetCapability("browserName", browser);
      capability.SetCapability(CapabilityType.Version, version);
      capability.SetCapability("platform", os);
      capability.SetCapability("api_key", "api_key");
      capability.SetCapability("api_secret", "api_secret");

      Console.WriteLine("Capabilities" + capability.ToString());

      driver = new RemoteWebDriver(new Uri("http://localhost:4445/wd/hub/"), capability);
    }

    [Test]
    public void TestCase()
    {
      driver.Navigate().GoToUrl("https://www.google.com");
      StringAssert.Contains("Google", driver.Title);
      IWebElement query = driver.FindElement(By.Name("q"));
      query.SendKeys("TestingBot");
      query.Submit();
    }

    [TearDown]
    public void CleanUp()
    {
        bool passed = TestContext.CurrentContext.Result.Status == TestStatus.Passed;
        try
        {
            // Logs the result to TestingBot
            ((IJavaScriptExecutor)driver).ExecuteScript("tb:test-result=" + (passed ? "passed" : "failed"));
        }
        finally
        {
            // Terminates the remote webdriver session
            driver.Quit();
        }
    }
  }
}

Mark tests as passed/failed

To see if a test passed or not in our member area, or to send additional meta-data to TestingBot, you can use our API.

Please see the example below on how to notify TestingBot about the test success state:

Copy code
[TearDown]
public void CleanUp()
{
    bool passed = TestContext.CurrentContext.Result.Status == TestStatus.Passed;
    try
    {
        // Logs the result to TestingBot
        ((IJavaScriptExecutor)driver).ExecuteScript("tb:test-result=" + (passed ? "passed" : "failed"));
    }
    finally
    {
        // Terminates the remote webdriver session
        driver.Quit();
    }
}

Other C# Framework examples

  • NUnit

    An unit testing framework that is open source written in C#.

  • PNunit

    With PNUnit you can run several tests in parallel.

  • SpecFlow

    SpecFlow allows you to run Automated .NET tests using Cucumber-compatible Gherkin syntax.

  • MSTest

    MSTest framework is a test framework which is included, by default, with Microsoft Visual Studio.

  • MbUnit

    MbUnit is a generative test unit framework, built for C sharp testing.