【问题标题】:Execution of Selenium Script even after Test case fails即使在测试用例失败后执行 Selenium 脚本
【发布时间】:2013-09-11 15:02:43
【问题描述】:

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

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

【问题讨论】:

  • (恕我直言)这可能会在以后的测试维护中产生问题..
  • 我正在尝试完全运行代码,以便检查有多少测试用例通过以及有多少失败。这可能吗 ?? @Jayan
  • 您是否在运行相互依赖的测试用例?您可以查看TestNg 以获取任何帮助
  • 一些测试用例是相互依赖的。但我认为我可以处理这种情况。我需要这个来运行不相互依赖的脚本。如果您有任何想法,请告诉我先生。!!! @pArAs

标签: java selenium scripting selenium-webdriver testcase


【解决方案1】:

在 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 时忽略异常,直到达到某个预先配置的超时。

【讨论】:

    【解决方案2】:

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

    @Test(alwaysRun = true)

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

    【讨论】:

      猜你喜欢
      • 2017-08-12
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 2012-07-04
      相关资源
      最近更新 更多