How to set baseUrl at runtime?

2,768 views
Skip to first unread message

dean.delponte

unread,
Jun 15, 2015, 11:35:28 AM6/15/15
to geb-...@googlegroups.com
I'm utilizing the example project at https://github.com/geb/geb-example-cucumber-jvm to run Cucumber with Geb.

The baseUrl changes depending on if I'm testing code that's in development, staging or production.

What's the recommended way for changing the baseUrl at runtime?

Can a parameter simply be passed in via the command line?

Thanks! 

- Dean

dean.delponte

unread,
Jun 16, 2015, 9:58:35 AM6/16/15
to geb-...@googlegroups.com
Is it typical that people do not change the URL at runtime?  I'm thinking it may useful when executing these tests on Jenkins.

Brian Kotek

unread,
Jun 16, 2015, 10:05:45 AM6/16/15
to geb-...@googlegroups.com
At least in my experience, I change the URL all the time (when navigating between pages). But I've never needed to change the base URL, since everything I'm testing is usually under a the same base URL...

--
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/e442ee94-5e88-4acf-b082-7ecacb9468cb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael Kutz

unread,
Jun 16, 2015, 11:03:56 AM6/16/15
to geb-...@googlegroups.com

You can just use environments in the GebConfig.groovy to set a different baseUrl. Then you just make Jenkins/CI call Maven/Groovy with -Dgeb.env parameter.


dean.delponte

unread,
Jun 16, 2015, 4:05:02 PM6/16/15
to geb-...@googlegroups.com
Thanks Micha.  I've tried that approach and was unable to get it to work.

Ultimately, what I did is update env.groovy to check for an external config file where the baseUrl value is available.

I recall trying something similar previously but the baseUrl was required to be set

Jim Shingler

unread,
Jun 16, 2015, 7:47:18 PM6/16/15
to geb-...@googlegroups.com
From Geb Spock Gradle example. Hope it helps // If you wanted to set the baseUrl in your build…
// systemProperty "geb.build.baseUrl", "http://myapp.com"


For more options, visit https://groups.google.com/d/optout.

Marcin Erdmann

unread,
Jun 18, 2015, 4:06:33 AM6/18/15
to geb-...@googlegroups.com
Dean,

Environments are used to flip the driver used in GebConfig.groovy on the example project that uses cucumber to drive Geb and it works: https://github.com/geb/geb-example-cucumber-jvm/blob/master/src/test/resources/GebConfig.groovy#L15.

One caveat is that since 0.8 the Gradle cucumber project runs features in a separate JVM so you need to pass the geb.env system property over from the build JVM to the cucumber JVM: https://github.com/geb/geb-example-cucumber-jvm/blob/master/build.gradle#L80.

Chi Cuong Le

unread,
Sep 3, 2017, 10:31:35 AM9/3/17
to Geb User Mailing List
I think the idea is great. I'm facing exactly the issue as I'm trying to implement continuous delivery. There are few GUI tests using geb, and they will run on different test environment. And I think a smoke test against PRODUCTION environment is also useful.

I found a workaround for this issue:
in GebConfig.groovy, we can put our logic directly where baseUrl is defined. example:

dw...@groupon.com

unread,
Feb 2, 2018, 12:09:57 PM2/2/18
to Geb User Mailing List
I need to change the base url for every tests. Like I am running tests for Uk, Us and so on. So for Uk tests the base url is www.myurl-uk.com and for us www.myurl-us.com. I need to set the base url run time. How to do that with Geb - spoke?

Thanks.

Roman Tretyak

unread,
Feb 3, 2018, 2:37:08 AM2/3/18
to Geb User Mailing List
def setupSpec() {
   browser.setBaseUrl(..)
}

-Roman

пятница, 2 февраля 2018 г., 19:09:57 UTC+2 пользователь dw...@groupon.com написал:

Alexander Kriegisch

unread,
Feb 3, 2018, 6:37:34 AM2/3/18
to geb-...@googlegroups.com
To the original poster: I do not want to be disrespectful, but really, is it asking to much to at least take a cursory glance at the manual?

http://www.gebish.org/manual/current/#base-url

There the very first paragraph of that chapter tells you how to set the base URL via configuration or via API call. I mean, come on, do you really need a mailing list for that? Geb's manual is exceptionally good for an open source product.

Regards
--
Alexander Kriegisch
https://scrum-master.de


Roman Tretyak schrieb am 03.02.2018 14:37:
>
> def setupSpec() {
> browser.setBaseUrl(..)
>
> }
>
>
>> I need to change the base url for every tests. Like I am running tests
>> for Uk, Us and so on. So for Uk tests the base url is
>> www.myurl-uk.com <http://www.myurl-uk.com>
>> and for us www.myurl-us.com
>> <http://www.myurl-us.com> . I need to set the base url run
Reply all
Reply to author
Forward
0 new messages