Wednesday, September 22, 2010

How to run your first selenium test in visual studio 2008 with c#

Step1:

Selenium IDE

  1. Install selenium IDE as add on in your firefox browser.
  2. Run Selenium IDE and record script using it with language as C#.
  3. Stop recording and copy the code.

Step2:

Selenium RC

  1. Download selenium RC file and extract it to your local folder
  2. Go through command prompt and local folder directory
  3. Write command as java – version to check java environment availability.
  4. If java environment is not there then install it first using jdk 1.6
  5. Write command as java –jar selenium-server.java
  6. It will start selenium RC server. If it gives port error then write java –jar selenium-server.jar –port 5555

Step3:

Visual Studio 2008

  1. Create one project with window application
  2. Add references with client drivers of selenium in the project
  3. In form1 add one button
  4. In project add one class as new item.
  5. Copy your selenium IDE c# script to that class1.cs
  6. In setup method give URL of your site going to be test in class1.cs as

public void SetupTest()

{

selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.gmail.com/");

selenium.Start();

verificationErrors = new StringBuilder();

}

7. Add reference of using library

8. In form1.cs button’s click event make object of that class using

private void button1_Click(object sender, EventArgs e)

{

SeleniumTests.Untitled a = new Untitled();

a.SetupTest();

a.TheUntitledTest();

a.TeardownTest();

}

9. Build the solution and run the application on click of button.

No comments:

Post a Comment