【问题标题】:Save current url with geb用geb保存当前网址
【发布时间】:2013-04-26 15:58:24
【问题描述】:

我在 geb 上进行测试,但我遇到了问题。我需要保存/打印当前页面的地址(函数SaveUrl())。

Spock 测试:

class TestSpec extends GebReportingSpec {
def "Google"() {
    given: "go to google.com"
    to GooglePage

    when: "we at Google home page"
    at GooglePage

    then: "Search Yahoo"
    Search("Yahoo")
    SaveUrl()
    }
}

谷歌页面:

class GooglePage extends Page {
    static url = "http://www.google.by"
    static at = { $("title").text() == "Google"}
    static content = {
        theModule { module SearchModule }
    }

def Search(String arg0) {
    theModule.field.value(arg0)
    theModule.search.click()
    }

def SaveUrl() {
    // need implement
    }
}

Modile:

class SearchModule extends Module {
static content = {
    field { $("input", name: "q") }
    search { $("input", name: "btnK") }
    }
}

请帮助保存/打印当前 URL。
谢谢你!

【问题讨论】:

    标签: groovy spock geb


    【解决方案1】:

    您可以在 WebDriver 类上使用current url getter。 WebDriver 实例存储为driver property on Browser。因此,在 Geb Spock 测试中,就像这样简单地说:

    driver.currentUrl
    

    编辑

    从 Geb 0.9.3 开始,还有一个 current url getter available on Browser

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2012-08-31
      • 2019-10-03
      相关资源
      最近更新 更多