当使用gradle下载repo时,如何设置路径

时间:2013-11-19 04:53:27

标签: maven gradle selenium-chromedriver

我正在使用gradle从maven下载selenium chrome驱动程序

webtestsCompile 'org.seleniumhq.selenium:selenium-chrome-driver:2.32.0'

我试图直接使用它,我发现我收到了这个错误:

  Caused by:
    java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

我已经从堆栈溢出和其他地方查找了几个问题,它要求我将属性webdriver.chrome.driver的值设置为我已下载的位置,如下所示:

System.setProperty("webdriver.chrome.driver", "path to chrome-driver");

我想知道最好的方法是什么?

编辑1:

我验证了java.class.path,这条路径的片段如下所示:

/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar

这看起来像java.class.path中存在selenium-chrome-driver。

编辑2:

我希望Chrome驱动程序无论我使用的操作系统如何都能正常工作,目前我在ubuntu盒子上,但很多都会在Windows机器上进行测试。当我将webdriver.chrome.driver的值硬编码为EDIT 1中的值时,我面临以下问题:

 java.lang.IllegalStateException: The driver is not executable: /home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar

编辑3:

我正在运行测试套件的任务 -

task webs(type: Test, dependsOn: updateNodeModules) {
testClassesDir = sourceSets.webtests.output.classesDir
classpath = sourceSets.webtests.runtimeClasspath

def javaHomeBin = new File(System.getProperty("java.home"), "bin");
def javaExec = new File(javaHomeBin, "java").getAbsolutePath();

systemProperties['jar.path'] = jar.archivePath

if(project.hasProperty('url')){
  println" url passed as variable is $url"
  systemProperties["selenium.webdriver.url"] = "$url"
 }
 systemProperties["selenium.webbrowser.type"] = "firefox"
 if(project.hasProperty('browser')){
 println "the browser passed is $browser"
 systemProperties["selenium.webbrowser.type"] = "$browser"
 }


include '**/UserEditControllerWebTest.class'

doFirst {
println " iterator is $it"
  def chrome=configurations.testRuntime.find { 
        it.name.contains("selenium-chrome-driver")
    }.path
    println " chrome driver path is $chrome"
    systemProperties["webdriver.chrome.driver"]= "$chrome"
  }

}

1 个答案:

答案 0 :(得分:1)

假设您需要为测试设置此系统属性,您可以执行以下操作:

test.doFirst {
    systemProperty "webdriver.chrome.driver", 
        classpath.find { 
            it.name.contains("selenium-chrome-driver")
        }.path
}