gpt4 book ai didi

java - 无法使用 Gradle 刷新 Selenium 的依赖项

转载 作者:行者123 更新时间:2023-11-30 06:10:19 25 4
gpt4 key购买 nike

我不明白为什么 Gradle 不下载 Selenium,即使有 refresh-dependencies,鉴于 Hibernate 下载正常。 Selenium 正在使用 mavenCentral 存储库,就像 Hibernate 一样:

thufir@mordor:~/NetBeansProjects/sel$ 
thufir@mordor:~/NetBeansProjects/sel$ gradle clean run --refresh-dependencies
:clean
:compileJava
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-core/3.6.7.Final/hibernate-core-3.6.7.Final.pom
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-parent/3.6.7.Final/hibernate-parent-3.6.7.Final.pom
Download https://jitpack.io/com/github/THUFIR/hello_api/master-SNAPSHOT/hello_api-master-1-gef696be-2.pom
Download https://repo1.maven.org/maven2/antlr/antlr/2.7.6/antlr-2.7.6.pom
Download https://repo1.maven.org/maven2/commons-collections/commons-collections/3.1/commons-collections-3.1.pom
Download https://repo1.maven.org/maven2/dom4j/dom4j/1.6.1/dom4j-1.6.1.pom
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-commons-annotations/3.2.0.Final/hibernate-commons-annotations-3.2.0.Final.pom
Download https://repo1.maven.org/maven2/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.pom
Download https://repo1.maven.org/maven2/javax/transaction/jta/1.1/jta-1.1.pom
Download https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.pom
Download https://repo1.maven.org/maven2/org/slf4j/slf4j-parent/1.6.1/slf4j-parent-1.6.1.pom
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-core/3.6.7.Final/hibernate-core-3.6.7.Final.jar
Download https://repo1.maven.org/maven2/antlr/antlr/2.7.6/antlr-2.7.6.jar
Download https://repo1.maven.org/maven2/commons-collections/commons-collections/3.1/commons-collections-3.1.jar
Download https://repo1.maven.org/maven2/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-commons-annotations/3.2.0.Final/hibernate-commons-annotations-3.2.0.Final.jar
Download https://repo1.maven.org/maven2/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar
Download https://repo1.maven.org/maven2/javax/transaction/jta/1.1/jta-1.1.jar
Download https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar
/home/thufir/NetBeansProjects/sel/src/main/java/net/bounceme/mordor/javascript/Main.java:25: error: no suitable constructor found for FirefoxDriver(URL)
driver = new org.openqa.selenium.firefox.FirefoxDriver(url);
^
constructor FirefoxDriver.FirefoxDriver(FirefoxProfile) is not applicable
(argument mismatch; URL cannot be converted to FirefoxProfile)
constructor FirefoxDriver.FirefoxDriver(Capabilities) is not applicable
(argument mismatch; URL cannot be converted to Capabilities)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 15.867 secs
thufir@mordor:~/NetBeansProjects/sel$

构建文件:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'net.bounceme.mordor.javascript.Main'
//version = 'dev'
//group = 'com.some.project'
description = 'hello world KISS'


clean{
delete "javascript"
}

sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
if (!hasProperty(mainClassName)) {
ext.mainClass = mainClassName
}

repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}


dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
compile 'com.github.THUFIR:hello_api:master-SNAPSHOT'
}

jar.doFirst
{
def manifestClasspath = configurations.runtime.collect { it.name }
manifestClasspath = manifestClasspath.unique().join(" ")
println (manifestClasspath)
manifest.attributes.put("Main-Class", mainClassName)
manifest.attributes.put("Class-Path", manifestClasspath)
}

最佳答案

您的问题:

/home/thufir/NetBeansProjects/sel/src/main/java/net/bounceme/mordor/javascript/Main.java:25: error: no suitable constructor found for FirefoxDriver(URL)
driver = new org.openqa.selenium.firefox.FirefoxDriver(url);
^
constructor FirefoxDriver.FirefoxDriver(FirefoxProfile) is not applicable
(argument mismatch; URL cannot be converted to FirefoxProfile)
constructor FirefoxDriver.FirefoxDriver(Capabilities) is not applicable
(argument mismatch; URL cannot be converted to Capabilities)

这里是参数不匹配问题。

根本原因分析:

从你的 build.xml 文件,

mainClassName = 'net.bounceme.mordor.javascript.Main'

执行 Main.java 类。

Main.java 类中,有一个声明/对象创建 driver = new org.openqa.selenium.firefox.FirefoxDriver(url); 会产生错误.

这里 Java 编译器无法构造 FirefoxDriver(URL) 对象,因为您对构造函数的调用与它的任何已知构造函数都不匹配。


具体来说,编译器找到了构造函数:

FirefoxDriver.FirefoxDriver()

但是您的调用如下所示,这是不匹配的:

new org.openqa.selenium.firefox.FirefoxDriver(url); // remove url from this section.

解决方案:

Main.java 行号 25 中更改您的代码

driver = new org.openqa.selenium.firefox.FirefoxDriver();

希望,它能解决您的问题。

相关链接:

  1. selenium-java : 2.53.0
  2. How to configure selenium tests with gradle?
  3. Executing Appium Tests with Gradle

关于java - 无法使用 Gradle 刷新 Selenium 的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36034319/

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