Selenium 第一次在容器上运行量角器时失败,并出现错误

Selenium 第一次在容器上运行量角器时失败,并出现错误,selenium,docker,selenium-webdriver,protractor,webdriver-manager,Selenium,Docker,Selenium Webdriver,Protractor,Webdriver Manager,我正在运行一个量角器示例应用程序,但它在容器上失败。 我在一台物理机器上尝试了相同的应用程序,它按预期工作,并通过了测试用例 我的测试代码:-->CheckTitleSpec.js //CheckTitleSpec.js2 describe('Protractor Demo', function() { it('to check the page title', function() { browser.ignoreSynchronization = true; browser.get('htt

我正在运行一个量角器示例应用程序,但它在容器上失败。 我在一台物理机器上尝试了相同的应用程序,它按预期工作,并通过了测试用例

我的测试代码:-->CheckTitleSpec.js

//CheckTitleSpec.js2
describe('Protractor Demo', function() {
it('to check the page title', function() {
browser.ignoreSynchronization = true;
browser.get('https://www.softwaretestinghelp.com/');
browser.driver.getTitle().then(function(pageTitle) {
expect(pageTitle).toEqual('Software Testing Help - Free Software        Testing & IT Tutorials and Courses');
});
});
});
conf.js文件

// conf.js
exports.config = {
    framework: 'jasmine',
    capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ["--headless", "--disable-gpu", "--window-size=800x600"]
    }
    },
    specs: ['CheckTitleSpec.js']
    };
用于构建容器的Docker文件:

FROM node:latest
USER root
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install software-properties-common
RUN apt-get install default-jre -y
RUN npm install -g protractor
RUN webdriver-manager update
RUN npm install protractor-jasmine2-screenshot-reporter
# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-  stable_current_amd64.deb
RUN apt install ./google-chrome-stable_current_amd64.deb -y
COPY CheckTitleSpec.js /
COPY conf.js /
ENTRYPOINT [ "sh", "-c", "protractor /conf.js" ]
在容器上,输出为:

java -version
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b12, mixed mode)

webdriver-manager version
I/version - webdriver-manager 12.1.4

node -v
v11.12.0

npm -v
6.7.0

protractor --version
Version 5.4.2

google-chrome --version
Google Chrome 74.0.3729.131

   protractor conf.js
[10:32:53] I/launcher - Running 1 instances of WebDriver
[10:32:53] I/local - Starting selenium standalone server...
[10:32:55] I/local - Selenium standalone server started at     http://172.17.0.2:49496/wd/hub
[10:32:56] E/launcher - unknown error: Chrome failed to start: exited    abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=74.0.3729.6   (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-  heads/3729@{#29}),platform=Linux 4.9.125-linuxkit x86_64) (WARNING: The   server did not provide any stacktrace information)
Command duration or timeout: 147 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: '153e772db9cd', ip: '172.17.0.2', os.name: 'Linux',  os.arch: 'amd64', os.version: '4.9.125-linuxkit', java.version:  '1.8.0_212'
Driver info: driver.version: unknown
[10:32:56] E/launcher - WebDriverError: unknown error: Chrome failed   to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is  no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=74.0.3729.6    (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch- heads/3729@{#29}),platform=Linux 4.9.125-linuxkit x86_64) (WARNING: The   server did not provide any stacktrace information)
Command duration or timeout: 147 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time:   '2018-11-14T08:25:53'
System info: host: '153e772db9cd', ip: '172.17.0.2', os.name: 'Linux',  os.arch: 'amd64', os.version: '4.9.125-linuxkit', java.version:  '1.8.0_212'
Driver info: driver.version: unknown
    at Object.checkLegacyResponse (/usr/local/lib/node_modules   /protractor/node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (/usr/local/lib/node_modules/protractor  /node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/usr/local/lib/node_modules/protractor /node_modules/selenium-webdriver/lib/http.js:441:30)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
From: Task: WebDriver.createSession()
    at Function.createSession (/usr/local/lib/node_modules /protractor/n  ode_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at Function.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/chrome.js:761:15)
    at createDriver (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/index.js:170:33)
    at Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/index.js:626:16)
    at Local.getNewDriver (/usr/local/lib/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
at Runner.createBrowser (/usr/local/lib/node_modules/protractor/built/runner.js:195:43)
at q.then.then (/usr/local/lib/node_modules/protractor/built/runner.js:339:29)
at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:834:54)
at /usr/local/lib/node_modules/protractor/node_modules/q/q.js:863:30
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules /protractor/node_modules/q/q.js:796:13)
[10:32:56] E/launcher - Process exited with error code 199
我在物理Linux box headless上测试了相同的代码,结果与预期的一样

非常感谢任何线索


谢谢。

我已经看到了几个类似于帖子中的答案。这些答案建议使用
--无沙盒
--禁用dev shm用法
标志作为解决方法

在配置中,添加如下标志:

capabilities: {
  browserName: 'chrome',
  chromeOptions: {
    args: [
      '--no-sandbox',
      '--disable-dev-shm-usage'
    ]
  }
}

在启动量角器之前,请尝试运行
export DISPLAY=:99
如果有帮助,请告诉我,我会给出完整答案。同样的错误。我试图设置显示,但仍然失败。当我还没有安装xvfb时,我看到了这个错误,但您仍然在headless中运行测试。。。试着按照本页的说明操作,现在效果很好。现在的挑战是将整个过程缝合到詹金斯管道中。感谢您提供的解决方案和链接。这很有帮助。:-)