Selenium Webdriver スクリプトで testng を使用しようとしています。
ページのサインイン情報を @BeforeClass に、サインアウト情報を @AfterClass に設定して、1 回サインインし、2 つのテスト ケースを実行してから、1 回だけサインアウトし、各 @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);
}
}
ありがとう