How to Use Selenium RC with Java
- August 18th, 2010
- Write comment
I know most of them are familiar using selenium IDE at the same time many of them are wondering how to use Selenium RC .
I was one among you all but with help from one of my friend I started working on Selenium RC and realised that Selenium RC is very powerful, useful and not a difficult one.I installed it on Ubuntu system and started writing Test cases with JUnit
- Install Eclipse
- Install selenium IDE as add on to your firefox browser
- Install Selenium RC – make sure you have all the following 3 files
- selenium-server-coreless.jar
- selenium-server.jar
- selenium-server-sources.jar
To start selenium server on your machine got to the directory where the above 3 files are present and then type in the following command “java -jar selenium-server.jar” and it should start the selenium server with out any exceptions.
Open your Eclipse and go to File ->New -> Project
Name your Project say “TestProject”
Right Click on Test and say New Package and name it as “TestPackage”
Right click on TestPackage and create a new Class and name it as “NewClass”
In the class put in the following code:
package mainpackage;
import java.util.Random;
import org.junit.Test;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
public class Logintest extends SeleneseTestCase {
// We create our Selenium test case
public void setUp() throws Exception {
setUp(“http://www.yourtestingsite.com/“, “*firefox”);
// We instantiate and start the browser
}
@Test //This is mandatory to put @Test at the start of each test
public void testSignUp() throws Exception {
//this code you get it from the recorded IDE session
selenium.open(“/”);
selenium.click(“link=Sign up”);
selenium.waitForPageToLoad(“30000″);
selenium.type(“username”, “random@random.com“);
selenium.type(“password”, “password”);
selenium.type(“confirm_pass”, “password”);
selenium.type(“display_name”, “random”);
selenium.click(“display_name”);
selenium.type(“display_name”, “random”);
selenium.click(“acceptUsage”);
selenium.click(“Login”);
selenium.waitForPageToLoad(“30000″);
verifyTrue(selenium.isTextPresent(“You’re almost done! One last thing … You just need to activate your account. Simply click on the link we’ve emailed you and you’re ready to go!”));
Results.result(“Signup is successful”);
}
To get the java code from recorded IDE you just need to click on Options -> Format ->Java(JUnit)-SeleniumRC
copy paste the code into your IDE and run the code.
Put in some tweaks to suit your testing needs.
Will post some more on RC code soon