Quality is delighting customers
How To Setup Eclipse To Run Selenium Script
1) Download Eclipse IDE : http://www.eclipse.org/downloads/
2) Download Selenium RC : http://seleniumhq.org/download/
3) Download Junit : http://www.junit.org/
A. Selenium RC Setup in Local Machine :
- Download the Selenium RC : selenium-remote-control-1.0.3 to the C drive which must contain 'selenium-java-
client-driver-1.0.1' and 'selenium-server-1.0.3' floders.
- Open Command prompt and run Selenium RC by below command :
C:\selenium-remote-control-1.0.3\selenium-server-1.0.3> java -jar selenium-server.jar
- After pressing enter the selenium-rc will the running in the port no 4444 in a new window.
B. Create new project in Eclipse :
Note :
- 'selenium-java-client-driver.jar' is found in the 'C:\selenium-remote-control-1.0.3\selenium-java-client-driver-
1.0.1' And 'junit-4.7.jar' is found in the download JUnit folder.You have to set the build path of both JARs in
eclipse from only from you local machine directory where these JARs are available.
Now our Eclipse environment is ready for Selenium Project [Congrats... !!!].
D. Step is to prepare a test case in Selenium IDE :
- A small test that searches for “linux” word in google. To export test case as Java, in Selenium IDE go
to Options -> Format -> Java (Junit) Selenium RC.
- As a result you should get something like this :
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Untitled extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.google.com/" "*chrome");
}
public void testUntitled() throws Exception {
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
}
}
E. Edit the Code as Below for Eclipse Running Environment :
package com.example.tests;
import com.thoughtworks.selenium.*;
public class GoogleTest extends SeleneseTestCase {
public DefaultSelenium selenium;
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
selenium.start();
}
public void testGoogleTest() throws Exception {
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
selenium.waitForPageToLoad("10000");
}
}
F. Lets add it in our Eclipse project :
Note : If any issue please be sure about your JAR paths are correct in the JAVA-Build Path of Eclipse.
G. Test Script Execution :
- Now, to start the test just select Run -> Run As -> Junit test.
Or Right Click on Eclipse code and Click RunAs : Junit
H. Observation :
- After a few Second 2 Windows will open as :
1. Selenium Debug window
2. IE with Gogle.com with search results for “linux” word.
I. Modify code to add more Scripts :
public void testGoogleTest() throws Exception {
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
selenium.waitForPageToLoad("10000");
}
- Modify this script as per your functional test only by adding a new method start with 'test<scriptName>'.
- Here any Method starts with 'test' which is the test-script execution entry point.
Comment
Comment by Rashmi Gupta on April 25, 2012 at 3:06pm Hi,
i am going through u r post, but not able to find Point D, which u have mention,
D. Step is to prepare a test case in Selenium IDE :
- A small test that searches for “linux” word in google. To export test case as Java, in Selenium IDE go
to Options -> Format -> Java (Junit) Selenium RC.
In my IDE Option > Format > no java(Junit) selenium Rc is there, pls help me to find that
Comment by S Sarita on August 17, 2011 at 5:04pm thnx san...
Comment by 0Santhosh Automation Engineer on August 16, 2011 at 6:28pm Hi Sarita,
ANT" scripting helps in build creation and deploying the scripts you created . . it helps you in defining where your library, result location , where the test cases(RC scripts stored ) . The order of Test cases to be executed .. Better to say like a shell script or .bat file .
Or better to say it helps you in automating your automated test cases .
San
Senior Automation Engineer
symphony Services bangalore
my blog http://qtpsanthosh.wordpress.com
My id :- software.analyst.bangalore@gmail.com
Comment by S Sarita on August 16, 2011 at 5:30pm Hi Girija,
In this set up you required selenium client and server jar, eclipse and Junit jar.
Do you know for what purpose behind using "ANT"?
-S Sarita.
© 2012 Created by Quality Testing.
You need to be a member of Quality Testing to add comments!
Join Quality Testing