Selenium WebDriver & Visual Studio 2013

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. newprojOnce the solution opens right click on the Project file in the Solution Explorer Window and Select Manage Nuget Packages…

nugetConduct 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.

nuget addBoth 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

dependenciesRight click on the chromedriver.exe and select Properties

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.

propertiesOnce 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

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

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.

Gary Woodfine

Freelance Full Stack Developer at
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

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)