Create Selenium Java test case using Eclipse

22

Requirement:
1. Eclipse 3.4+
2. FireFox Browser
3. Java 1.5 or 1.6
4. Selenium Jars
selenium-server-standalone-2.3.0.jar
selenium-java-2.3.0.jar

Steps to create selenium project:
1. Open Eclipse
2. Create new project
3. Import selenium-server-standalone-2.3.0.jar and
selenium-java-2.3.0.jar
4. Create new java file with name TestSample
5. Refer the below code

import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.Selenium;

public class TestSample {
public static void main(String[] args) throws Exception {
String url = "http://www.google.co.in";
Properties properties = LoadProperties.loadPropertiesFile();
WebDriver driver = new FirefoxDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, url);
driver.get(url);
selenium.waitForPageToLoad("900000");
String a = selenium.captureScreenshotToString();
driver.close();
selenium = null;
driver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(driver, url);
driver.get(url);
selenium.waitForPageToLoad("400000");
selenium.waitForPageToLoad("400000");
String b = selenium.captureScreenshotToString();
System.out.println("clicked" + a);
System.out.println("clicked" + b);
if(a.equalsIgnoreCase(b)){
System.out.println("true");
}  else {
System.out.println("false");
}
}
}

6. Save file
7. Run TestSample : java file as a Run Test.

Total Page Visits: 3845 - Today Page Visits: 14

Leave a Reply