passing baseUrl from gradle commandline

1,118 views
Skip to first unread message

Geemang

unread,
Feb 18, 2016, 9:27:32 AM2/18/16
to Geb User Mailing List
I'm attempting to do: ./gradlew -Dgeb.build.baseUrl=https://dev-admin.domain.info -Dtest.single=LoginSpec test


LoginSpec > can get to the login page FAILED
    geb.error.NoBaseUrlDefinedException at LoginSpec.groovy:21


2 Questions:

1) Is it possible to pass the baseUrl using gradle?
2) How do you target a specific test?

TIA,
Geemang

Brian Kotek

unread,
Feb 18, 2016, 10:11:41 AM2/18/16
to Geb User Mailing List
I don't think so. I ended up adding options like running subsets of tests to settings.gradle, like this:

testPatternMatch=*

Then, in build.gradle, I can look for that and set the appropriate System properties:

if( project.hasProperty( "testPatternMatch" ) && project[ "testPatternMatch" ] != "*" ) {
  System.setProperty( "integrationTest.single", testPatternMatch )
}

This way, I can run all tests, or all tests matching a pattern, or just one specific test (by using the full test name).


--
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/43f44d99-8921-44a8-8dce-3ceabfbc94e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcin Erdmann

unread,
Feb 20, 2016, 1:45:18 PM2/20/16
to Geb User Mailing List
To pass the baseUrl from command line when invoking gradle you need to set the system property on the test task because the system properties set for the build are not by default passed to the jvm running the tests. In your gradle build script you need to add:

test {
    systemProperties("geb.build.baseUrl": System.getProperty("geb.build.baseUrl"))
}

You can also use project properties instead of system properties when passing the build url from the command line to save yourself some typing:

test {
    if (project.hasProperty("baseUrl") {
        systemProperties("geb.build.baseUrl": project.baseUrl)
    }
}

and:

./gradlew -PbaseUrl="https://dev-admin.domain.info" test


To run a single test you can use the --tests switch (https://docs.gradle.org/current/userguide/java_plugin.html#test_filtering):

./gradlew test --tests="*LoginSpec"

--
Message has been deleted

tu Mimi

unread,
Dec 7, 2016, 5:58:38 AM12/7/16
to Geb User Mailing List
Hi Marcin,

first of all thanks a lot for your work investigated to Geb. I love this cool framework!

Based on your geb-example-gradle-master project from github I added the project properties to "build.gradle"

test {
if (project.hasProperty("baseUrl")) {
systemProperties("geb.build.baseUrl": project.baseUrl)
}
dependsOn drivers.collect { tasks["${it}Test"] }
enabled = false
}

and deactivated the baseUrl in "GebConfig.groovy"

// To run the tests with all browsers just run “./gradlew test”
// baseUrl = "http://gebish.org"

But following error is thrown if I tried to pass the baseUrl via command line (only GebishOrgSpec was unter test, GebishOrgTest was out of the test scope)

> gradle -PbaseUrl="http://gebish.org" chromeTest
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources
:testClasses
:downloadChromeDriver UP-TO-DATE
:unzipChromeDriver UP-TO-DATE
:chromeTest

GebishOrgSpec > can get to the current Book of Geb FAILED
    org.openqa.selenium.WebDriverException at GebishOrgSpec.groovy:7
        Caused by: org.openqa.selenium.remote.ScreenshotException at GebishOrgSpec.groovy:7
            Caused by: org.openqa.selenium.WebDriverException

1 test completed, 1 failed
:chromeTest FAILED

FAILURE: Build failed with an exception.

Do you know what´s wrong? Do I miss any thing?

Kind regards
Tu

tu Mimi

unread,
Dec 8, 2016, 7:12:47 AM12/8/16
to Geb User Mailing List
ok, I found a workaround for this:

ext.myUrl= project.hasProperty('myUrl') ? project.getProperty('myUrl') : 'No url delivered'

task 'example'(type: Test) {
....
systemProperty "geb.build.baseUrl", myUrl
}

>gradle example -PshopUrl=...
...
BUILD SUCCESSFUL
Reply all
Reply to author
Forward
0 new messages