gpt4 book ai didi

maven - 使用gradle下载 repo 文件时如何设置路径

转载 作者:行者123 更新时间:2023-12-03 04:06:07 25 4
gpt4 key购买 nike

我正在使用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"
}

}

最佳答案

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

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

关于maven - 使用gradle下载 repo 文件时如何设置路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com