Maven无法连接到远程独立Selenium服务器

时间:2016-06-16 15:35:26

标签: java maven google-chrome selenium

我正在为工作中的项目创建测试套件,我们将从中央盒(所有vms)在多个操作系统上测试我们的应用程序。测试框是一个使用apache-maven进行测试的CentOS服务器。我试图测试运行selenium-standalone-server的Windows 10机箱但到目前为止没有运气。以下是每个框的配置:

CentOS的

  • Apache Maven
  • IP地址 - 192.168.4.62
  • 子网掩码 - 255.255.255.0

样本测试

package com.netsweeper.browsertests;

import static org.junit.Assert.assertEquals;
import java.net.URL;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.safari.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ReadyTest {
    @Test
    public void accessChrome() {
       try {
            WebDriver driver = new RemoteWebDriver(new URL("http://192.168.4.60:4444/wd/hub"), DesiredCapabilities.chrome());
            driver.get("http://google.com");
            assertEquals("The page title should equal Google at the start of the test", "Google", driver.getTitle());
            driver.close();
            driver.quit();
        }
        catch ( java.net.MalformedURLException e) {
            System.out.println("Broken");
        }
    }
}

测试输出

[root@62 browser_tests]# mvn -Dtest=ReadyTest test

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Browser Tests 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ browsertests ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /src/client_filter/browser_tests/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ browsertests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ browsertests ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /src/client_filter/browser_tests/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ browsertests ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ browsertests ---
[INFO] Surefire report directory: /src/client_filter/browser_tests/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.netsweeper.browsertests.ReadyTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.392 sec <<< FAILURE!
accessChrome(com.netsweeper.browsertests.ReadyTest)  Time elapsed: 1.325 sec  <<< ERROR!
org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Command duration or timeout: 732 milliseconds
Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44'
System info: host: '62.4.168.192.in-addr.arpa.support', ip: '192.168.4.62', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-642.1.1.el6.x86_64', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
        at com.netsweeper.browsertests.ReadyTest.accessChrome(ReadyTest.java:20)
        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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        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.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        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 org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
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 https://github.com/SeleniumHQ/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:199)
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
        at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:138)
        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.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


Results :

Tests in error:
  accessChrome(com.netsweeper.browsertests.ReadyTest): The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html(..)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.391 s
[INFO] Finished at: 2016-06-16T11:17:21-04:00
[INFO] Final Memory: 16M/168M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project browsertests: There are test failures.
[ERROR]
[ERROR] Please refer to /src/client_filter/browser_tests/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

[root@62 browser_tests]# 

Windows 10

  • Selenium独立服务器
    • 置于C:\Users\------\Documents\client_filter\selenium-server-standalone-2.53.0
    • 从所述目录开始java -jar selenium-server-standalone-2.53.0
    • 正确开始运行
  • Chrome驱动程序
    • 已下载并置于C:\Windows\System32
    • 从命令行启动它可以正常工作,因此它在$ PATH
    • C:\Users\Kendall Roth\Documents\client_filter> chromedriver.exe
  • IP地址 - 192.168.4.60
  • 网络掩码 - 255.255.255.0

然而,上面的错误似乎表明chromedriver不在正确的位置,即使它可以从任何地方找到(由于在路径中)。该错误也显示在Windows控制台中,并说同样的事情。

我环顾四周,但找不到任何与Selenium独立服务器远程安装有关的内容。遗憾的是,这个链接不起作用,但与我的问题相似(虽然在当地范围内): selenium-2-chrome-driver

2 个答案:

答案 0 :(得分:0)

事实证明,这是一个相当简单的修复。虽然C:\Windows\不在系统路径中,但这是chromedriver.exe应该去的地方。将其置于此处而不是C:\Windows\System32\中似乎可以解决问题。我不确定这只是一个远程服务器,还是它扩展到本地独立实例,但这个解决方案对我们有用。

答案 1 :(得分:0)

我发现在项目的资源文件夹中包含chromedriver.exe是可行的故障保护,所以我不必依赖于具有可执行文件的新用户或远程服务器在他们的文件系统中的正确位置。