Geb

How to set a page URL dynamically in Geb

In this example, I am navigating to the About me page using the dynamically constructed URL https://yaroslavgrebnov.com/about-me/. In order to construct the URL, I’m using the convertToPath() method of the geb.Page class.

GebConfig

baseUrl is defined in GebConfig.groovy file:

baseUrl = "https://yaroslavgrebnov.com/"

AboutMePage class

dynamicUrlPart is converted to an URL path and dynamically added to the page URL. If the baseUrl is not defined, the entire page URL can be set in dynamicUrlPart.

import geb.Page

class AboutMePage extends Page {

    String dynamicUrlPart

    @Override
    String convertToPath(Object[] args) {
        "$dynamicUrlPart"
    }

    static at = {
        title == "About me | Yaroslav Grebnov"
    }
}

Test script

when:
        to new AboutMePage(dynamicUrlPart: "about-me")