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 In order to construct the URL, I’m using the convertToPath() method of the geb.Page class.


baseUrl is defined in GebConfig.groovy file:

baseUrl = ""

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

    String convertToPath(Object[] args) {

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

Test script

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