這里的場景是我正在保存資料,并且在成功保存后顯示了一條祝酒詞,但是如果我把祝酒詞保存為WebElement并驗證.isDisplayed()將不會起作用,因為我認為它將被顯示,因為無論如何元素都會存在于DOM中,所以有什么其他方法可以使用祝酒詞來斷言網格中的資料保存?
uj5u.com熱心網友回復:
下面是我在專案中使用的一個驗證吐司顯示的例子:
Assert.assertTrue(validateToastMessageAppearance("invalid Entitlement") )。
其中validateToastMessageAppearance方法定義為
public boolean validateToastMessageAppearance(String message){
waitForElementToBeVisible(String.format(toastMessage,message))。
return true。
方法waitForElementToBeVisible被定義為:
public boolean waitForElementToBeVisible(By. xpath(xpath)) {
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(xpath))。
return true。
}catch (Throwable t){
return false;
}
}
而toastMessage被定義為
public String toastMessage = toast textElement;
何處
public String toast = "//div[包含(@class, 'ToastContent')]"。
而且
public String textElement = "//*[包含(text(), '%s')]"。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/318357.html
標籤:
