Monday, October 29, 2012

Setup Selenium WebDriver

I need to setup Selenium WebDriver with .Net so here are the steps:

1. Download the latest selenium-dotnet zip file from:
https://code.google.com/p/selenium/downloads/list

2. Unblock the zip file before unzipping it: Right click on the zip file, click “Properties”, click “Unblock” and click “OK”.

3. Unzip the contents of the zip file, and add a reference to each of the unzipped dlls to your project in Visual Studio.

4. Get Official NuGet Packages:
http://www.nuget.org/packages/Selenium.WebDriver
http://docs.nuget.org/docs/start-here/using-the-package-manager-console

5. Download Chrome driver from here:
http://code.google.com/p/chromedriver/downloads/list
http://code.google.com/p/selenium/wiki/ChromeDriver

6. In Visual Studio go to Test -> New Test -> name it FirtsSeleniumTest.cs

7. Write the following code:

var driver = new ChromeDriver(@"C:\Selenium\chromedriver_win_23.0.1240.0");
driver.Navigate().GoToUrl("http://www.google.com/");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("My first Selenium test");
query.Submit();

8. Run the code. This will open google and type "My fisrt Selenium test".

No comments:

Post a Comment