Monday, January 5, 2015

Selenium WebDriver in Visual Studio

Introduction

This week we will present how to use Selenium WebDriver in Visual Studio.
We used the following softwares (but these are not mandatory):

  • Windows 8.1
  • Visual Studio 2012
  • NUnit
  • Selenium
  • NuGet
  • Resharper

Installation

In order to create a new project with Selenium WebDriver:

  • Open Visual Studio and create a new C# class project
  • Download and intall NuGet from Tools --> Extensions and Updates. Restart Visual Studio in order to apply the new settings
  • Open Library Package Manager from Tools --> Library Package Manager --> Package Manager Console
  • Install the latest version of Selenium WebDriver by running command Install-Package 
  • Selenium.WebDriver -Version 2.44.0
  • Install the latest version of Selenium WebDriver Support by running command Install-Package Selenium.Support


  • Install Resharper from https://www.jetbrains.com/resharper/download/
  • Install NUnit  from http://www.nunit.org/
  • Add the NUnit reference for the created project by right-clicking on the Reference --> Add reference and add the path to the nunit.framework.dll, in our case C:\Program Files (x86)\NUnit 2.6.3\bin\framework\nunit.framework.dll


At the end, the Solution Explorer should look like this:


Creating the First Test

We will not detail the way we should write the C# code this week. But the idea is the same like described in two previous posting http://ralucasuditu-softwaretesting.blogspot.ro/2014/12/selenium-webdriver-create-helper.html and http://ralucasuditu-softwaretesting.blogspot.ro/2014/12/selenium-webdriver-create-helper_17.html.
Just translate the java code in C# code, but taking into consideration some differences that will be later explained.
Here is a test example where we marked some differences:


Running the Test

We will explain two ways of running a test.
If you have Resharper installed that you can click on the left icons to run all tests in a class or only a test.


If you don't have a Resharper license then:

  • Go to menu Projects --> Projects Properties (where 'Project' is the project name)
  • Select the Debug tab


  • Click on Start external program and set the path to nunit.exe, in our case C:\Program Files (x86)\NUnit 2.6.3\bin\nunit-x86.exe
  • Build the project
  • Run the tests by pressing F5 key. NUnit will be opened and, from here you can run your tests.


Happy testing in 2015 and... make it green, becomes a dream :).

No comments:

Post a Comment

Popular Posts