GitLab CI上的Selenium Grid错误:转发新会话时出错用于设置功能的VM空池

时间:2022-03-12 17:08:57

Since documentation on GitLab CI configuration and Selenium is generally poor, I'm asking for help.

由于关于GitLab CI配置和Selenium的文档通常很差,我正在寻求帮助。

Configuration as by interest point:

按兴趣点配置:

gitlab.ci.yml:

gitlab.ci.yml:

image: node:7

variables:
  HUB_PORT_4444_TCP_ADDR: "selenium__hub"
  HUB_PORT_4444_TCP_PORT: "4444"

services:
  - selenium/hub:latest
  - selenium/node-phantomjs:latest

stages:
  - test

test:
  stage: test
  before_script:
    - apt-get update
    - apt-get install -y default-jdk default-jre
    - npm install -s -g @angular/cli@1.0.6
    - npm install -s
    - node ./node_modules/protractor/bin/webdriver-manager update
  script:
    - ./node_modules/.bin/protractor protractor.ci.conf.js

protractor.ci.conf.js:

protractor.ci.conf.js:

/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'phantomjs',
    'phantomjs.binary.path': './node_modules/phantomjs-prebuilt/bin/phantomjs'
  },
  directConnect: false,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  },
  seleniumAddress: 'http://selenium__hub:4444/wd/hub'
};

With the above configuration, GitLab fails with:

使用上面的配置,GitLab失败了:

$ ./node_modules/.bin/protractor protractor.ci.conf.js
(node:3702) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[09:53:27] I/launcher - Running 1 instances of WebDriver
[09:53:27] I/hosted - Using the selenium server at http://selenium__hub:4444/wd/hub
[09:53:28] E/launcher - Error forwarding the new session Empty pool of VM for setup Capabilities [{phantomjs.binary.path=./node_modules/phantomjs-prebuilt/bin/phantomjs, count=1, browserName=phantomjs}]
[09:53:28] E/launcher - WebDriverError: Error forwarding the new session Empty pool of VM for setup Capabilities [{phantomjs.binary.path=./node_modules/phantomjs-prebuilt/bin/phantomjs, count=1, browserName=phantomjs}]
    at Object.checkLegacyResponse (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/error.js:505:15)
    at parseHttpResponse (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/http.js:440:13)
    at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/builds/netaachen/operator-app/node_modules/selenium-webdriver/lib/webdriver.js:777:24)
    at createDriver (/builds/netaachen/operator-app/node_modules/selenium-webdriver/index.js:167:33)
    at Builder.build (/builds/netaachen/operator-app/node_modules/selenium-webdriver/index.js:632:14)
    at Hosted.getNewDriver (/builds/netaachen/operator-app/node_modules/protractor/lib/driverProviders/driverProvider.ts:60:29)
    at Runner.createBrowser (/builds/netaachen/operator-app/node_modules/protractor/lib/runner.ts:225:39)
    at q.then.then (/builds/netaachen/operator-app/node_modules/protractor/lib/runner.ts:391:27)
    at _fulfilled (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:796:13)
    at /builds/netaachen/operator-app/node_modules/protractor/node_modules/q/q.js:556:49
[09:53:28] E/launcher - Process exited with error code 199
ERROR: Build failed: exit code 1

2 个解决方案

#1


1  

I have neved used Gitlab CI but have Selenium experience. So let me first describe some important considerations:

我已经使用过Gitlab CI,但有Selenium经验。首先让我描述一些重要的考虑因素:

  1. An error you receive means that there's no requested browser in the hub. This is probably because PhantomJS did not manage to register.
  2. 您收到的错误表示集线器中没有请求的浏览器。这可能是因为PhantomJS无法注册。
  3. You don't need to install neither Java nor Selenium server to work with PhantomJS. It is a standalone binary implementing itself Selenium protocol. So in order to work with PhantomJS - just start container with PhantomJS. For example I would use this one: selenoid/phantomjs:2.1.1 (build file is here) - it just runs phantomjs --webdriver=4444. PhantomJS by default listens on port 8910 but because of command above we can still use 4444.
  4. 您既不需要安装Java也不需要安装Selenium服务器来使用PhantomJS。它是一个实现Selenium协议的独立二进制文件。因此,为了使用PhantomJS - 只需使用PhantomJS启动容器。例如,我会使用这个:selenoid / phantomjs:2.1.1(构建文件在这里) - 它只运行phantomjs --webdriver = 4444。 PhantomJS默认侦听端口8910,但由于上面的命令,我们仍然可以使用4444。
  5. I think you also don't need to use webdriver-manager which is a Javascript tool to download Selenium server or webdriver binaries. This is not needed to work with PhantomJS.
  6. 我想你也不需要使用webdriver-manager这是一个Javascript工具来下载Selenium服务器或webdriver二进制文件。使用PhantomJS不需要这样做。
  7. Not sure why environment variables like HUB_PORT_4444_TCP_ADDR were added. So I would remove them all.
  8. 不确定为什么添加了像HUB_PORT_4444_TCP_ADDR这样的环境变量。所以我会将它们全部删除。

Having said that let's try to modify your files.

说过,让我们尝试修改你的文件。

gitlab-ci.yml becomes:

gitlab-ci.yml变为:

image: node:7

services:
  - selenoid/phantomjs:2.1.1

stages:
  - test

test:
  stage: test
  before_script:
    - npm install -s -g @angular/cli@1.0.6
    - npm install -s
  script:
    - ./node_modules/.bin/protractor protractor.ci.conf.js

protractor.ci.conf.js becomes (only changed container name in seleniumAddress):

protractor.ci.conf.js变为(仅在seleniumAddress中更改容器名称):

/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'phantomjs',
    'phantomjs.binary.path': './node_modules/phantomjs-prebuilt/bin/phantomjs'
  },
  directConnect: false,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  },
  seleniumAddress: 'http://selenoid__phantomjs:4444/wd/hub'
};

Not sure what is baseUrl - seems to be some Protractor stuff, so I think don't need to change. Please ask more questions if any.

不确定什么是baseUrl - 似乎是一些Protractor的东西,所以我认为不需要改变。如果有的话,请提出更多问题。

#2


1  

The key is to use Xvfb on GitLab CI. That spins up the display so --headless Chrome can run the specs.

关键是在GitLab CI上使用Xvfb。这会使显示屏旋转,因此无头的Chrome可以运行规格。

I wrapped more info and chunks of code into the blog post of How to run AngularJS end-to-end tests on GitLab CI.

我将更多信息和大量代码包含在如何在GitLab CI上运行AngularJS端到端测试的博客文章中。

#1


1  

I have neved used Gitlab CI but have Selenium experience. So let me first describe some important considerations:

我已经使用过Gitlab CI,但有Selenium经验。首先让我描述一些重要的考虑因素:

  1. An error you receive means that there's no requested browser in the hub. This is probably because PhantomJS did not manage to register.
  2. 您收到的错误表示集线器中没有请求的浏览器。这可能是因为PhantomJS无法注册。
  3. You don't need to install neither Java nor Selenium server to work with PhantomJS. It is a standalone binary implementing itself Selenium protocol. So in order to work with PhantomJS - just start container with PhantomJS. For example I would use this one: selenoid/phantomjs:2.1.1 (build file is here) - it just runs phantomjs --webdriver=4444. PhantomJS by default listens on port 8910 but because of command above we can still use 4444.
  4. 您既不需要安装Java也不需要安装Selenium服务器来使用PhantomJS。它是一个实现Selenium协议的独立二进制文件。因此,为了使用PhantomJS - 只需使用PhantomJS启动容器。例如,我会使用这个:selenoid / phantomjs:2.1.1(构建文件在这里) - 它只运行phantomjs --webdriver = 4444。 PhantomJS默认侦听端口8910,但由于上面的命令,我们仍然可以使用4444。
  5. I think you also don't need to use webdriver-manager which is a Javascript tool to download Selenium server or webdriver binaries. This is not needed to work with PhantomJS.
  6. 我想你也不需要使用webdriver-manager这是一个Javascript工具来下载Selenium服务器或webdriver二进制文件。使用PhantomJS不需要这样做。
  7. Not sure why environment variables like HUB_PORT_4444_TCP_ADDR were added. So I would remove them all.
  8. 不确定为什么添加了像HUB_PORT_4444_TCP_ADDR这样的环境变量。所以我会将它们全部删除。

Having said that let's try to modify your files.

说过,让我们尝试修改你的文件。

gitlab-ci.yml becomes:

gitlab-ci.yml变为:

image: node:7

services:
  - selenoid/phantomjs:2.1.1

stages:
  - test

test:
  stage: test
  before_script:
    - npm install -s -g @angular/cli@1.0.6
    - npm install -s
  script:
    - ./node_modules/.bin/protractor protractor.ci.conf.js

protractor.ci.conf.js becomes (only changed container name in seleniumAddress):

protractor.ci.conf.js变为(仅在seleniumAddress中更改容器名称):

/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'phantomjs',
    'phantomjs.binary.path': './node_modules/phantomjs-prebuilt/bin/phantomjs'
  },
  directConnect: false,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  },
  seleniumAddress: 'http://selenoid__phantomjs:4444/wd/hub'
};

Not sure what is baseUrl - seems to be some Protractor stuff, so I think don't need to change. Please ask more questions if any.

不确定什么是baseUrl - 似乎是一些Protractor的东西,所以我认为不需要改变。如果有的话,请提出更多问题。

#2


1  

The key is to use Xvfb on GitLab CI. That spins up the display so --headless Chrome can run the specs.

关键是在GitLab CI上使用Xvfb。这会使显示屏旋转,因此无头的Chrome可以运行规格。

I wrapped more info and chunks of code into the blog post of How to run AngularJS end-to-end tests on GitLab CI.

我将更多信息和大量代码包含在如何在GitLab CI上运行AngularJS端到端测试的博客文章中。