Robotframework selenium tests failed in docker image

Hello,
I use an Alpine docker image for automated robotframework testing with the Selenium library
Recently I started getting the error failed to decode response from marionette and also WebDriverException: Message: invalid argument: can’t kill an exited process.

After investigation, I updated the webdriver and the browser in the docker image and I also activated healless mode and the number of failures to decrease but now I have a new error: InvalidSessionIdException: Message: Tried to run command without establishing a connection
and in the logs I see the error:
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :99

What is the recommended value for the DISPAY variable ?

Hi Marta,

The recommended value for the DISPAY variable is the port your display server is running on. If you don’t have one you need to install and run one.

It’s not enough to simply set the display variable, there also needs to be a display server running on that port for the browser to connect to (even when running headless), as docker containers don’t usually have a graphics card the best way to deal with this is to use xvfb (you can search this forum for xvfb, there are plenty of threads discussing this)

Hope that helps,

Dave.

2 Likes

Thanks Dave for your quick response.

I’m not familar with docker, in my docker file i have command to install Xvfb, which is :

run apk add xorg-server xvfb

And also, i have : ENV DISPLAY=:0.0

Maybe i should add this line in my dockerfile : Xvfb :99 -ac -screen 0 1280x720x16 or in my gitlab-ci.yml

What do you think ?

Yes you should add this, this will make sure it is running, but also

The value for DISPLAY needs to match what you gave to Xvfb, so make them both :99, make them both :0, or make them both another number, any number you like as long as they are the same, I make them both :13 because 13 is my lucky number, the number you choose is not important, being the same number is.

Normally I’d suggest avoiding :0.0 only because that’s the default for an xserver connected to the internal graphics card, but in a docker container you shouldn’t have that issue.

Also if you’re testing web pages you might want to make the screen size a bit bigger as many modern web pages don’t fit well on that screen size and your browser scripts will have to do a lot of scrolling, also the x16 signifies 16 bit colour which may cause some colour issues in your screenshots so if becomes an issue for you increase it to x24 (24 bit colour is considered “true colour”, most people can’t see the difference between x24 and x32)

Dave.

1 Like