我正在尝试在我的selenium webdriver脚本中使用testng。
我希望页面在@BeforeClass中登录信息,并在@AfterClass中注明信息,以便我登录一次 - 执行2个测试用例然后 - 只签出一次而不必登录并注销每个@Test。但我不断收到@Test public void test1()的断言超时错误。
@BeforeClass
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
baseUrl = commInfo.getURL();
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
userID = commInfo.getuiUserID();
passwd = commInfo.getuiPasswd();
conn=null;
stmt=null;
sql="";
rs=null;
segName=null;
driver.get(baseUrl + "/uiportal/login/Logout.com");
driver.findElement(By.id("usernameField")).clear();
driver.findElement(By.id("usernameField")).sendKeys(userID);
driver.findElement(By.id("textfield2")).clear();
driver.findElement(By.id("textfield2")).sendKeys(passwd);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.id("submitLink"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("submitLink")).click();
@Test
public void test1() throws Exception {
some test code here
}
@Test
public void test2() throws Exception {
some test code here
}
@AfterClass
public void tearDown() throws Exception {
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.partialLinkText("Sign out"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.partialLinkText("Sign out")).click();
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
由于