How to video-record selenium tests running headless inside a docker? How to video-record selenium tests running headless inside a docker? python python

How to video-record selenium tests running headless inside a docker?


The correct steps to record the virtual display with ffmpeg are:

xvfb-run --listen-tcp --server-num 44 --auth-file /tmp/xvfb.auth -s "-ac -screen 0 1920x1080x24" python seltest.py &export DISPLAY=:44ffmpeg -f x11grab -video_size 1920x1080 -i :44 -codec:v libx264 -r 12 video.mp4


As the article provides, there are couple things to try:

You can fix the “cannot open display” error by following the xhost procedure:

  1. Allow clients to connect from any host using xhost+ Execute the following command to disable the access control, by which you can allow clients to connect from any host.

    $ xhost + access control disabled, clients can connect from any host
  2. Enable X11 forwarding While doing ssh use the option -X to enable X11 forwarding.

    $ ssh username@hostname -X 

    Enable trusted X11 forwarding, by using the -Y option,

    $ ssh username@hostname -Y
  3. Open GUI applications in that host After opening ssh connection to the remote host as explained above, you can open any GUI application which will open it without any issue.

    If you still get the “cannot open display” error, set the DISPLAY variable as shown below.

    $ export DISPLAY='IP:0.0' 

    Note: IP is the local workstation’s IP where you want the GUI application to be displayed.

EDIT:

hostname:n.m

Where hostname is the network hostname, qualified with domain name as needed (or use the IP address directly); n is the display number on that host (usually 0); and m is the screen number on that host (usually 0).

So try to replace 127.0.0.1:44 with 127.0.0.1:n.m. If you have multiple displays try to find out which one will work by passing 127.0.0.1:0.0, 127.0.0.1:0.1, 127.0.0.1:1.0 ...

Also check if display dimensions is really 1920x1080.