Docker Community Forums

Share and learn in the Docker community.

Opening chrome using docker to run selenium automation test


(Lamgadekamal) #1

while running selenium tests locally, it automatically opens up the chrome browser to performs tasks. However, while running the same command from docker does not and the tests fails with below error.

Unknown error: cannnot focus element

Error: An unknown server-side error occurred while processing the command.

kam-MBP: kl$ docker build -t dockerfinal .
    Sending build context to Docker daemon  787.3MB
    Step 1/3 : FROM dockerinit
     ---> 4d6fdb65d879
    Step 2/3 : USER root

---> Using cache
 ---> 5fab69855211

Step 3/3 : RUN ./node_modules/.bin/wdio
 ---> Running in f55f142eabf3
------------------------------------------------------------------

[chrome #0-0] Session ID: 819c77057d6a7e274c8fbfd36858e3d9
[chrome #0-0] Spec: /tinderbox2_frontend/e2e/accproset.test.js
[chrome #0-0] Running: chrome

[chrome #0-0]
[chrome #0-0] accountprojectsetting
[chrome #0-0]   1) "before each" hook for "should be able to do setting in account and project"
[chrome #0-0]
[chrome #0-0]
[chrome #0-0] **1 failing (30s)**

[chrome #0-0]
[chrome #0-0] 1) accountprojectsetting "before each" hook for "should be able to do setting in account and project":
[chrome #0-0] **unknown error: cannot focus element**
[chrome #0-0] Error: An unknown server-side error occurred while processing the command.
[chrome #0-0]     at elementIdValue("0.17283645604924724-1", "testG1BDCgRtwowtEBp@moxion.rocks") - setValue.js:46:80

(Sam) #2

u are trying to do this during image build. not container run time

also, the containers are headless… they have no UI… so, how would chrome work?


(Lamgadekamal) #3

i removed the headless parameter now and placed ENTRYPOINT ./node_modules/.bin/wdio , which helped to build the docker file . Then, I ran the docker image but not able to open a browser.

it’s returning -> Unknown Error: chrome couldn’t open: exited unexpectedly.


(Sam) #4

good, but… there is no UI in the container, it is a server process.
so chrome can’t run there.

some have tty’d into the running container, set the xterm variables and then started chrome remotely, but I have never done that…


(Think) #5

can have a look at xvfb-run to start graphical programs without “X”.


(Vince Bowdren) #6

There are official Selenium containers to make webdriver testing easier. For example you can get a container which includes the standalone selenium server, and a headless Chrome, and point your wdio config towards that:
https://hub.docker.com/r/selenium/standalone-chrome/