PUNit Automated Testing

PNUnit is an expansion to the NUnit framework. The "P" stands for "Parallel" which 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

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("http://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:


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

Configuring capabilities

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


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


1. Select a Platform
2. Select a Browser


Testing Internal/Staged 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 Java WebDriver test with our Tunnel:


1. Download our tunnel and start the tunnel:

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 securily through the tunnel to TestingBot and back:


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("http://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();
        }
    }
  }
}

Other Options

We offer many other test options, for example: disable video recording, specifying a custom Firefox Profile, loading Chrome/Firefox/Safari extensions, running an executable before your test starts, uploading files, ...
See our list of test options for a full list of options to customize your tests.

Pick a C# Test Framework

  • 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.