简体   繁体   English

Web驱动程序的依赖性问题-无法从最终类继承

[英]Dependency problems with Web Drivers - cannot inherit from final class

I was trying to run various web drivers (ChromeDriver and HtmlUnitDriver) in my maven Java project, but I encountered errors which I suspect to be maven dependency issues. 我试图在我的maven Java项目中运行各种Web驱动程序(ChromeDriver和HtmlUnitDriver),但是遇到了一些错误,我怀疑这是maven依赖问题。 I am seeing if anybody could help me spot the source of the error? 我正在查看是否有人可以帮助我发现错误的根源?

Below are the error messages: 下面是错误消息:

(For ChromeDriver) (对于ChromeDriver)

Exception in thread "main" 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://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
...etc...

(For HTMLUnitDriver) (对于HTMLUnitDriver)

Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:542)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:506)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:150)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1281)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1198)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:474)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:463)
...etc...

I have examined my pom.xml file (relevant section as below) and I am still not sure where the problem lies. 我已经检查了pom.xml文件(相关部分如下),但我仍然不确定问题出在哪里。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ret</groupId>
<artifactId>inventory</artifactId>
<version>1.0</version>
<name>inventory</name>
<description>Core inventory modules to support plugins and batch reports.</description>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
    <repository>
        <id>ret</id>
        <url>https://dev2.ret.com/snapshots</url>
    </repository>
    <repository>
        <id>sonatype</id>
        <url>http://oss.sonatype.org/content/repositories/releases/</url>
    </repository>
</repositories>
<distributionManagement>
    <snapshotRepository>
        <id>maven3-snapshot-repository</id>
        <name>Maven3 Snapshot Repository</name>
        <url>scp://dev.ret.com/snapshots/</url>
        <uniqueVersion>false</uniqueVersion>
    </snapshotRepository>
</distributionManagement>
<dependencies>
    <dependency>
        <groupId>com.ret</groupId>
        <artifactId>common</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>  <!-- declare the exclusion here -->
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-htmlunit-driver</artifactId>
        <version>2.37.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>2.37.1</version>
    </dependency>
    <dependency>
        <groupId>com.ret</groupId>
        <artifactId>crawl</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.ret</groupId>
        <artifactId>plugin</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
        <type>jar</type>
        <optional>false</optional>
    </dependency>


</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <excludes>
                                <exclude>junit:junit</exclude>
                                <exclude>org.apache.maven:lib:tests</exclude>
                                <exclude>crawl*:jar</exclude>
                            </excludes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <extensions>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh</artifactId>
            <version>1.0</version>
        </extension>
    </extensions>
</build>

And here is the test class on which I am running the web drivers. 这是我正在运行Web驱动程序的测试类。

 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.htmlunit.HtmlUnitDriver;

 public class TestClass {

     public static void main(String[] args){

         WebDriver driver = new HtmlUnitDriver();
         driver.get("http://www.google.com");

         System.setProperty("webdriver.chrome.driver",  "/Users/tank/Documents/workspace/chromedriver");
         WebDriver webDriver = new ChromeDriver();
         webDriver.get("http://www.google.com");

     }
}

Any form of help/feedback on the possible sources of errors will be appreciated :) Thank you! 任何形式的帮助/反馈,包括可能的错误源,将不胜感激:)谢谢!

  1. For ChromeDriver, you must install another executable as hinted here , the simplest way is to download it and add it to your PATH . 对于ChromeDriver,您必须按照此处的提示安装另一个可执行文件,最简单的方法是将其下载并添加到PATH
  2. For HtmlUnitDriver, you are mixing versions of selenium-htmlunit-driver , selenium-chrome-driver and selenium-java , all of them should be exact match, so you don't have conflicting dependencies. 对于HtmlUnitDriver,您要混合使用selenium-htmlunit-driverselenium-chrome-driverselenium-java ,它们应该完全匹配,因此不会有相互依赖的依赖关系。 Also, you shouldn't explicitly add commons-httpclient , since it may conflict with an already defined dependency. 另外,您不应显式添加commons-httpclient ,因为它可能与已经定义的依赖项冲突。

    I would just depend on selenium-chrome-driver and selenium-htmlunit-driver in your case, without anything else. 在您的情况下,我只依赖selenium-chrome-driverselenium-htmlunit-driver ,无需其他任何操作。

Try to find where the problem really lays, debug the code without maven. 尝试查找问题的根源,在不使用maven的情况下调试代码。 and then proceed forward. 然后继续前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM