2

I want to paramaterize GebConfig.groovy such that I can specify a RemoteWebDriver url.

I am using Gradle as my build tool.

My GebConfig.groovy looks like

import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver

driver = {
   DesiredCapabilities capabilities = DesiredCapabilities.firefox()
   new RemoteWebDriver(
     new URL("http://xx:4444/wd/hub"), capabilities
   )
}

What I want to do is to say

new URL(project.remoteURL)

Where remoteURL is passed in via the command like like

gradle test -PremoteURL=http://xx:4444/wd/hub

Is this do-able? How does GebConfig.groovy get a reference to the Gradle project? Or is there a alternative?

IanWatson
  • 1,649
  • 2
  • 27
  • 49

1 Answers1

4

That should be fairly simple. First, pass the url from project property to a system property in the test JVM in your build.gradle:

test {
    systemProperty "com.example.test.remoteWebDriverUrl", project.remoteURL
}

And then use it in GebConfig.groovy to create a RemoteWebDriver instance.

driver = {
    DesiredCapabilities capabilities = DesiredCapabilities.firefox()
    URL url = new URL(System.getProperty("com.example.test.remoteWebDriverUrl")
    new RemoteWebDriver(url, capabilities)
}
erdi
  • 6,944
  • 18
  • 28