Java使用Selelium的一个例子

public class TestUserRegister extends TestCase {

public TestUserRegister() {

}

WebDriver driver;

protected void setUp() throws Exception {
System.out.println("setup before father class - before class");

// driver = new FirefoxDriver();
driver = new FirefoxDriver();

// Adjust firefox window
// JavascriptExecutor js = (JavascriptExecutor) driver;
// js.executeScript("window.resizeTo(1280,heightscreen.)");
// driver.get("http://localhost:8080/HelloStripes/index.jsp");
}

public void test1() {
driver.findElement(By.id("message")).sendKeys("Test");
driver.findElement(By.id("sayHello")).click();
waitForLoad(By.id("HelloWorld"));
}

public void waitForLoad(final By elementBy) {
WebDriverWait wait = (new WebDriverWait(driver, 30));
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
boolean loadcomplete = d.findElement(elementBy).isDisplayed();
return loadcomplete;
}
});
}

}
展开阅读全文

没有更多推荐了,返回首页