0

我正在尝试在我的 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);
    }
}

谢谢

4

0 回答 0