Monday, April 8, 2013

Running Selenium tests from Visual Studio – Step by step

From Firefox, record new selenium test, for example for Google search

2013-04-07_13-14-39

Export the test to C# web drive

2013-04-07_13-15-06

This is how it looks like after export

2013-04-07_13-15-50

Open visual studio, create new test project

2013-04-07_13-16-36

By default the file UnitTest1.cs is created

2013-04-07_13-25-47

Create a new cs file, name it for example GoogleSearch

2013-04-07_13-25-54

Copy the code from the cs file generated by selenium and paste it in the file GoogleSearch.cs

2013-04-07_13-26-42

Add reference in the project to Selenium .Net WebDriver, WebDriver.dll and WebDriver.Support.dl

2013-04-07_13-29-322013-04-07_13-29-07

Now the references added, you can see that the editor recognizes the selenium name spaces

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

2013-04-07_13-29-40

Find and replace “TestFixture” to “TestClass”, “SetUp” to “TestInitialize()”, “Test” to “TestMethod”, “TearDown” to “TestCleanup()”

2013-04-08_00-31-32

To run with Chrome, download chromedriver.exe from https://code.google.com/p/chromedriver/downloads/list, place it in the bin folder

2013-04-08_09-45-49

Change the driver in the code to Chrome then run the test

driver = new OpenQA.Selenium.Chrome.ChromeDriver();

2013-04-08_09-45-09

Running the test, chrome will open, and Google search page will be displayed, displaying search results then closed

2013-04-08_09-51-36

This was a step by step example on running selenium test from visual studio