org.openqa.selenium.WebDriverException:浏览器无法启动,在fluentlium中测试

时间:2018-11-11 09:04:23

标签: java selenium htmlunit-driver

我想在fluentlium中运行简单的示例,但在驱动程序中却出现异常

我的代码:

Config.java

public  class Config extends ConfigurationDefaults {
    @Override
 public String getWebDriver() {
   System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
   WebDriver driver = new ChromeDriver();
   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   return "chrome";
 }
}

AbstractBaseTest.java

@FluentConfiguration(configurationDefaults =fluentleniumTutorial.Config.class)
public class AbstractBaseTest extends FluentTest {}

TestExample.java

public class TestExample extends AbstractBaseTest{
     @Test
        public void testGoogle() {
           goTo("http://www.google.com");
        }
}

我的例外:

> org.openqa.selenium.WebDriverException: Browser failed to start, test [ testGoogle(fluentleniumTutorial.TestExample) ] execution interrupted.
Caused by: [ com.gargoylesoftware.htmlunit.WebWindowListener]
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'DEV09', ip: '10.167.166.143', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: unknown
    at org.fluentlenium.adapter.FluentTestRunnerAdapter.starting(FluentTestRunnerAdapter.java:116)
    at org.fluentlenium.adapter.junit.FluentTest.access$000(FluentTest.java:15)
    at org.fluentlenium.adapter.junit.FluentTest$1.starting(FluentTest.java:25)
    at org.fluentlenium.adapter.junit.FluentTestRule$1.evaluate(FluentTestRule.java:43)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.fluentlenium.adapter.junit.FluentTest$2$1.evaluate(FluentTest.java:55)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.fluentlenium.adapter.FluentTestRunnerAdapter.getSharedWebDriver(FluentTestRunnerAdapter.java:181)
    at org.fluentlenium.adapter.FluentTestRunnerAdapter.getSharedWebDriver(FluentTestRunnerAdapter.java:142)
    at org.fluentlenium.adapter.FluentTestRunnerAdapter.starting(FluentTestRunnerAdapter.java:109)
    ... 21 more
Caused by: java.lang.ExceptionInInitializerError
    at org.fluentlenium.adapter.FluentAdapter.newWebDriver(FluentAdapter.java:146)
    at org.fluentlenium.adapter.SharedWebDriverContainer$Impl.createDriver(SharedWebDriverContainer.java:92)
    at org.fluentlenium.adapter.SharedWebDriverContainer$Impl.getOrCreateDriver(SharedWebDriverContainer.java:83)
    at org.fluentlenium.adapter.SharedWebDriverContainer.getOrCreateDriver(SharedWebDriverContainer.java:28)
    at org.fluentlenium.adapter.FluentTestRunnerAdapter.lambda$getSharedWebDriver$0(FluentTestRunnerAdapter.java:172)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.fluentlenium.configuration.ConfigurationException: class org.fluentlenium.configuration.DefaultWebDriverFactories$HtmlUnitWebDriverFactory can't be instantiated.
    at org.fluentlenium.configuration.AbstractFactoryRegistryImpl.<init>(AbstractFactoryRegistryImpl.java:57)
    at org.fluentlenium.configuration.WebDriversRegistryImpl.<init>(WebDriversRegistryImpl.java:16)
    at org.fluentlenium.configuration.WebDrivers.<init>(WebDrivers.java:17)
    at org.fluentlenium.configuration.WebDrivers.<clinit>(WebDrivers.java:15)
    ... 9 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.fluentlenium.configuration.AbstractFactoryRegistryImpl.<init>(AbstractFactoryRegistryImpl.java:53)
    ... 12 more
Caused by: java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebWindowListener
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.fluentlenium.configuration.ReflectiveWebDriverFactory.<init>(ReflectiveWebDriverFactory.java:35)
    at org.fluentlenium.configuration.DefaultWebDriverFactories$HtmlUnitWebDriverFactory.<init>(DefaultWebDriverFactories.java:113)
    ... 17 more
Caused by: java.lang.ClassNotFoundException: com.gargoylesoftware.htmlunit.WebWindowListener
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 21 more

1 个答案:

答案 0 :(得分:0)

看到底行异常,ClassNotFoundException:com.gargoylesoftware.htmlunit.WebWindowListener

这是HtmlUnit类的一部分,您需要下载这些类并将其添加到项目类路径(lib文件夹)中

请参见Selenium-WebDriver’s Drivers

  

HtmlUnit驱动程序   这是当前WebDriver最快,最轻量的实现。顾名思义,这是基于HtmlUnit的。 HtmlUnit是不带GUI的WebBrowser的基于Java的实现。对于任何语言绑定(非Java),Selenium Server都必须使用此驱动程序。