Java Selenium video recording


The site has an animation block, which is animated using html5, css, and js. Is it possible to somehow record this animation in a gif? I use selenium and the getScreenshotAs method.

Initially, the idea was this: to make a bunch of screenshots, and then blind them into a gif file, but the problem is that using the getScreenshotAs method, the screenshot is made for a very long time(350-400ms), so there is no smoothness(it turns out 3-4 frames per second, or even less).

The question is, is it possible to solve this problem somehow, if not, then maybe there is some other way? Options with screen recording will not work, because it will all be done on the server, without the gui.

Author: Nofate, 2018-11-14

1 answers

You can draw Selenium on a virtual framebuffer Xvfb and record video, for example, via ffmpeg.

Start the Xvfb server, and in it the browser:

xvfb-run --listen-tcp --server-num=123 --auth-file /tmp/xvfb.auth -e /dev/stdout -s "-ac -screen 0 1024x768x24" firefox ru.stackoverflow.com 

123 - xserver display number of your choice
/tmp/xvfb.auth - the path where the authorization data will be saved
1024x768x24 - desired framebuffer geometry
firefox ru.stackoverflow.com - opens this site in Firefox; replace with your Selenium startup string

To start writing video:

ffmpeg -f x11grab -i :123 -video_size 1024x768 -codec:v libx264 -r 12 video.mp4

-f x11grab -i :123 - video stream source: xserver, 123rd display
-video_size 1024x768 - video file resolution
libx264 - desired video codec
-r 12 - frame rate

For a gif file, you do not need to specify the codec:

ffmpeg -f x11grab -video_size 1024x768 -i :123 -r 12 1.gif

To take a screenshot (requires an installed ImageMagick):

xwd -display :123 -root | convert xwd:/dev/stdin png:1.png

-display :123 - still the same 123rd display
-root - does not relate to the root user; indicates that a screenshot of the entire desktop is needed, not specific window

 4
Author: Nofate, 2018-11-15 14:27:48