Save current url with geb

geb, groovy, spock

Solution

You can use the current url getter on WebDriver class. A WebDriver instance is stored as `driver` property on Browser. So in a Geb Spock test it is as simple as saying:

driver.currentUrl

EDIT

Since Geb 0.9.3 there is also a current url getter available on `Browser`.

Problem

I work with tests on `geb` and I have problem. I need to save/print the address of the current page (function `SaveUrl()`). Spock Test: ``` 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() } } ``` GooglePage: ``` 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") } } } ``` Please help save/print current URL. Thank You!

Original source