简体   繁体   English

如何验证是否显示 toast 消息?

[英]How to verify if toast message is displayed?

The scenario here is I'm saving data and after a successful save a toast message is displayed but if I lets say save the toast message as a WebElement and verify.isDisplayed() won't work because I think it would be displayed as element would be present in DOM anyways so any other way to assert a data save in grid using toast message?这里的场景是我正在保存数据,成功保存后会显示一条 toast 消息,但如果我说将 toast 消息保存为 WebElement 并且 verify.isDisplayed() 将不起作用,因为我认为它将显示为元素无论如何都会出现在 DOM 中,所以还有其他方法可以使用 toast 消息断言数据保存在网格中吗?

Here is an example for validation the toast is displayed I use in my project:这是验证我在项目中使用的 toast 显示的示例:

Assert.assertTrue(validateToastMessageAppearance("invalid Entitlement"));

Where validateToastMessageAppearance method defined as其中validateToastMessageAppearance方法定义为

public boolean validateToastMessageAppearance(String message){
    return waitForElementToBeVisible(String.format(toastMessage,message));
}

The method waitForElementToBeVisible is defined as: waitForElementToBeVisible方法定义为:

public boolean waitForElementToBeVisible(By.xpath(xpath)) {
    try {
    wait.until(ExpectedConditions.visibilityOfElementLocated(xpath));
    return true;
    }catch (Throwable t){
        return false;
    }
}

While toastMessage is defined as虽然toastMessage被定义为

public String toastMessage = toast + textElement;

Where在哪里

public String toast =  "//div[contains(@class,'ToastContent')]";

and

public String textElement = "//*[contains(text(),'%s')]";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM