简体   繁体   English

如何对在 docker 中无头运行的 selenium 测试进行视频录制?

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

I am running python-selenium tests inside a docker using a headless firefox.我正在使用无头 Firefox 在 docker 中运行 python-selenium 测试。

During these tests I am able to make screenshots with the selenium method for screenshots - but can I use something to 'video' record the virtual display during the whole test (several test scripts with several test methods, with many webdrivers started and stopped).在这些测试中,我可以使用 selenium 方法制作屏幕截图 - 但是我可以在整个测试过程中使用一些东西来“视频”记录虚拟显示(几个测试脚本,几个测试方法,许多网络驱动程序启动和停止)。

So how can I video-record a complete test session?那么我怎样才能对完整的测试会话进行视频录制呢?

Addendum : I have found a webpage that describes exactly what I need: here .附录:我找到了一个准确描述我需要的网页: here Unfortunately I get an error when I try to do the recording.不幸的是,当我尝试进行录制时出现错误。 Here are the commands I am doing:这是我正在执行的命令:

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

and the error is (for the second command):错误是(对于第二个命令):

[x11grab @ 0x1d289c0] Cannot open display 127.0.0.1:44, error 1.
127.0.0.1:44: Input/output error

The correct steps to record the virtual display with ffmpeg are:ffmpeg记录虚拟显示的正确步骤是:

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

As thearticle provides, there are couple things to try:正如文章所提供的,有几件事可以尝试:

You can fix the “cannot open display” error by following the xhost procedure:您可以按照 xhost 程序修复“无法打开显示”错误:

  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+ 从任何主机连接 执行以下命令禁用访问控制,您可以允许客户端从任何主机连接。

     $ 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.启用 X11 转发 在执行 ssh 时使用选项 -X 来启用 X11 转发。

     $ ssh username@hostname -X

    Enable trusted X11 forwarding, by using the -Y option,启用受信任的 X11 转发,通过使用 -Y 选项,

     $ 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.在该主机中打开 GUI 应用程序在如上所述打开与远程主机的 ssh 连接后,您可以打开任何 GUI 应用程序,它可以毫无问题地打开它。

    If you still get the “cannot open display” error, set the DISPLAY variable as shown below.如果仍然出现“无法打开显示器”错误,请按如下所示设置 DISPLAY 变量。

     $ export DISPLAY='IP:0.0'

    Note: IP is the local workstation's IP where you want the GUI application to be displayed.注意: IP 是您希望在其中显示 GUI 应用程序的本地工作站的 IP。

EDIT:编辑:

hostname:n.m

Where hostname is the network hostname, qualified with domain name as needed (or use the IP address directly);其中hostname为网络主机名,根据需要加上域名(或直接使用IP地址); n is the display number on that host (usually 0); n 是该主机上的显示编号(通常为 0); and m is the screen number on that host (usually 0). m 是该主机上的屏幕编号(通常为 0)。

So try to replace 127.0.0.1:44 with 127.0.0.1:nm .因此,尝试更换127.0.0.1:44127.0.0.1:nm 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 ...如果您有多个显示器,请尝试通过传递127.0.0.1:0.0127.0.0.1:0.1127.0.0.1:1.0 ...

Also check if display dimensions is really 1920x1080 .还要检查显示尺寸是否真的是1920x1080

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM