2017-12-27 261 views
0

即使其中一個軟斷言失敗,測試也會繼續。 但在我的情況下,我的測試在軟件斷言失敗後停止,因爲找不到下一個測試元素。無法找到softAssert失敗後的元素

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。 第二次軟斷言!!!

並停止測試。

環境:Selenium 3.5 + geckodriver + Mozilla 56.0.1。

回答

0

這看起來不是一個斷言的問題,因爲正如你所提到的第二行正在運行,但它會拋出異常。你的問題可能在這裏:p.OtsPage.fEditValue().isEnabled()

更確切地說:根據docs,NoSuchElementException拋出WebDriver.findElement(By)

您可能在fEditValue()函數中運行findElement(),您應該在那裏搜索問題。在運行時確保此功能中由選擇器表示的元素確實存在於頁面中。