[英]How can I catch the Selenium error message
我想检查在页面之间导航时是否收到错误消息。当错误消息出现时,测试将终止并进行报告。为此,我使用以下与站点上的错误消息相关的元素.
try {
WebElement element=driver.findElement(By.className("p-toast-message-text"));
element.isDisplayed();
boolean s= element.isDisplayed();
System.out.println(s);
}
catch (NoSuchElementException e) {
throw new RuntimeException("-----");
}
但是,当我设置这个结构时,如果页面有错误,则测试成功,如果没有错误,则测试不成功。 因此,无法切换到不同的页面。如何控制这一点?
好吧,我会要求 HTML 看看你给它的路径是否对你的情况是唯一的,如果你希望代码在显示错误后停止,我可以建议使用 Assert,如果你希望代码继续,即使有最后带有 assertall() 的错误。 我控制这个的方式:
Boolean NoCanceledAppointement = driver.findElements(By.xpath("//div[@class=\"empty-result\"]/h2[normalize-space(text())=\"Vous n’avez pas de Rendez-vous annulés !\"]")).size() > 0;
if(NoCanceledAppointement == true) {
Reporter.log(FormatMessageSucces + " No Canceled Appointement Exist</font>");
}
else {
Sa.assertEquals(false, true, "The Page didn't show the message of 'You have no canceled appointments!'");
ScreenShot(driver);
Reporter.log(FormatMessageError + " The Page didn't show the message of 'You have no canceled appointments!'</font>");
}
如果我的代码没有找到该元素,那么它将访问软断言,ScreenShot 只是为了在显示错误时为页面拍照。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.