having multiple baseUrls or switching baseUrl per feature method ?

428 views
Skip to first unread message

Torsten Reinhard

unread,
Jun 27, 2016, 5:57:58 AM6/27/16
to Geb User Mailing List
Hi,

I´m trying to use Geb for automated infrastructure tests in multiple environments - and later on for regression tests.
My Infrastructure has some Apache´s and Application Servers which are connected, each with a different baseURL:

// DEV environment for example
..
https://mycompany/myApache
https://mycompany/myApache:1000
https://mycompany/myApache:2000
https://mycompany/myAppServer:1111
https://mycompany/myAppServer:2222
....

I´m executing all *Spec tests from Maven (3.3.3) , using the PhantomJsDriver (2.1.1), setup with the phantomjs-maven-plugin.

For testing the global setup (proxy, network, ....) I´ve also created a simple InternetAccessSpec:

class GoogleHomePage extends Page {
 
static url = "http://www.google.com"
 
 
static at = { title == "Google" }
}

class InternetAccessSpec extends GebReportingSpec {

 
def internetURLReachable() {

   
when:
    browser
.to GoogleHomePage

   
then:
    browser
.page.verifyAt()
 
}
}

This spec is running fine, but the next Specs - running on different baseUrls - are all failing - changing the baseUrl seems not to work:

class PayaraAdminPage extends Page {
 
static url = "index.html"
 
static at = { title == "Login" }
}

class PayaraSpec extends GebReportingSpec {

 
def @Shared GPathResult adminServer
 
 
def setupSpec() {
   
..
    adminServer
= readFromJSon()
 
}

 
def String adminInstanceURL() {
   
String hostname = adminServer.hostname
   
String port = adminServer.port

   
return "https://${hostname}:${port}/"
 
}

 
/**
   * Test Login Page shows up.
   */

 
def "admin console available"() {
    given
:
    browser
.go adminInstanceURL()

   
when:
    browser
.to PayaraAdminPage

   
then:
    browser
.page.verifyAt()
 
}

 
/**
   * Test *'server running' is displayed
   */

 
@Unroll
 
def "server running at #baseUrl"(String baseUrl) {

    given
:
    browser
.go baseUrl

   
when:
    browser
.to PayaraPage

   
then:
    browser
.page.verifyAt()

   
where:
    baseUrl
<< myData.collect { "https://${it.hostname.text()}:${it.sslport.text()}/" }
 
}
}

In the screenshots created by GebReportingSpec i still see "Google" displayed in the browser.

What am I doing wrong here ?

As far as I understood the docs, setting the baseUrl is possible at startup (GebConfig), as well as in the prepartion of a GebSpec.

Thanx for any advice,

Torsten

Marcin Erdmann

unread,
Jul 3, 2016, 8:40:33 AM7/3/16
to Geb User Mailing List
Hi Torsten,

You should have a look at the Making Requests section of the manual (http://www.gebish.org/manual/current/#making-requests) to understand what base url is and how relative and absolute urls are resolved in GEB.

From the example you posted I would expect that you're getting an exception telling you that baseUrl has been requested but has not been set. Or you set a baseUrl in the GebConfig.groovy file without telling us. Anyway, given that your PayaraAdminPage has a relative url then you should be setting the baseUrl property of browser to the result of adminInstanceURL() and then navigating to that page:

given:
baseUrl = adminInstanceURL()

when:
to PayaraAdminPage

then:
at PayaraAdminPage


Cheers,
Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/d9a1bf89-f095-4034-aa54-6aff120e3993%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages