In this guide I’ll provide instructions on how to set up Selenium Web Driver using Microsoft Visual Studio 2013 and an example of how to write a quick test.
Selenium WebDriver browser automation testing
The WebDriver is a tool for automating the testing of web applications. It assists in the running of web browsers natively as a user would either locally or on a remote machine using the Selenium Server.
The first step would be to start Microsoft Visual Studio and create a new Visual C# Unit Test Project. Once the solution opens right click on the Project file in the Solution Explorer Window and Select Manage Nuget Packages…
Conduct a search using Online and the search term Selenium the options for both the Selenium WebDriver and Selenium WebDriver Support Classes should appear. Ensure you install both these packages to your project.
Both the Internet Explorer and Firefox driver are included in the Selenium, however we will need to download an additional web driver for Chrome . Once the web driver for chrome has been downloaded extract the executable file to a folder in your solution .
I created a folder called dependencies and added the executable there
Ensure the Build Action Content is selected Copy to Output Directory Copy Always has been selected. This will ensure that chromedriver.exe is always in the folder of the running assembly so it can be used.
Once all the set up is complete we can now begin writing a simple test check everything is working as expected. In my example I am going to test that a user is redirected to a login page if they select the Login link on the homepage of the threenine.co.uk.
Example of how to use Selenium for automated browser testing
We’ll create a simple ThreeNineLoginTest.cs unit test class and import the Selenium Namespaces required
We’ll now create a simple unit test
public class ThreeNineLoginTest
public void RedirectToLoginFromHomePage()
using (IWebDriver wdriver = new ChromeDriver(@"dependencies"))
If we run the test, we’ll see the chrome browser launch and the website should be loaded, the new chrome window should be maximized and then the Login link should be click and the user should be redirected to the login page. We’ll carry out a simple assert to determine if the Browser URL is inded the URL of the login page. The test should pass.
When in the Visual Studio IDE, I prefer to run all my tests using Resharper Productivity Tool for Visual Studio, but we can now also equally run these tests using the Selenium Server too.
Will be continuing to add more Selenium tutorials on this blog so do check the archives for anymore information and tutorials. If you have any further questions please feel free to ask in the comments section below or via the contact form and I will endeavour to respond as soon as I can.
A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Latest posts by Gary Woodfine (see all)
- C# Tuples - June 11, 2017
- C#Local Functions - May 21, 2017
- Using AutoMapper in Domain Objects with DotNet Core - April 24, 2017