Java使用Selelium的一个例子 博客分类: SorLib javaSeleliumdemo例子
程序员文章站
2024-03-11 23:42:55
...
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; } }); } }