即使其中一个软断言失败,测试即使进行。但是在我的情况下,由于无法找到下一个测试元素,因此我的测试停止了。
softAssert.assertTrue(p.OtsPage.fName().getAttribute("readonly").equals("true"), "field Name is Editable", "field Name is Read Only");
softAssert.assertTrue(p.OtsPage.fEditValue().isEnabled(), "field Edit Value is not Editable", "field Edit Value is Editable");
这可以正常工作,但是如果我设置:
softAssert.assertFalse(p.OtsPage.fName().getAttribute("readonly").equals("true"), "field Name is Editable", "field Name is Read Only");
softAssert.assertFalse(p.OtsPage.fEditValue().isEnabled(), "field Edit Value is not Editable", "field Edit Value is Editable");
我有以下错误消息:
org.openqa.selenium.nosuchelementException。对于第二个软宣言!!!
和测试停止。
环境:硒3.5 geckodriver mozilla 56.0.1。
这似乎不是断言的问题,因为正如您提到的第二行正在运行,但会引发异常。您的问题可能在这里:p.OtsPage.fEditValue().isEnabled()
。
更准确地说:根据文档,WebDriver.findElement(By)
抛出了NosuchelementException。
您可能在fEditValue()
功能中运行findElement()
,应该在那里搜索问题。确保在运行该功能的时刻,在此功能中,选择器表示的元素确实存在于页面上。