Your guide to running Selenium Webdriver tests with C# on BrowserStack.
Introduction
BrowserStack gives you instant access to our Selenium Grid of 2000+ real devices and desktop browsers. Running your Selenium tests with C# on BrowserStack is simple. This guide will help you:
- Run a sample Selenium Webdriver test on BrowserStack
- Setup your environment to be able to test URLs in your internal network
- Understand and configure the core capabilities in your Selenium test suite
- Explore advanced features
Prerequisites
Before you can start running your Selenium tests with C#::
- Download the Selenium C# bindings from the Selenium website
- Extract the bindings and add them to relevant folder
Getting Started
To get started, let’s run a simple Selenium Webdriver test. The C# script below will open a URL, input a string, submit the form, and return the page title.
First, select the OS and Device/Browser combination you'd like to test on the using drop-down menus below. This will automatically update the C# code sample below:
1. Select an OS
2. Select a device
Look for the icon to select a real device.
using System; using OpenQA.Selenium; using OpenQA.Selenium.Remote; namespace SeleniumTest { class Program { static void Main(string[] args) { IWebDriver driver; DesiredCapabilities capability = new DesiredCapabilities(); capability.SetCapability("browserName", "iPhone"); capability.SetCapability("device", "iPhone 8 Plus"); capability.SetCapability("realMobile", "true"); capability.SetCapability("os_version", "11.0"); capability.SetCapability("browserstack.user", "USERNAME"); capability.SetCapability("browserstack.key", "ACCESS_KEY"); driver = new RemoteWebDriver( new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability ); driver.Navigate().GoToUrl("http://www.google.com"); Console.WriteLine(driver.Title); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Browserstack"); query.Submit(); Console.WriteLine(driver.Title); driver.Quit(); } } }