我在Node上构建了一个Docker镜像来执行一系列Selenium测试。 这是我的Dockerfile:
#Dockerfile for individual node instance
FROM node:latest
#add the .js Selenium testcase files
COPY ./tests /tests
#add geckodriver (latest version) from local directory
COPY geckodriver-v0.19.1-linux64.tar.gz /
#set Path variable to firefox binary
ENV Path="/firefox/firefox-bin"
RUN ["mkdir","/firefox"]
#download firefox executables
RUN ["wget","-O","/firefox/ff.tar.bz2","https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=de"]
#unpack firefox executables
RUN ["tar","xjf", "/firefox/ff.tar.bz2"]
#unpack geckodriver
RUN ["tar", "xzf", "geckodriver-v0.19.1-linux64.tar.gz"]
#install webdriver on node
RUN ["npm","install","selenium-webdriver@3.6.0"]
#launch the test suite
CMD ["node","/tests/suite.js"]
#CMD ["tail","-f","/dev/null"]

代码因执行以下启动而失败(suite.js中的测试用例在执行任何操作之前调用方法init):
let obj = {
driver: null,
By: null,
init: function() {
let webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
let firefox = require('selenium-webdriver/firefox');
//choose binary which was copied to the docker image
let binary = new firefox.Binary('/firefox/firefox-bin');
//run in headless mode
binary.addArguments("-headless");
let profile = new firefox.Profile();
//add proxy
profile.setPreference('network.proxy.type', 1);
profile.setPreference('network.proxy.http', 'localhost');
profile.setPreference('network.proxy.http_port', 8090);
profile.setPreference('network.proxy.no_proxies_on', '');
let options = new firefox.Options().setProfile(profile);
options.setLogLevel(FirefoxDriverLogLevel.TRACE)
options.setBinary(binary);
obj.driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
obj.By = webdriver.By;
return obj;
}

但是,上面的代码在本地节点安装时运行良好。但是当我运行构建的docker镜像时,它会生成以下内容:
WebDriverError:进程意外关闭状态:255 at Object.throwDecodedError(/node_modules/selenium-webdriver/lib/error.js:514:15) at parseHttpResponse(/node_modules/selenium-webdriver/lib/http.js:519:13) at doSend.then.response(/node_modules/selenium-webdriver/lib/http.js:441:30) 在 at process._tickCallback(internal / process / next_tick.js:160:7) 来自:任务:WebDriver.createSession() 在Function.createSession(/node_modules/selenium-webdriver/lib/webdriver.js:769:24) 在Function.createSession(/node_modules/selenium-webdriver/firefox/index.js:521:41) 在createDriver(/node_modules/selenium-webdriver/index.js:170:33) 在Builder.build(/node_modules/selenium-webdriver/index.js:645:16) at Object.init(/tests/upik_lib.js:28:10) 在对象。 (/tests/upik_suite.js:1:97) 在Module._compile(module.js:660:30) at Object.Module._extensions..js(module.js:671:10) 在Module.load(module.js:573:32)
我真的不知道这里出了什么问题。我希望执行节点来启动我的selenium测试。我包括了Geckodriver和一个firefox二进制文件。 有什么想法吗?