0
我正在使用Try工程並使用Try-Catch塊聲明內容,但TestNg會在類斷言失敗時中斷類。爲什麼這麼做,請提出任何想法。在迭代器循環中斷言失敗時TestNG測試中斷
while (countryListiterator.hasNext()) {
searchResultPO toSearchpage = homeTosearch.search(countryListiterator.next());
try {
errorCellinSearchpage = driver.findElement(By.xpath(errorCellXpath));
Assert.assertFalse(errorCellinSearchpage.isDisplayed()));
} catch (Exception E) {
E.printStackTrace();
E.getCause();
E.getStackTrace();
}
}
不,它實際上顯示,我得到java.lang.AssertionError和程序停止。其餘的迭代被發現。 – user3596755
錯誤java.lang.AssertionError表示斷言失敗,只有在errorCellinSearchpage.isDisplayed()返回true時纔會發生[Means item is displayed]。我認爲你應該使用Assert.assertTrue。 – h4k3r
我實際上聲稱失敗,因爲我不期望在頁面中看到該元素 - 即使它這樣做,testng類也不應該中斷。 – user3596755