【发布时间】:2012-08-11 15:15:58
【问题描述】:
我正在尝试在同一个类中编写两个 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: 无法定位元素:{"method":"link text","selector":"Accounts"}
但如果我包含命令“driver.findElement(By.linkText("Accounts")).click();”在 testLogin() 测试中,它可以工作。我想在同一个浏览器会话中运行我的所有测试。
任何输入将不胜感激。 谢谢。
【问题讨论】: