欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java使用Selelium的一个例子 博客分类: SorLib javaSeleliumdemo例子 

程序员文章站 2024-03-12 08:25:26
...
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;
			}
		});
	}

}