- mkdir stests
- cd stests
- wget http://selenium.googlecode.com/files/selenium-java-2.33.0.zip
- unzip selenium-java-2.33.0.zip
- mkdir jars
- find selenium-2.33.0 -type f -name '*jar' -exec mv -v {} jars \;
- rm -rfv selenium-*
- mkdir src
- vi src/Test.java
- use below code
- mkdir out
- javac -d out -cp 'jars/*' src/MyTest.java
- ignore "Notes" output
- cd out
- rm -rfv org
- java -cp '../jars/*:.' MyTest
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
The Article on Selenium test on CLI in 5 minutes using Java is nice. It give detail information about it .Thanks for Sharing the information on Selenium test. Software Testing Services
ReplyDelete