Header logo Open Menu Close Menu
  • Products
  • Developers
  • Enterprise
  • Pricing
  • Support
  • Products
      • Test your websites
      • Live
        Interactive cross browser testing
      • Automate
        Selenium testing at scale
      • Test your mobile apps
      • App Live
        Interactive native & hybrid app testing
      • App Automate
        Test automation for native & hybrid mobile apps
      • Tools
      • Screenshots
      • Responsive
  • Developers
  • Enterprise
  • Pricing
  • Support
  • Sign in
  • Free Trial
  • Products
  • Test your websites
  • Live
    Interactive cross browser testing
  • Automate
    Selenium testing at scale
  • Test your mobile apps
  • App Live
    Interactive native & hybrid app testing
  • App Automate
    Test automation for native & hybrid mobile apps
  • Tools
  • Screenshots
  • Responsive
  • Get help
  • Documentation
  • NodeJS
  • Java
  • Python
  • C#
  • Ruby
  • Perl
  • PHP
  • WebdriverIO
  • Protractor
  • Nightwatch
  • JUnit
  • JavaScript testing
  • Test dev environments
  • Jenkins
  • References
  • Selenium Capabilities
  • Browsers & Devices
  • Continuous Integration (CI)
  • REST API

Documentation Automate MBUnit

MBUnit

Documentation for running Selenium Tests with BrowserStack.

Getting Started

Note: Refer our sample repo on Github: mbunit-browserstack

BrowserStack supports Selenium automated tests using MBUnit, and running your tests on our cloud setup is simple and straightforward. Get started with a sample test, which opens Google's homepage, searches for ‘BrowserStack’, and asserts for the title of the search results page. For the code to run successfully on your machine, please ensure that the following libraries have been installed:

Install mbunit using NuGet Gallery

Here is a sample test case written for running with MBUnit.

[TestFixture]
public class SingleTest : BrowserStackMBUnitTest
{
  public SingleTest() : base("single", "chrome") { }

  [Test]
  public void SearchGoogle()
  {
    driver.Navigate().GoToUrl("https://www.google.com/ncr");
    IWebElement query = driver.FindElement(By.Name("q"));
    query.SendKeys("BrowserStack");
    query.Submit();
    System.Threading.Thread.Sleep(5000);
    Assert.AreEqual("BrowserStack - Google Search", driver.Title);
  }
}

To actually run the test case, we need to integrate with BrowserStack as follows.

Integration with BrowserStack

Note: Running your MBUnit tests on BrowserStack requires a username and an access key.

To obtain your username and access keys, sign up for a Free Trial or purchase a plan.

Integration of MBUnit with BrowserStack is made possible by use of following module:

[TestFixture]
public class BrowserStackMBUnitTest
{
  protected IWebDriver driver;
  protected string profile;
  protected string environment;
  private Local browserStackLocal;

  public BrowserStackMBUnitTest(string profile, string environment = "chrome")
  {
    this.profile = profile;
    this.environment = environment;
  }

  [FixtureSetUp]
  public void Init()
  {
    NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection;
    NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection;

    DesiredCapabilities capability = new DesiredCapabilities();

    foreach (string key in caps.AllKeys)
    {
      capability.SetCapability(key, caps[key]);
    }

    foreach (string key in settings.AllKeys)
    {
      capability.SetCapability(key, settings[key]);
    }

    String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
    if(username == null)
    {
      username = ConfigurationManager.AppSettings.Get("user");
    }

    String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
    if (accesskey == null)
    {
      accesskey = ConfigurationManager.AppSettings.Get("key");
    }

    capability.SetCapability("browserstack.user", username);
    capability.SetCapability("browserstack.key", accesskey);

    if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
    {
      browserStackLocal = new Local();
      List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
        new KeyValuePair<string, string>("key", accesskey)
      };
      browserStackLocal.start(bsLocalArgs);
    }

    driver = new RemoteWebDriver(new Uri("http://"+ ConfigurationManager.AppSettings.Get("server") +"/wd/hub/"), capability);
  }

  [FixtureTearDown]
  public void Cleanup()
  {
    driver.Quit();
    if (browserStackLocal != null)
    {
      browserStackLocal.stop();
    }
  }
}

The module reads from config file where you need to put the BrowserStack Hub URL and credentials.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="capabilities">
      <section name="single" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>

    <sectionGroup name="environments">
      <section name="chrome" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>
  </configSections>

  <appSettings>
    <add key="user" value="USERNAME" />
    <add key="key" value="ACCESS_KEY" />
    <add key="server" value="hub-cloud.browserstack.com" />
  </appSettings>

  <capabilities>
    <single>
      <add key="browserstack.debug" value="true" />
    </single>
  </capabilities>

  <environments>
    <chrome>
      <add key="browser" value="chrome" />
    </chrome>
  </environments>
</configuration>

Run your test on BrowserStack using following command:

Build the solution in Visual Studio 2010 SP1
Run test with fixture "single" from Test Explorer

Testing on Internal Networks

To test a private server with MBUnit on BrowserStack, install local bindings.

Install BrowserstackLocal using NuGet Gallery

Then update config file and set the browserstack.local capability to true.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="capabilities">
      <section name="local" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>

    <sectionGroup name="environments">
      <section name="chrome" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>
  </configSections>

  <appSettings>
    <add key="user" value="USERNAME" />
    <add key="key" value="ACCESS_KEY" />
    <add key="server" value="hub-cloud.browserstack.com" />
  </appSettings>

  <capabilities>
    <local>
      <add key="browserstack.local" value="true" />
    </local>
  </capabilities>

  <environments>
    <chrome>
      <add key="browser" value="chrome" />
    </chrome>
  </environments>
</configuration>

Here is a sample test case written for running local with MBUnit.

[TestFixture]
public class LocalTest : BrowserStackMBUnitTest
{
  public LocalTest() : base("local", "chrome") { }

  [Test]
  public void HealthCheck()
  {
    driver.Navigate().GoToUrl("http://bs-local.com:45691/check");
    Assert.IsTrue(Regex.IsMatch(driver.PageSource, "Up and running", RegexOptions.IgnoreCase));
  }
}

Run your local test on BrowserStack using following command:

Build the solution in Visual Studio 2010 SP1
Run test with fixture "local" from Test Explorer

Speed up testing

To run tests on multiple browsers in parallel with JBehave on BrowserStack, modify the config file as below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="capabilities">
      <section name="parallel" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>

    <sectionGroup name="environments">
      <section name="chrome" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <section name="firefox" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <section name="safari" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <section name="ie" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </sectionGroup>
  </configSections>

  <appSettings>
    <add key="user" value="BROWSERSTACK_USERNAME" />
    <add key="key" value="BROWSERSTACK_ACCESS_KEY" />
    <add key="server" value="hub-cloud.browserstack.com" />
  </appSettings>

  <capabilities>
    <parallel>
      <add key="browserstack.debug" value="true" />
    </parallel>
  </capabilities>

  <environments>
    <chrome>
      <add key="browser" value="chrome" />
    </chrome>
    <firefox>
      <add key="browser" value="firefox" />
    </firefox>
    <safari>
      <add key="browser" value="safari" />
    </safari>
    <ie>
      <add key="browser" value="ie" />
    </ie>
  </environments>
</configuration>

Capabilities for each environment can be customised as explained earlier.

Run your tests in parallel on BrowserStack using following command:

Build the solution in Visual Studio 2010 SP1
Run tests with fixture "parallel" from Test Explorer

Note: Achieve your test coverage and build execution time goals by using our calculator to understand how many parallel sessions you need.

Configuring capabilities

To run your tests on BrowserStack Automate, the tests have to be run on remote machines. Therefore, the capabilities of the WebDriver have to be changed accordingly.

Run tests on desktop and mobile browsers

Using the drop-down menus, select a combination of operating system, browser, and screen resolution. To see the order of precedence for the capabilities, please read about parameter override rules here.

You can additionally run your Selenium test scripts on real Android and iOS devices in our datacenters.

Look for the icon to select a real device.

1. Select an OS
iOS
Mobile
  • iOS
  • Android
Desktop
  • Windows 10
  • Windows 8.1
  • Windows 8
  • Windows 7
  • Windows XP
  • OS X Mojave
  • OS X High Sierra
  • OS X Sierra
  • OS X El Capitan
  • OS X Yosemite
  • OS X Mavericks
  • OS X Mountain Lion
  • OS X Lion
  • OS X Snow Leopard
2. Select a browser
Windows XP
2. Select a device
iOS
3. Select a resolution
1024 x 768
Resolution

    Note: Testing on real devices requires the Automate Mobile plan

    <environments>
      <bs>
        <add key="os" value="Windows" />
        <add key="os_version" value="7" />
        <add key="browser" value="IE" />
        <add key="browser_version" value="8.0" />
        <add key="resolution" value="1024x768" />
      </bs>
    </environments>
    
    <environments> <bs> <add key="os" value="Windows" /> <add key="os_version" value="7" /> <add key="browser" value="IE" /> <add key="browser_version" value="8.0" /> <add key="resolution" value="1024x768" /> </bs> </environments>
    <environments> <bs> <add key="browserName" value="iPhone" /> <add key="platform" value="MAC" /> <add key="device" value="iPhone 5" /> </bs> </environments>
    <environments> <bs> <add key="device" value="iPhone 5" /> <add key="realMobile" value="true" /> <add key="os_version" value="9.0" /> </bs> </environments>

    Note: If browser_version capability is not set, the test will run on the latest version of the browser set by browser capability.

    For a list of all supported devices, visit the Browsers and Platforms page.

    Builds and projects

    Keep track of all your automated tests using the build and project capabilities. Group your tests into builds, and builds further into projects.

    <capabilities>
      <single>
        <add key="build" value="version1" />
        <add key="project" value="newintropage" />
      </single>
    </capabilities>
    

    Note: Allowed characters include uppercase and lowercase letters, digits, spaces, colons, periods, and underscores. Other characters, like hyphens or slashes are not allowed.

    Self-signed certificates

    To avoid invalid certificate errors while testing on BrowserStack Automate, set the acceptSslCerts capability in your test to true.

    <capabilities>
      <single>
        <add key="acceptSslCerts" value="true" />
      </single>
    </capabilities>
    

    Enable and Disable Pop-ups

    IE

    To enable the popups in IE, use the browserstack.ie.enablePopups capability.

    <capabilities>
      <single>
        <add key="browserstack.ie.enablePopups" value="true" />
      </single>
    </capabilities>
    
    Safari

    To enable the popups in Safari, use the browserstack.safari.enablePopups capability.

    <capabilities>
      <single>
        <add key="browserstack.safari.enablePopups" value="true" />
      </single>
    </capabilities>
    

    Debugging

    Logs

    To debug failed tests, BrowserStack provides you with raw logs, which are the console logs from the browser tests; visual logs, which capture successive screenshots of the test; and text logs to display all the steps that were performed by the test.

    Live screencast

    With live screencast, view ongoing tests to debug the functionality of features that are being tested. The generated videos can be recorded and downloaded for later viewing.

    Logs and the live screencast help you to compare and detect any changes that may have occurred since a similar test was last run. Debugging is set to false by default. To enable logs, set the BrowserStack custom capability browserstack.debug to true.

    <capabilities>
      <single>
        <add key="browserstack.debug" value="true" />
      </single>
    </capabilities>
    
    Video recording

    Videos are recorded for every BrowserStack Automate test. This feature helps you to verify and debug failed tests, confirm the functionality of tested features, and download videos for later viewing.

    Note: Video recording increases test execution time slightly. You can disable this feature by setting the browserstack.video capability to false.

    <capabilities>
      <single>
        <add key="browserstack.video" value="false" />
      </single>
    </capabilities>
    

    Other capabilities

    BrowserStack supports the full complement of Selenium capabilities, as well as, some custom ones.

    Additional Notes

    REST API

    It is possible to mark tests as either a pass or a fail, using the following snippet:

    namespace RestApi {
      class ChangeSessionStatus {
        static void Main(string[] args) {
          string reqString = "{\"status\":\"completed\", \"reason\":\"\"}";
    
          byte[] requestData = Encoding.UTF8.GetBytes(reqString);
          Uri myUri = new Uri(string.Format("https://www.browserstack.com/automate/sessions/<session-id>.json"));
          WebRequest myWebRequest = HttpWebRequest.Create(myUri);
          HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;
          myWebRequest.ContentType = "application/json";
          myWebRequest.Method = "PUT";
          myWebRequest.ContentLength = requestData.Length;
          using (Stream st = myWebRequest.GetRequestStream())st.Write(requestData, 0, requestData.Length);
    
          NetworkCredential myNetworkCredential = new NetworkCredential("USERNAME", "ACCESS_KEY");
          CredentialCache myCredentialCache = new CredentialCache();
          myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
          myHttpWebRequest.PreAuthenticate = true;
          myHttpWebRequest.Credentials = myCredentialCache;
    
          myWebRequest.GetResponse().Close();
        }
      }
    }

    The two potential values for status can either be completed or error. Optionally, a reason can also be passed.

    Queuing

    With queuing, you can launch an additional number of parallel tests with different browser configurations that will be queued in a sequence, for a seamless parallel execution. For instance, if you want to run 5 additional tests, apart from your subscribed limit of 2 parallel tests, BrowserStack will queue the additional 5 tests until one of the 2 initial tests finish, and a slot is available for execution. With queuing, you can be less bothered about managing your tests, and it can save development time.

    With this feature, accounts up to 5 parallel tests can queue 5 tests. Beyond 5 parallel tests, an equivalent number of tests will be queued.

    Note: The wait limit for the execution of a pending queued job is 15 minutes and will be cancelled if exceeded.

    We have provided examples of parallel testing implementation using popular testing frameworks. In order to increase the number of tests, purchase more parallel tests of your Automate or Automate Pro plan to get access to more tests.

    In This Article

    • Getting Started
    • Integration with BrowserStack
    • Testing on Internal Networks
    • Speed up testing
    • Configuring Capabilities
      • Run tests on desktop and mobile browsers
      • Builds and projects
      • Self-signed certificates
      • Enable and Disable Pop-ups
      • Debugging
      • Other capabilities
    • Additional Notes
      • REST API
      • Queuing

    Languages & Frameworks

    C#

    NUnit

    PNUnit

    SpecFlow

    Related Articles

    Debugging Tools

    Browsers & Devices

    Capabilities

    Timeouts

    REST API

    JS Testing

    Local Testing

    Continuous Integration

    Travis CI

    TeamCity

    Products
    • Live
    • Automate
    • App Live New
    • App Automate New
    • Screenshots
    • Responsive
    • Enterprise
    Mobile
    • Test on Right Devices
    • Mobile Features
    • Mobile Emulators
    • Test on iPhone
    • Test on iPad
    • Test on Galaxy
    • Android testing
    • iOS testing
    Other Links
    • Open Source
    • Test in IE
    • Careers We're hiring!
    • Support
    • Contact
    • Company
    • News
    Knowledge
    • Selenium
    Social
    Header logo

    © 2011-2019 BrowserStack - The Most Reliable Mobile App & Browser Testing Company

    • Terms of Service
    • Privacy Policy
    • Cookie Policy

    We use cookies to enhance user experience, analyze site usage, and assist in our marketing efforts. By continuing to browse or closing this banner, you acknowledge that you have read and agree to our Cookie Policy, Privacy Policy and Terms of Service.