由于您已发现错误,因此不会失败。我重新创建了如下情况。这没有失败。但是抛出了一个 Throwable。Error
被打印。
public class TNG {
WebDriver driver;
@Test
public void googleSearch(){
System.setProperty("webdriver.chrome.driver", "path to web driver");
driver = new ChromeDriver();
driver.get("http://www.google.co.in/");
System.out.println(" ---------- Start -------------");
try {
Assert.assertTrue(driver.findElement(By.xpath("xyz")).isDisplayed(), "unable to find the link");
} catch (Throwable t) {
System.out.println("Error");
}
System.out.println(" ---------- End -------------");
}
@Test
public void anotherTest(){
System.out.println("another test");
}
}
以下是执行测试的结果。
another test
Starting ChromeDriver 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41) on port 43423
Only local connections are allowed.
Jul 20, 2017 5:55:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
---------- Start -------------
Error
---------- End -------------
PASSED: anotherTest
PASSED: googleSearch
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
如果您想在某些测试失败的情况下继续执行测试,您可以简单地编写带有@Test
注释的方法,例如我创建的 anotherTest() 方法。但是你不能保证测试执行的顺序。在上面的 anotherTest() 已首先执行。