Before setting up Selenium with Visual Studio, we should make sure that machine should have installed Visual Studio 2013 and NuGet.

So if above pre-requisites are in right place then start Visual Studio and create new project.

VS

Select Visual C# > Test > Unit Test Project. Provide project name, location and click on OK button.

VS1

Select your project and right click. Click on Manage NuGet Packages…option.

VS2

Make sure you are pointing to ‘Online‘. Search the term ‘Selenium‘ and install Selenium WebDriver and Selenium WebDriver Support Classes. Now close the ‘Manage NuGet Package‘ window.

VS3

We will use Chrome browser to execute our first selenium script, so for this download Chrome driver from here.

Download and extract the file.

Open UnitTest1.cs file and include following namespaces-

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

Now under TestMethod1() add following code-

IWebDriver driver = new ChromeDriver(@”D:\Download\VisualStudio_Projects”);
driver.Navigate().GoToUrl(“http://www.bing.com”);
driver.Manage().Window.Maximize();
driver.FindElement(By.Id(“sb_form_q”)).SendKeys(“Mayank”);
driver.FindElement(By.Id(“sb_form_go”)).Click();
driver.Quit();

VS4

Now run the method. It will open the Chrome browser with bing.com and will search the term.

Comment out if above steps are not working for you.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s