我使用java在selenium中创建测试并使用testlink进行测试执行和结果。没有断言测试与testlink工作正常并显示结果但是当我使用断言验证预期和实际结果时这样:
try {
driver.get("http://www.software-testing-tutorials-automation.com");
String ExpextedTitle="Software testing tutorials and automatio";
String ActualTitle=driver.findElement(By.xpath("//h1[@class='title']")).getText();
Assert.assertEquals(ActualTitle, ExpextedTitle);
IntegrationWithTestLink.updateResult("GR-1", null, TestLinkAPIResults.TEST_PASSED);
}catch(Exception e){
System.out.println("Hiiiii");
IntegrationWithTestLink.updateResult("GR-1", e.getMessage(), TestLinkAPIResults.TEST_FAILED);
}
}
我不知道为什么结果没有在testlink中显示 例外。任何人都可以建议我在这里使用Assertion更好的方法。
答案 0 :(得分:0)
catch块不会捕获断言错误,因为您捕获的异常不是错误。要捕获错误,请更改下面给出的代码。
尝试{
driver.get("http://www.software-testing-tutorials-automation.com");
String ExpextedTitle="Software testing tutorials and automatio";
String ActualTitle=driver.findElement(By.xpath("//h1[@class='title']")).getText();
Assert.assertEquals(ActualTitle, ExpextedTitle);
IntegrationWithTestLink.updateResult("GR-1", null, TestLinkAPIResults.TEST_PASSED);
}catch(AssertionError e){
System.out.println("Hiiiii");
IntegrationWithTestLink.updateResult("GR-1", e.getMessage(), TestLinkAPIResults.TEST_FAILED);
}
}
它可能适合你。