Here we are going to see how to integrate selenium with Visual Studio. This actually help developers to test their code on their own.

What is selenium and why we need them

Selenium, almost all techies will look for this now. Selenium is an open source software testing framework that helps user to run an automated test on their web based applications.

So, how this happens

Selenium WebDriver is the successor to Selenium RC. Selenium WebDriver accepts commands (sent in via a Client API) and sends them to a browser. Selenium consists of APIs that helps to integrate with any programming language such as Java, C#, Groovy, Perl, PHP, Python and Ruby.
Now, we will see how we add them to our visual studio. These are the simple steps that helps you to integrate selenium to Visual studio.

STEP 1: Open Visual Studio and create new project,

new

STEP 2: Click on test project (here I’m using Visual Studio 2010).

unittest

Now, after creating a New Test project, we need to add the Selenium APIs to the Visual studio. Here is the link to download Selenium Web Driver.

debug

STEP 3: Adding selenium to your c# project in Visual Studio.

selenium

STEP 4: Add all dll files from the folder where selenium drivers are extracted.

drivers

STEP 5:

STEP 6: Replace the following code and run them.

  1. using System;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4. using OpenQA.Selenium.Support.UI;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace SeleniumExample
  7. {
  8. [TestClass]
  9. public class UnitTest1
  10. {
  11. ChromeDriver Chrome;
  12. // This is the test to be carried out.
  13. [TestMethod]
  14. public void TestMethod1()
  15. {
  16. Chrome = new ChromeDriver();
  17. Chrome.Navigate().GoToUrl("http://www.google.com/");
  18. Chrome.FindElement(By.Id("lst-ib")).SendKeys("APJ ABDUL KALAM");
  19. Chrome.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
  20. }
  21. // This closes the driver down after the test has finished.
  22. [TestCleanup]
  23. public void TearDown()
  24. {
  25. //Chrome.Quit();
  26. }
  27. }
  28. }

STEP 7: