How to retrieve system property within GebConfig.groovy when declared in a Gradle task

31 views
Skip to first unread message

Lee

unread,
Apr 23, 2020, 7:55:06 PM4/23/20
to Geb User Mailing List
I've created a Gradle file where I define a task to execute Geb tests pretty much as follows:

task gebTest(type: Test {
 include
'somePathToTests'
 systemProperty
'geb.env', 'chrome'
)

I have the 'chrome' environment configured in my GebConfig.groovy file and that works fine.

What I'd like to do is define a new system property in the Gradle task and be able to use that from within the GebConfig file.

Example of modified Gradle task with new 'remoteUrl' system property declaration:

task gebTest(type: Test {
  include
'somePathToTests'
  systemProperty
'geb.env', 'chrome'
  systemProperty
'remoteUrl', "http://localhost:4444/wd/hub"
)



How I'm trying to use it in the GebConfig file:

standAloneURL = System.getProperty('remoteUrl')​​​​​​​

environments
{
 chrome
{
   driver
= {
     chromeOptions
.addArguments("--window-size=1920,1080")
     chromeOptions
.addArguments("--headless")
     chromeOptions
.addArguments("--disable-gpu")
     
new RemoteWebDriver(new URL(standAloneURL), chromeOptions)
   
}
 
}
}

This always fails though as it seems to not be able to get the property when it's declared in the Gradle task.

But, if I update the GebConfig file by hard coding the 'standAloneURL' to be what I want, it works fine.

Example:

This is confusing me as setting the system property 'geb.env' in my Gradle task works just fine.

Are there any suggestions as to what I may be doing wrong?

Marcin Erdmann

unread,
Apr 29, 2020, 5:54:51 PM4/29/20
to geb-...@googlegroups.com
Hi Lee,

The configuration you described looks correct to me and it should work as far as I can tell. The geb.env system property seems to be set because configuration for chrome environment is used so I don't see a reason why another property, set in the same way on the same gradle test task would not be picked up in your geb config script.

When you say that:


> This always fails though as it seems to not be able to get the property when it's declared in the Gradle task.

how exactly does this failure manifest?

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 view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/49e631e5-d019-4a9b-81b6-1a677e106a82%40googlegroups.com.

Lee

unread,
Apr 29, 2020, 9:08:11 PM4/29/20
to Geb User Mailing List
Thanks for responding Marcin.

Unfortunately, I had to move forward with a proof of concept for this and ended up implementing it a very ugly way for now.  I don't have the original results available to provide here.  I will circle back around to this and re-create what I did before and update this with the results in the near future after I finish a higher priority issue.

For what it's worth, it seemed like it just couldn't find "http://localhost:4444/wd/hubto execute against when I set 'standAloneURL' equal to that via the system property 'remoteUrl' that I set in the Gradle task.

But, if I hard-coded it in the gebconfig file it did work though.  Like this:


environments
{

 chrome
{
   driver
= {
     chromeOptions
.addArguments("--window-size=1920,1080")
     chromeOptions
.addArguments("--headless")
     chromeOptions
.addArguments("--disable-gpu")
     
new RemoteWebDriver(new URL(standAloneURL), chromeOptions)
   
}
 
}
}

Again, I'll try to re-create this soon so I can provide better info.

Thanks much,

Lee

On Wednesday, April 29, 2020 at 4:54:51 PM UTC-5, Marcin Erdmann wrote:
Hi Lee,

The configuration you described looks correct to me and it should work as far as I can tell. The geb.env system property seems to be set because configuration for chrome environment is used so I don't see a reason why another property, set in the same way on the same gradle test task would not be picked up in your geb config script.

When you say that:

> This always fails though as it seems to not be able to get the property when it's declared in the Gradle task.

how exactly does this failure manifest?

Cheers,
Marcin

To unsubscribe from this group and stop receiving emails from it, send an email to geb-...@googlegroups.com.

Lee

unread,
May 7, 2020, 10:56:00 AM5/7/20
to Geb User Mailing List
Hi Marcin,

I totally redid everything so I could try and reproduce the issue and get more error details. And of course, everything worked this time as expected.  ;-)

I must have mis-typed one little thing someplace that caused the issue initially.  

It helped to know that this 'should' work though.

Thanks again for taking a look and responding.

Take care,

Lee

Marcin Erdmann

unread,
May 10, 2020, 1:25:33 PM5/10/20
to geb-...@googlegroups.com
Yeah, getting a confirmation that what you are expecting to work should work usually helps a great deal because if it doesn't then you can be certain that it's because of some mistake on your part. I'm glad that it works for you now, Lee.

Marcin

To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/d41a5852-ecb0-4b20-ba28-0408ba1d34dc%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages