Can Geb baseUrl navigation system be used with subdomains?

I am using Geb to write tests for browser automation. It allows you to configure baseUrl

and specify the action on this browser, as described in of The Book of Geb . This works well for paths within a site, but I don't see the syntax for working with subdomains.

Is there an easy way to navigate from baseUrl = http://myapp.com/

to http://sub.myapp.com

using the Geb DSL or will I have to grab the property that defines the baseUrl in the code and use that to create the subdomain?

+3


source to share


3 answers


As indicated by erdi, there seems to be no way to do this right now. We ended up adding an overridden version of getPageUrl () to our page subclass.

String getPageUrl() {
    def subdomainPresent = this.class.declaredFields.find {
        it.name == 'subdomain' && isStatic(it.modifiers)
    }
    if( subdomainPresent ) {
        def baseURL = getBrowser().getConfig().getBaseUrl()
        def splicePoint = baseURL.indexOf('//') + 1

        pageUrl = baseURL[0..splicePoint] + this.class.subdomain + "." + baseURL[splicePoint+1..-1] + pageUrl
    }
    pageUrl
}

      

Used as for an account. {baseUrl} / login



class MyPage extends MyPageBase{
    static subdomain = "account"
    static url = "login"
}

      

Documented here as a pull request https://github.com/geb/geb/pull/37/files

+1


source


In Geb, the Browser class has this method:

    /**
 * Changes the base url used for resolving relative urls.
 * <p>
 * This method delegates to {@link geb.Configuration#setBaseUrl}.
 */
void setBaseUrl(String baseUrl) {
    config.baseUrl = baseUrl
}

      

Geb Javadoc



I have been successfully using it to switch server contexts of the same application.

eg:    browser.setBaseUrl('http://int/app/pages/') browser.setBaseUrl('http://ci/sameapp/pages/')

If you are running tests using Spock, this must be done before each function as it gets reset.

+1


source


As far as I know, there is no way to change baseUrl

while the test is running, other than setting it directly in config:

browser.config.baseUrl = 'http://sub.myapp.com'

      

0


source







All Articles