是什么导致JBrowserDriver WebDriverException:org / openqa / selenium / security / Credentials

时间:2018-01-17 23:35:30

标签: java selenium selenium-webdriver webdriver

我正在尝试使用JDK 8和InteliJ 2017在Windows 10中创建JBrowserDriver的工作实现,但遇到了一个我无法解决的异常。有谁知道为什么我会得到这个例外?

Exception in thread "main" org.openqa.selenium.WebDriverException: org/openqa/selenium/security/Credentials

我成功设置了EdgeDriver,InternetExplorerDriver,ChromeDriver,FirefoxDriver和PhantomJSDriver的工作实现。不幸的是,JBrowserDriver的这个例外让我感到困惑。

该课程如下:

package app;

import org.openqa.selenium.WebDriver;
import com.machinepublishers.jbrowserdriver.Timezone;
import com.machinepublishers.jbrowserdriver.JBrowserDriver;
import com.machinepublishers.jbrowserdriver.Settings;

public class Go {
    public static void main(String[] args) {
        JBrowserDriver driver = new JBrowserDriver(Settings.builder().timezone(Timezone.AMERICA_DENVER).build());
        driver.get("https://www.google.com");
        String title = driver.getTitle();
        System.out.println(title);
        driver.quit();
    }
}

Maven pom.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<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>app.group</groupId>
    <artifactId>Template</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>app.Go</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

            <plugin>
                <!-- http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html -->
                <!-- http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <!-- http://www.oracle.com/technetwork/java/javase/overview/index.html -->
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-exec -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>1.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient-cache -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient-cache</artifactId>
            <version>4.5.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.machinepublishers/jbrowserdriver -->
        <dependency>
            <groupId>com.machinepublishers</groupId>
            <artifactId>jbrowserdriver</artifactId>
            <version>0.17.11</version>
        </dependency>

    </dependencies>

</project>

这是完整的堆栈跟踪:

Exception in thread "main" org.openqa.selenium.WebDriverException: org/openqa/selenium/security/Credentials
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'NeonFlimsy', ip: '10.0.0.224', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: TestJBrowserDriver
    at com.machinepublishers.jbrowserdriver.Util.handleException(Util.java:139)
    at com.machinepublishers.jbrowserdriver.JBrowserDriver.<init>(JBrowserDriver.java:352)
    at app.TestJBrowserDriver.launch(TestJBrowserDriver.java:16)
    at app.Go.main(Go.java:17)
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/security/Credentials
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetPublicMethods(Class.java:2902)
    at java.lang.Class.getMethods(Class.java:1615)
    at sun.rmi.server.Util.getRemoteInterfaces(Util.java:244)
    at sun.rmi.server.Util.getRemoteInterfaces(Util.java:216)
    at sun.rmi.server.Util.createProxy(Util.java:146)
    at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:224)
    at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:383)
    at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:346)
    at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:225)
    at com.machinepublishers.jbrowserdriver.RemoteObject.<init>(RemoteObject.java:26)
    at com.machinepublishers.jbrowserdriver.AlertServer.<init>(AlertServer.java:46)
    at com.machinepublishers.jbrowserdriver.Context.<init>(Context.java:65)
    at com.machinepublishers.jbrowserdriver.JBrowserDriverServer.setUp(JBrowserDriverServer.java:162)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.security.Credentials
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 32 more

1 个答案:

答案 0 :(得分:0)

错误确实给出了一些线索如下:

NewID

分析:

  • 首先,我怀疑出现了问题:

    org.openqa.selenium.WebDriverException: org/openqa/selenium/security/Credentials
    
  • 作为第三方jar的
  • JBrowserDriver driver = new JBrowserDriver(Settings.builder().timezone(Timezone.AMERICA_DENVER).build()); 应该配置为:

    JBrowserDriver
  • 接下来,您会看到 orClassDefFoundError ,因为 org / openqa / selenium / security / Credentials 未解析运行时。

    WebDriver driver = new JBrowserDriver(Settings.builder().timezone(Timezone.AMERICA_DENVER).build());
    
  • 此问题与质量检查How can I resolve my class from a different jar with same structure like another

  • 非常相似

理由:

您看到 Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/security/Credentials 的原因可能有多种可能性,如下所示:

  • 初步原因似乎是NoClassDefFoundError。正如您所提到的那样,您将 import com.machinepublishers.jbrowserdriver.JBrowserDriver; 相关jar添加为外部依赖项。确保您正确定义范围的jar的正确版本,并在打包应用程序时将其捆绑在一起。

    class was not found in the classpath
  • 您可以在质量检查Exception in thread “main” java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

  • 中找到有关 NoClassDefFoundError 的详细讨论
  • 最后,根据 WebDriver 的范围, pom.xml 包含多个引用,如下所示:

    1

    <!-- https://mvnrepository.com/artifact/com.machinepublishers/jbrowserdriver -->
    <dependency>
        <groupId>com.machinepublishers</groupId>
        <artifactId>jbrowserdriver</artifactId>
        <version>0.17.11</version>
    </dependency>
    

    2

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.8.1</version>
    </dependency>
    

    3

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>3.8.1</version>
    </dependency>
    

    4

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>3.8.1</version>
    </dependency>
    

解决方案:

可能的解决方案是:

  • 确保<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>3.8.1</version> </dependency> correct version jar scope已正确定义bundled package {{1}}当您{{1}}申请时。{/ li} >
  • 根据Selenium Maven Information删除其他(未使用的)依赖项。