实际上,我正在尝试使用 TestNG 在 Eclipse 中运行 Web 应用程序的测试用例。但我在运行 Selenium 脚本时遇到了一些问题。即使某些测试用例失败,我只想继续执行。但我不知道该怎么做。
friend 们,我对这个话题很陌生。请帮我..!!!无论如何,提前致谢。
最佳答案
在 TestNG 中使用 alwaysRun = true 注释并不能完全解决您的问题。
为了让 Selenium 在偶尔出现 Exception 的情况下也能够继续运行,您需要使用 FluentWait 类定义一个 Wait 对象,如下所示:
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring( NoSuchElementException.class, ElementNotFoundException.class );
// using a customized expected condition
WebElement foo1 = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply( WebDriver driver ) {
// do something here if you want
return driver.findElement( By.id("foo") );
}
});
// using a built-in expected condition
WebElement foo2 = wait.until( ExpectedConditions.visibilityOfElementLocated(
By.id("foo") );
这使您能够在每次调用 .findElement 时忽略异常,直到达到某个预先配置的超时为止。
关于java - 即使测试用例失败也执行 Selenium 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18744775/