wallnfl
wallnfl

Reputation: 11

Selenium WebDriver - Process unexpectedly closed

I have built a Docker image on top of Node to execute a bunch of Selenium tests. Here is my 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","[email protected]"]

#launch the test suite
CMD ["node","/tests/suite.js"]
#CMD ["tail","-f","/dev/null"]

The code fails by executing the following initilization (the test cases in suite.js call the method init before doing anything):

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;
  }

However, the code above runs fine with my local node installation. But when i run the built docker image, it produces the following:

WebDriverError: Process unexpectedly closed with status: 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 at process._tickCallback (internal/process/next_tick.js:160:7) From: Task: WebDriver.createSession() at Function.createSession (/node_modules/selenium-webdriver/lib/webdriver.js:769:24) at Function.createSession (/node_modules/selenium-webdriver/firefox/index.js:521:41) at createDriver (/node_modules/selenium-webdriver/index.js:170:33) at Builder.build (/node_modules/selenium-webdriver/index.js:645:16) at Object.init (/tests/upik_lib.js:28:10) at Object. (/tests/upik_suite.js:1:97) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:573:32)

I really dont have an idea of what went wrong here. I would expect to execute node to launch my selenium tests. I included Geckodriver and a firefox binary. Any ideas?

Upvotes: 1

Views: 1364

Answers (1)

Matteo Pasini
Matteo Pasini

Reputation: 2022

I've had the same problem these days, apparently it's due to the firefox executables being downloaded directly from the link inside a docker container, which doesn't have a set of libraries firefox needs to work. To solve the problem I therefore had to add the following line to the Dockerfile.

RUN apt-get update && apt-get install -y wget bzip2 libxtst6 packagekit-gtk3-module libx11-xcb-dev libdbus-glib-1-2 libxt6 libpci-dev && rm -rf /var/lib/apt/lists/*

To test which libraries were missing, I connected to the docker container and try to run firefox in the following way:

firefox -headless

Upvotes: 0

Related Questions