Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 即使在测试用例失败后仍执行Selenium脚本_Java_Selenium_Scripting_Selenium Webdriver_Testcase - Fatal编程技术网

Java 即使在测试用例失败后仍执行Selenium脚本

Java 即使在测试用例失败后仍执行Selenium脚本,java,selenium,scripting,selenium-webdriver,testcase,Java,Selenium,Scripting,Selenium Webdriver,Testcase,实际上,我正在尝试使用TestNG在Eclipse中运行web应用程序的测试用例。但是我在运行Selenium脚本时遇到了一些问题。我只想继续执行,即使有些测试用例失败。但我不知道怎么做 朋友们,我对这个话题很陌生。请帮帮我。。!!!无论如何,请提前感谢。好的,在这种情况下,您需要使用@Test注释的一个属性,即 @Test(alwaysRun = true) @测试(始终运行=真) 如果设置为true,则此测试方法将始终运行,即使它依赖于失败的方法。确定,在这种情况下,您需要使用@test注释

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


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

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

@Test(alwaysRun = true) @测试(始终运行=真)
如果设置为true,则此测试方法将始终运行,即使它依赖于失败的方法。

确定,在这种情况下,您需要使用
@test
注释的一个属性,即

@Test(alwaysRun = true) @测试(始终运行=真) 如果设置为true,则此测试方法将始终运行,即使它依赖于失败的方法。

在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") );
Wait Wait=new FluentWait(驱动程序)
.带超时(30秒)
.每(5秒)轮询一次
.忽略(NoSuchElementException.class、ElementNotFoundException.class);
//使用定制的预期条件
WebElement foo1=wait.until(新函数(){
公共WebElement应用(WebDriver){
//如果你想在这里做点什么
返回驱动程序findElement(By.id(“foo”);
}
});
//使用内置的预期条件
WebElement foo2=等待.until(ExpectedConditions.visibilityOfElementLocated(
By.id(“foo”);
这使您能够在任何时候忽略异常。在达到某个预先配置的超时之前调用findElement。

在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") );
Wait Wait=new FluentWait(驱动程序)
.带超时(30秒)
.每(5秒)轮询一次
.忽略(NoSuchElementException.class、ElementNotFoundException.class);
//使用定制的预期条件
WebElement foo1=wait.until(新函数(){
公共WebElement应用(WebDriver){
//如果你想在这里做点什么
返回驱动程序findElement(By.id(“foo”);
}
});
//使用内置的预期条件
WebElement foo2=等待.until(ExpectedConditions.visibilityOfElementLocated(
By.id(“foo”);

这使您能够在调用.findElement时忽略异常,直到达到某个预先配置的超时。

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