How to run a .NET C# Test in Sauce Labs

Automation Testing Published on:

I recently received the following email:

“I have gone through your video on How to run a Selenium Web driver test case with Sauce Labs but it was for Java. Can you please show [us] how to do the same using the Selenium C# .NET binding?” So today I'm going to show you how to run a C# Selenium script in Sauce labs.

For those of you that aren't aware, Sauce Labs is the exclusive sponsor of my TestTalks podcast. Accordingly, I have a special code you can use to get 20 hours of free automation! Check out my SauceLabs page for more info.

Getting Started with Sauce Labs C Sharp

  • First, log on to SauceLabs with your free account. (Check out my video on how to use my special SauceLabs promo offer.)

  • Under the Tools section, select the Getting Started button.


  • You'll be presented with three options:
    • Automated
    • Mobile
    • Manual

  • Select Automated

Now, all you need to do is follow this quick, four-step process:

Choose your language

  • For this example, I'll be using C#.NET, but Sauce Labs supports all the Selenium language bindings.
  • Select the C#.NET option.

Setup Your Project

Open up a new project in Visual Studio.

  • In the New Project screen, select a C# Class Library template.

  • Name the project ExampleSauce and click OK.
  • From the VST menu, choose Tools>Library Package Manager> Manage Nuget Package for Solution.
  • In the Manage NuGet Packages screen, enter Selenium in the Search packages field.

  • Click on the Install button for the Selenium WebDriver. Once it's installed, do the same for Selenium WebDriver Support Classes.
  • Next, search for Gallio and install Gallio & MbUnit.

  • And Gallio Bundle

  • Click Close in the Manage NuGet Packages window.

Start writing the C# tests

At the top under the using statements, add:

using Gallio.Framework;
using Gallio.Model;
using MbUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

  • In the RunInSauce project right before Class1, add the following:

[Header("browser", "version", "platform")]
[Row("chrome", "42", "Windows 7")]
[Row("chrome", "35", "linux")]

  • Under the Class1 section, let's add a method named SimpleTest and our test code. (This is for demonstration purposes only — there are better ways of doing this.)
[Test, Parallelizable]
public void SimpleTest(string browser, string version, string platform)
Uri commandExecutorUri = new Uri("");
DesiredCapabilities desiredCapabilites = new DesiredCapabilities(browser, version, Platform.CurrentPlatform);
desiredCapabilites.SetCapability("platform", platform);
desiredCapabilites.SetCapability("username", "yourseleniumusername");
desiredCapabilites.SetCapability("accessKey", "yourseleniumaccesskey");
desiredCapabilites.SetCapability("name", TestContext.CurrentContext.Test.Name);
var _Driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilites);
// navigate to the page under test
// verify the page title is correct
Assert.Contains(_Driver.Title, "Selenium WebDriver Validation");
  • Right click on the ExampleSauce project and select Properties.
  • Click on Debug.
  • Click on Start external program and navigate to Gallio.Icarus.exe in your VST projects packages>GallioBundle.>bin directory. Mine was in:




  • Under the Command line arguments, enter the name of your namespace.dll

  • Click on F5 to build and debug the solution.
  • The Gallio Icarus runner will appear where you can run your tests.
  • Click on the Start button.

  • Your test should run and pass. You can tell by looking in the Gallio Test Report Execution Log tab:

  • You should also see the results when you login to Sauce Labs.

  • Clicking on each Session will bring up each individual run's execution results, where you can see step-by-step results and timings as well as video playback.


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. This was really useful, we are about to release a new product to the market and is really important for us to test how it behaves on the most used web browsers.

    Thanks a lot!


  2. It looks like the gallio framework can not be installed when .net framework 4.6.1 is being used. I suggest you rewrite this maybe for users to use nunit 3.. I got it working with the example on sauce lab with some minor changes (notably the status check that it passed was outdated syntax with < nunit 3) . But would be nice to have an example with running with multiple browsers. Their example only had textfixture with one.

  3. Hi there!
    How to resolve this error?
    I’m trying to add following package in VS project.

    Error: Could not install package ‘GallioBundle 3.4.14’. You are trying to install this package into a project that targets ‘.NETFramework,Version=v4.5.2’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0

    Need quick solution, please tell the solution ASAP.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Latest Automation Trends: Top 13 Predictions for 2023

Posted on 01/04/2023

Welcome to my annual Latest Automation Trends: Top 13 Predictions for 2023 article. ...

Chrome Selenium Driver in Visual Studio C#

Posted on 12/21/2022

I'm sure you've all heard of Selenium by now. It's a popular tool ...

15 Reasons Why You Should (or shouldn’t) Automate a Test

Posted on 12/20/2022

Just because you can automate tests doesn’t necessarily mean that you should. In ...