简体   繁体   中英

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?

Here is an example for validation the toast is displayed I use in my project:

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

Where validateToastMessageAppearance method defined as

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

The method waitForElementToBeVisible is defined as:

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

While toastMessage is defined as

public String toastMessage = toast + textElement;

Where

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

and

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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