Features

C# Automated Testing with MSTest

MSTest framework is a test framework which is included, by default, with Microsoft Visual Studio.
It is also referred to as Visual Studio Unit Testing Framework and is popular with developers using the Visual Studio IDE.


MSTest V2 is open-sourced and available on GitHub.
With MSTest V2 you can easily run tests in parallel, using In-Assembly Parallel (via Annotations or RunSettings).

Installation

To get started with MSTest, you'll need to make sure that MSTest Framework and MSTest Adapter are installed.


You can install the packages via the commandline or with NuGet:

  • MSTest.TestAdapter
  • MSTest.TestFramework
  • Microsoft.NET.Test.Sdk

Your first MSTest test

Please see the example test below, using MSTest.
The test will start 3 browsers, visit our homepage and print the title.


SingleTest.cs:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
 
[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)]
 
namespace MS_Test_Cross_Browser
{
    IWebDriver driver;
    String key = "key";
    String secret = "secret";

    DesiredCapabilities capabilities;

    [TestInitialize]
    public void setupInit()
    {
        capabilities = new DesiredCapabilities();

        capabilities.SetCapability("key", key);
        capabilities.SetCapability("secret", secret);
    }

    [DataTestMethod]
    [DataRow("chrome", "latest", "Windows 10")]
    [DataRow("MicrosoftEdge", "latest-1", "Windows 10")]
    [DataRow("Firefox", "latest", "BIGSUR")]

    [TestMethod]
    public void Single_Test(String browser, String version, String os)
    {
        capabilities.SetCapability("browserName", browser);
        capabilities.SetCapability("version", version);
        capabilities.SetCapability("platform", os);
        capabilities.SetCapability("name", "MsTest with TestingBot");

        driver = new RemoteWebDriver(new Uri("https://" + username + ":" + accesskey + "@hub.testingbot.com"), capabilities, TimeSpan.FromSeconds(20000));

        driver.Url = "https://testingbot.com";

        /* Perform wait to check the output */
        System.Threading.Thread.Sleep(2000);

        Console.WriteLine(driver.Title);
   }
}

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.


IWebDriver driver;
DesiredCapabilities desiredCap = new DesiredCapabilities();
desiredCap.SetCapability("key", "key");
desiredCap.SetCapability("secret", "secret");

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

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



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

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

Run tests in Parallel

Parallel Testing means running the same test, or multiple tests, simultaneously. This greatly reduces your total testing time.

You can run the same tests on all different browser configurations or run different tests all on the same browser configuration.
TestingBot has a large grid of machines and browsers, which means you can use our service to do efficient parallel testing. It is one of the key features we provide to greatly cut down on your total testing time.


To modify the number of parallel tests with MSTest, please use the Parallelize annotation:

[assembly: Parallelize(Workers = 5, Scope = ExecutionScope.MethodLevel)]
This will run the test on 5 workers (= 5 parallel sessions).

Queuing

Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

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:

[TearDown]
public void CleanUp()
{
    bool passed = true || false;
    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.