0

I am trying to store the urls I need in a config file that gets pulled using ConfigSlurper. I think this may not work but not sure. Thoughts?

jrock2004
  • 3,229
  • 5
  • 40
  • 73
  • Can you please explain why would you need that and how page urls change based on different environments? – erdi Apr 03 '13 at 08:01
  • I have multiple sites and each sites have a testing site and then a live site. The sites have a backend and a frontend. So I may have test.abc.com then I would have prod.abc.com. – jrock2004 Apr 03 '13 at 12:31

3 Answers3

2

You are probably looking for functionality provided by baseUrl configuration. When using to MyPage the url which is used by the browser is determined by combining basUrl configuration and the url property of your page class.

erdi
  • 6,944
  • 18
  • 28
1

If you wanted a slightly cleaner method of doing this, you could implement a base page such as the one below - inner class for brevity and to avoid calling protected methods directly - (we have apps on 26 different subdomains!):

package page.admin

import geb.Configuration
import geb.Page

class AdminPage extends Page {

    class WrappedConfig extends Configuration {

        WrappedConfig(ConfigObject rawConfig) {
            super(rawConfig)
        }

        String getAdminBaseUrl() {
            return readValue('adminUrl', '<invalid-url>')
        }

    }

    String getPageUrl() {
        WrappedConfig config = new WrappedConfig(browser.config.rawConfig)
        return config.adminBaseUrl + this.class.url
    }

}

Your config might look something like this:

baseUrl = 'http://base-app.example.net'
adminUrl = 'http://admin-app.example.com'

This way, you can still use normal geb syntax:

given:
    to PageWhichExtendsAdminPage, 'your-path', key1: 'value1

to generate the url http://admin-app.example.com/your-path/?key1=value1

Antony Jones
  • 2,387
  • 1
  • 15
  • 18
0

I run geb on different locales so I encountered the same issue. I usually load the different urls out of a config file with locale.getCountry() as parameter for the environment.

In the running class I replace the baseUrl with the loaded entry with the ConfigSlurper. The advantage is that I can handle multiple locales and localhost environments. Testing locally vs testing the staging environment.

I have one main spock file containing the whole regression testing and a inheriting spock class for every country. The inheriting spock files doesn't contain much except the country/language encoding in the class name.

The config file:

environment{
  CA{
    url="ca.somewhere.com"
    validZipCode=...
    ...
  }
  ...
}

The main class:

class MainRegression extends GebReportingSpec{

@Shared Locale locale

def setupSpec(){
  ...
  locale = ParameterReader.getLocale(this.class.name)
  ...
}

def "testing the website"(){
  when: "entering the main url"
  go URLService.getBaseUrl(locale)
  ...

}

The inheriting class:

@Stepwise
class CaEnRegressionSpec{} // Canada with english language

A good way to handle the at-verification with different languages / locales: http://ldaley.com/post/1013531080/painless-page-identification-with-geb-grails

Krzys
  • 81
  • 1
  • 5