我目前正在使用 Java Selenium 进行 UI 自动化,我有 3 个测试类。当我单独运行它们时,我没有遇到任何问题。但是,如果我同时运行所有 3 个页面,则某些测试会失败,表示找不到定位器。如何解决这个问题。这是同步问题还是我的等待时间太长了?
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:84)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:230)
at pages.CartPage.addItemsToCart(CartPage.java:37)
at tests.CartPageTest.updateCart(CartPageTest.java:27)
The exception clearly points to the Timeout Exception, add a Wait mechanism after every test.
**@Test**
Test1()
{
//code
Wait<Webdriver> wait=new WebdriverWait(driver, Duration.ofSeconds(20));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("pass the element it take a time to appear in the page"));
}
**@Test**
Test2()
//your code
Wait<Webdriver> wait=new WebdriverWait(driver, Duration.of seconds(20));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("pass the element it take a time to appear in the page"));
}