我在使用Protractor在Docker中使用Chrome时遇到了一些麻烦,这是我的protractor.conf.js文件:
'use strict';
const seleniumHost = process.env.CDT_SELENIUM_HOST || 'localhost';
const cdtServerHost = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
const cdtServerPort = process.env.OPENSHIFT_NODEJS_PORT || 3040;
const jasmineReporters = require('jasmine-reporters');
const util = require('util');
///////////////////////////////////////////////////////////////////////////////
exports.config = {
params: {
env: process.env.CDT_PROTRACTOR_ENV || 'local'
},
noColors: process.env.PROTRACTOR_NO_COLORS === 'yes',
chromeDriver: '/usr/bin/google-chrome',
onPrepare: function () {
global.projectRoot = String(__dirname);
let env = jasmine.getEnv();
env.clearReporters();
env.addReporter(new jasmineReporters.TapReporter());
},
jasmineNodeOpts: {
noColors: true,
showColors: false, // process.env.PROTRACTOR_NO_COLORS !== 'yes',
defaultTimeoutInterval: 15000,
},
seleniumAddress: `http://${seleniumHost}:4444/wd/hub`,
multiCapabilities: [
{
browserName: 'firefox',
firefoxOptions: {
args: ['-headless']
}
},
{
browserName: 'chrome',
chromeOptions: {
binary: '/usr/bin/google-chrome',
args: ['--headless']
}
}
],
specs: [
'./test/e2e/**/*spec.js',
]
};
我感到困惑的是为什么Firefox会在我们的Docker容器中工作,显然没有设置工作但Chrome不会。我不知道为什么我们需要Chrome驱动程序与Selenium-running-Chrome交谈而不需要Firefox驱动程序与Selenium-running-Firefox交谈。
在Jenkins上使用Docker运行测试时,错误如下:
[20:14:35] I/launcher - Running 2 instances of WebDriver
[20:14:36] I/testLogger -
------------------------------------
[20:14:36] I/testLogger - [chrome #11] PID: 15
[chrome #11] Specs: /usr/local/cdt-tests/test/e2e/by-roles/itso/home-page/home-page-spec.js
[chrome #11]
[chrome #11] (node:15) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[chrome #11] selenium host: cdt-selenium.cdt-net
[chrome #11] cdt server host: cdt-server.cdt-net
[chrome #11] cdt server port: 3040
[chrome #11] [20:14:35] I/hosted - Using the selenium server at http://cdt-selenium.cdt-net:4444/wd/hub
[chrome #11]
[chrome #11] /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:546
[chrome #11] throw new ctor(message);
[chrome #11] ^
[chrome #11] WebDriverError: 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
[chrome #11] at Object.checkLegacyResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:546:15)
[chrome #11] at parseHttpResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
[chrome #11] at doSend.then.response (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:441:30)
[chrome #11] at <anonymous>
[chrome #11] at process._tickCallback (internal/process/next_tick.js:188:7)
[chrome #11] From: Task: WebDriver.createSession()
[chrome #11] at Function.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
[chrome #11] at Function.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/chrome.js:761:15)
[chrome #11] at createDriver (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/index.js:170:33)
[chrome #11] at Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/index.js:626:16)
[chrome #11] at Hosted.getNewDriver (/usr/local/lib/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
[chrome #11] at Runner.createBrowser (/usr/local/lib/node_modules/protractor/built/runner.js:195:43)
[chrome #11] at q.then.then (/usr/local/lib/node_modules/protractor/built/runner.js:339:29)
[chrome #11] at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:834:54)
[chrome #11] at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:863:30)
[chrome #11] at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:796:13)
[20:14:36] I/testLogger -
[20:14:36] E/launcher - Runner process exited unexpectedly with error code: 1
[20:14:36] I/launcher - 1 instance(s) of WebDriver still running
.[20:15:00] I/testLogger -
------------------------------------
[20:15:00] I/testLogger - [firefox #01] PID: 14
[firefox #01] Specs: /usr/local/cdt-tests/test/e2e/by-roles/itso/home-page/home-page-spec.js
[firefox #01]
[firefox #01] (node:14) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[firefox #01] selenium host: cdt-selenium.cdt-net
[firefox #01] cdt server host: cdt-server.cdt-net
[firefox #01] cdt server port: 3040
[firefox #01] [20:14:35] I/hosted - Using the selenium server at http://cdt-selenium.cdt-net:4444/wd/hub
[firefox #01] Started
[firefox #01] .
[firefox #01]
[firefox #01]
[firefox #01] 1 spec, 0 failures
[firefox #01] Finished in 21.585 seconds
[firefox #01]
正如您所看到的,Firefox已经通过,但Chrome因此错误而失败:
[chrome #11] throw new ctor(message);
[chrome #11] ^
[chrome #11] WebDriverError: 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
答案 0 :(得分:0)
好的,我认为这是因为我使用的Selenium Docker图像是这样的:
FROM selenium/standalone-firefox:3.4.0-chromium
USER root
ENV NODE_ENV test
RUN mkdir -p /usr/local/cdt-tests/csv-data
COPY ./csv-data /usr/local/cdt-tests/csv-data
USER seluser
也许我需要使用一个使用Google Chrome而不是Firefox?
FROM selenium/standalone-chrome
或是
FROM selenium/standalone-firefox:3.4.0-chromium
旨在包含Firefox和Chrome驱动程序?