Search code examples
seleniumspockgeb

Changing Geb baseUrl in runtime


I want to write and end to end test that involves 2 systems

  • System 1: www.sys1.com
  • System 2: www.sys2.com

The process that im trying to test starts with system 1 and eventually I will be able to see changes in system 2. When I start my tests, I pass the following parameter to geb

-Dgeb.build.baseUrl=http://www.sys1.com/

I want somehow in the middle of my test to reconfigure the baseUrl so i can navigate to pages in www.sys2.com

Is this possible? if so how?

Tech stuff:

  • Geb 1.1.1
  • Selenium 3.0.1
  • Groovy 2.4.7

Solution

  • This is possible by using browser.setBaseUrl:

    APage:

    class APage extends Page
    {
       static url = "myUrl/"
    }
    

    Geb Config:

    baseUrl = "http://www.google.com/"
    

    Example:

        browser.to(APage) //Goes to http://www.google.com/myUrl/
    
        browser.setBaseUrl("http://www.mynewurl.com/") // sets new baseUrl
    
        browser.to(APage) //Goes to http://www.mynewurl.com/myUrl/