我正在尝试在同一个类中编写两个 testng 测试(使用 Selenium webdriver) - 一个登录到应用程序,另一个创建一个新帐户。
这些是我正在遵循的步骤 - 使用 @BeforeClass 在 Firefox 浏览器上打开应用程序
@BeforeClass
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.salesforce.com";
driver.get(baseUrl + "/");
}
首先测试登录网站
@Test public void testLogin() throws Exception { driver.findElement(By.id("username")).sendKeys(strUsername); driver.findElement(By.id("password")).sendKeys(strPassword); driver.findElement(By.id("Login")).click();
}
第二次测试创建一个新帐户
@Test public void createAccount() throws Exception { driver.findElement(By.linkText("Accounts")).click(); ************************ ************************ ************************ ************************ ************************
}
我的问题是,当我运行这个 testng 测试时,我在第二个测试中遇到异常: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Accounts"}
但如果我包含命令“driver.findElement(By.linkText("Accounts")).click();” 在 testLogin() 测试中,它可以工作。我想在同一个浏览器会话中运行我的所有测试。
任何输入将不胜感激。谢谢。