Is there a way to do an "if I see, then…" with webdriver acceptance testing?

58 Views Asked by At

I'm using webdriver for acceptance testing. https://codeception.com/docs/03-AcceptanceTests#WebDriver I'm running into a thing where depending on if new features are launched, a popup will sometimes be there to notify the user of the new features. So that popup may or may not be there depending on where we are in the release cycle. Is there a way to say: "If I see , click Close" ?

2

There are 2 best solutions below

1
On

You didn't say which programming language you are using, but the following in Groovy (Java) checks for an alert/modal popup. You can dismiss it in the method or use the return value in an if statement.

You should be able to adapt it for your language.

def isAlertPresent(driver){
    boolean foundAlert = false
    WebDriverWait wait = new WebDriverWait(driver, 10) //time-out secs
    try {
        wait.until(ExpectedConditions.alertIsPresent())
        foundAlert = true
    } catch (TimeoutException e) {
        foundAlert = false
    }
    return foundAlert
}
0
On

Did you checked out if Cucumber.io and Gherkin syntax works for you? With Gherkin you’ll be able to do everything you want.