4

I'm using Geb to write some browser automation tests. It allows you to configure a baseUrl and specify browser actions relative to this, as detailed in The Book of Geb. This works nicely for paths within the site but I can't see any syntax for dealing with subdomains.

Is there a simple way of going from baseUrl = http://myapp.com/ to http://sub.myapp.com using the Geb DSL or am I going to have to grab the property that defines the baseUrl in code and use it to generate the subdomain?

Chris
  • 99
  • 1
  • 4
  • what exactly are you trying to achieve? run the same tests against different domains or switch domains within the same set of tests? – erdi Feb 01 '13 at 09:43
  • I'm trying to switch to a subdomain of my baseUrl as part of a test. So I have a Page object where the url is defined relative to the baseUrl (eg. url = "signup/" which is equivalent to /signup) I want to define another page object that whose url is a subdomain of the baseUrl (eg. account.). I can populate that value in code but am just wondering if there is an easy way in the DSL (that I am missing) to specify it. The baseUrl property is useful for testing across a number of different environments. – Chris Feb 11 '13 at 12:20

3 Answers3

1

As stated by erdi there seems to be no way to currently do it. In the end we added an overridden version of getPageUrl() to our subclass of Page.

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 like this for 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

Chris
  • 99
  • 1
  • 4
1

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 successfully use it to switch server contexts of the same application.

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

If you are running tests using Spock this needs to be done before each feature as it gets reset.

twinj
  • 2,009
  • 18
  • 10
0

As far as I know there is no way to modify baseUrl during test execution other than by directly setting it in the config:

browser.config.baseUrl = 'http://sub.myapp.com'
erdi
  • 6,944
  • 18
  • 28
  • Thanks, yeah we came to the same conclusion and implemented the feature in code as expanded on in my answer. – Chris Jun 13 '13 at 15:21