Your guide to running Selenium Webdriver tests with C# on BrowserStack.
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:
Before you can start running your Selenium tests with C# you have to set up visual studio project with Selenium bindings as shown below (you can skip this section if you already have a working C# setup to run Selenium tests):
Now, your setup is ready to run the first Selenium test.
To get started, let’s run a simple Selenium Webdriver test. The C# script below opens
google.com, input a search string, submits the form, and returns the page title. It also marks the test as passed or failed based on the page title.
First, select the OS and Device/Browser combination you’d like to test on using the drop-down menus below. This will automatically update the C# code sample below:
Look for the icon to select a real device.
driver.quit()statement is required, otherwise the test continues to execute, leading to a timeout.
Second, copy-and-paste the code sample into the empty .cs file that you created in the Prerequisite step, and execute the test.
Third, verify the results. The Selenium Webdriver test should have opened a URL, inputted a string, submitted the form, returned the page title and marked the test as passed or failed based on the returned title.
BrowserStack does not know whether your test’s assertions have passed or failed because only the test script knows whether the assertions have passed. Therefore, based on the assertions on your script, you have to explicitly inform BrowserStack whether your tests have passed or not and this document will help you in doing that exactly.
It is possible to mark tests as either a pass or a fail and also give a reason for the same, using the following snippet (Refer the above sample script which implements the snippet shown below):
failedas the value
reasonaccepts a value in string datatype
Marking test as pass/fail is also possible using our REST API at any point in the test or also after the test has concluded. You can read more about marking test using REST API and use it, if it fits your use case.
BrowserStack provides a range of debugging tools to help you quickly identify and fix bugs you discover through your automated tests.
Text Logs are a comprehensive record of your test. They are used to identify all the steps executed in the test and troubleshoot errors for the failed step. Text Logs are accessible from the Automate dashboard or via our REST API.
Visual Logs automatically capture the screenshots generated at every Selenium command run through your C# script. Visual logs help with debugging the exact step and the page where failure occurred. They also help identify any layout or design related issues with your web pages on different browsers.
Visual Logs are disabled by default. In order to enable Visual Logs you will need to set
browserstack.debug capability to
capability.AddAdditionalCapability("browserstack.debug", "true", true);
Sample Visual Logs from Automate Dashboard:
Every test run on the BrowserStack Selenium grid is recorded exactly as it is executed on our remote machine. This feature is particularly helpful whenever a browser test fails. You can access videos from Automate Dashboard for each session. You can also download the videos from the Dashboard or retrieve a link to download the video using our REST API.
In addition to these logs BrowserStack also provides Raw logs, Network logs, Console logs, Selenium logs, Appium logs and Interactive session. Complete details to enable all the debugging options can be found here.
Once you have successfully run your first test on BrowserStack, you might want to do one of the following:
Contact our Support team for immediate help while we work on improving our docs.