2

实际上,我正在尝试使用 TestNG 在 Eclipse 中运行 Web 应用程序的测试用例。但是我在运行 Selenium 脚本时遇到了一些问题。即使某些测试用例失败,我也只想继续执行。但我不知道该怎么做。

我对这个话题很陌生朋友。请帮我..!!!无论如何,提前致谢。

4

2 回答 2

2

好的,在这种情况下,您需要使用@TestAnnotation 的属性之一,即

@Test(alwaysRun = true)

如果设置为 true,即使它依赖于失败的方法,该测试方法也将始终运行。

于 2013-09-11T16:06:12.203 回答
2

在 TestNG 中使用alwaysRun = true注释并不能完全解决您的问题。

为了让 Selenium 即使在偶尔出现异常时也能继续运行,您需要使用 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 时忽略异常,直到达到某个预先配置的超时。

于 2013-09-11T20:12:28.613 回答