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

 



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

Choose your language

Setup Your Project

Open up a new project in Visual Studio.





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;



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


[Test, Parallelizable]
public void SimpleTest(string browser, string version, string platform)
{
Uri commandExecutorUri = new Uri("http://ondemand.saucelabs.com/wd/hub");
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);
_Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
// navigate to the page under test
_Driver.Navigate().GoToUrl("https://testguild.com/SeleniumTestPage.html");
// verify the page title is correct
Assert.Contains(_Driver.Title, "Selenium WebDriver Validation");
_Driver.Quit();
}