Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Openshift-gitlab cli-phantomjs-WebDriverException:等待驱动程序服务器启动时超时_Selenium_Phantomjs_Gitlab Ci - Fatal编程技术网

Selenium Openshift-gitlab cli-phantomjs-WebDriverException:等待驱动程序服务器启动时超时

Selenium Openshift-gitlab cli-phantomjs-WebDriverException:等待驱动程序服务器启动时超时,selenium,phantomjs,gitlab-ci,Selenium,Phantomjs,Gitlab Ci,我有一个带有验收测试(即一致性测试)的Java项目设置。 在本地使用chrome和phantomjs驱动程序(在windows上),测试正在通过(即由gradle运行) 在gitlab ci上运行时(openshift中有一个运行程序),我会遇到以下异常: java.lang.ExceptionInInitializerError at be.axians.actemium.milter.helper.BrowserTestParent.openBrowser(BrowserTest

我有一个带有验收测试(即一致性测试)的Java项目设置。 在本地使用chrome和phantomjs驱动程序(在windows上),测试正在通过(即由gradle运行)

在gitlab ci上运行时(openshift中有一个运行程序),我会遇到以下异常:

  java.lang.ExceptionInInitializerError
    at be.axians.actemium.milter.helper.BrowserTestParent.openBrowser(BrowserTestParent.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    ...

    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'runner-5408090a-project-349-concurrent-0dtvl2', ip: '10.131.1.51', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-514.26.1.el7.x86_64', java.version: '1.8.0_131'
Driver info: driver.version: PhantomJSDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
    at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:116)
    at be.axians.actemium.milter.helper.WebDriverManager.<clinit>(WebDriverManager.java:53)
    ... 52 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:7465/status] to be available after 20001 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:107)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:190)
    ... 60 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:140)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)
    ... 61 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:128)
    ... 62 more
对于给定的依赖项:

testCompile "com.codeborne:phantomjsdriver:1.4.3"
phantomjs-1.9.8
并使用以下gitlab ci配置:

acceptance-test:
  stage: acceptance-test
  services:
   - jboss/keycloak:3.3.0.CR1
   - postgres:latest
  variables:
    POSTGRES_DB: "..."
    POSTGRES_USER: "..."
    POSTGRES_PASSWORD: "..."
    KEYCLOAK_PASSWORD: "..."
    KEYCLOAK_USER: "..."
  script:
    - ls
    - cd acceptance-tests/driver
    - ls
    - tar xf phantomjs-1.9.8-linux-x86_64.tar.bz2
    - ls -al
    - mv phantomjs-1.9.8-linux-x86_64 phantomjs
    - ls
    - ls phantomjs
    #- ls -al phantomjs/bin
    #- ln -s phantomjs/bin/phantomjs /usr/bin/phantomjs
    - ls -al /actemium/milter/acceptance-tests/driver/phantomjs/bin/phantomjs
    - cd ../..
    - ls
    - pwd
    - ./gradlew -g .gradle_home acceptanceTest -Dspring.profiles.active=at --stacktrace
  artifacts:
    when: on_failure
    paths:
      - acceptance-tests/tests/build/reports/tests
    expire_in: 1 week

有人知道如何解决这个问题吗?

您可以通过Chrome浏览器使用headless执行所有操作。不要使用HTMLUnit,因为它有很多配置问题

PhantomJS是无头浏览器的另一种方法,但由于维护不善,PhantomJS最近出现了bug

您可以将chromedriver本身用于无头作业

您只需在chromedriver中传递一个选项,如下所示:-

chromeOptions.addArguments("--headless");
完整代码如下所示:-

System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.co.in/");
如果您仍然想使用phantomjs。 然后首先从以下URL下载phantomjs二进制文件:-

完整的代码如下所示:-

System.setProperty("phantomjs.binary.path","D:\\Workspace\\kumolus-test-automation\\src\\lib\\phantomjs\\phantomjs.exe");
DesiredCapabilities capabilities = null;
ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,
        new String[] { "--logLevel=2" });

WebDriver driver = new PhantomJSDriver();
driver.get("https://www.facebook.com/");
System.out.println(driver.getTitle());
System.setProperty(“phantomjs.binary.path”、“D:\\Workspace\\kumolus test automation\\src\\lib\\phantomjs\\phantomjs.exe”);
DesiredCapabilities=null;
ArrayList cliArgsCap=新的ArrayList();
capabilities=DesiredCapabilities.phantomjs();
cliArgsCap.add(“--websecurity=false”);
cliArgsCap.add(“--ssl协议=any”);
cliArgsCap.add(“--ignoressl errors=true”);
能力。设置能力(“takesScreenshot”,true);
setJavascriptEnabled(true);
能力。设置能力(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);
能力。设置能力(
PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_参数,
新字符串[]{--logLevel=2“});
WebDriver=newphantomjsdriver();
驱动程序。获取(“https://www.facebook.com/");
System.out.println(driver.getTitle());

更改上述代码第1行中Phantomjs位置路径的位置

我的Phantomjs解决方案安装了一个隐藏的依赖项:

yum install -y libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev

我试试看。我针对PhantomJS的解决方案是安装一个隐藏的依赖项:yum安装-y libfontconfig1 fontconfig libfontconfig1 dev libfreetype6-dev。但如果可能的话,首选headless chrome;)
yum install -y libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev