【问题标题】:Is there a way to do an "if I see, then…" with webdriver acceptance testing?有没有办法通过 webdriver 验收测试来做“如果我看到,那么……”?
【发布时间】:2021-01-25 18:52:32
【问题描述】:

我正在使用 webdriver 进行验收测试。 https://codeception.com/docs/03-AcceptanceTests#WebDriver 我遇到了一个问题,根据是否启动了新功能,有时会弹出一个窗口来通知用户新功能。因此,根据我们在发布周期中所处的位置,该弹出窗口可能存在也可能不存在。有没有办法说:“如果我看到,请单击关闭”?

【问题讨论】:

    标签: selenium-webdriver webdriver selenium-chromedriver codeception acceptance-testing


    【解决方案1】:

    您没有说您使用的是哪种编程语言,但 Groovy (Java) 中的以下内容会检查警报/模式弹出窗口。您可以在方法中关闭它或在 if 语句中使用返回值。

    您应该能够根据您的语言对其进行调整。

    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
    }
    

    【讨论】:

    • 对不起,我假设我发布的链接会推断出我使用的是 PHP,但 WebDriver 是 WebDriver,尤其是基于 C 的语言,所以我会试试看如果它在 PHP 中工作!
    【解决方案2】:

    您是否检查过Cucumber.ioGherkin 语法是否适合您? 有了 Gherkin,您就可以随心所欲。

    【讨论】:

      猜你喜欢
      • 2016-09-22
      • 2011-06-09
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2020-04-28
      • 2021-04-23
      相关资源
      最近更新 更多