问题描述
我想对GebConfig.groovy进行参数化,以便可以指定RemoteWebDriver URL.
I want to paramaterize GebConfig.groovy such that I can specify a RemoteWebDriver url.
我正在使用Gradle作为构建工具.
I am using Gradle as my build tool.
我的GebConfig.groovy看起来像
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
)
}
我想说的是
new URL(project.remoteURL)
通过类似这样的命令传递remoteURL的地方
Where remoteURL is passed in via the command like like
gradle test -PremoteURL=http://xx:4444/wd/hub
这可行吗? GebConfig.groovy如何获得对Gradle项目的引用?还是有其他选择?
Is this do-able? How does GebConfig.groovy get a reference to the Gradle project? Or is there a alternative?
推荐答案
那应该很简单.首先,将URL从项目属性传递到build.gradle
中的测试JVM中的系统属性:
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
}
,然后在GebConfig.groovy
中使用它创建一个RemoteWebDriver
实例.
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)
}
这篇关于Gradle GebConfig.groovy参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!