Jenkins上的XVFB连接到错误的显示显示屏显示黑屏

问题描述

我正在尝试在UBUNTU AWS / VM上使用XVFB通过Jenkins执行无头铬Selenium测试。

我的Jenkins XVFB配置为:

enter image description here

预构建Execute Shell:

export disPLAY=:98
x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :98 -auth /var/run/lightdm/root/:0 -rfbport 5900

开始构建时,我看到:

Xvfb starting$ /usr/bin/Xvfb :98 -screen 0 1024x768x24 -fbdir /var/lib/jenkins/xvfb-82-..fbdir10942188934689457655
[Jenkins-Headless] $ /bin/sh -xe /tmp/jenkins11502774511620101086.sh
+ export disPLAY=:98
+ x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :98 -auth /var/run/lightdm/root/:0 -rfbport 5900
17/09/2020 09:50:33 passing arg to libvncserver: -rfbport
17/09/2020 09:50:33 passing arg to libvncserver: 5900
.
.
.

最后:

17/09/2020 09:50:34 x11vnc version: 0.9.13 lastmod: 2011-08-10  pid: 11460
17/09/2020 09:50:34 Using X display :98
17/09/2020 09:50:34 rootwin: 0x298 reswin: 0x200001 dpy: 0x1a57e8f0
.
.
The VNC desktop is:      jenkins-it02:0
PORT=5900

现在通过我的MAC上的终端,我正在使用ssh -L 5900:localhost:5900 [email protected]命令连接到VM。

并使用VNCViewer,我连接到localhost:5900。它已连接,但我只看到黑屏。我希望屏幕上出现Chrome浏览器窗口。

enter image description here

enter image description here

如何解决此问题并在vncviewer上观看Chrome窗口?

解决方法

我自己找到了解决方案。对于遇到相同问题的任何人:

我做错了是我在代码中使用driver = new ChromeDriver(options);而不是driver = new RemoteWebDriver(new URL("http://my.aws.ip:4444/wd/hub"),options);

进行此更改后,我在ec2中将selenium-server-standalone.jar下载到了。

然后,在开始测试之前,我对ec2进行ssh -X [email protected]并执行:

Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:99
java -jar /home/qa_user/Selenium/selenium-server-standalone.jar

现在,执行测试,同时打开一个新终端并执行以下操作:

ssh -L 5900:localhost:5900 [email protected]

设置好屏幕后,我就会这样做:

x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :99 -auth /var/run/lightdm/root/:0  -rfbport 5900

接下来,打开VNC查看器,连接到localhost:5900,您将看到Chrome执行。

稍后,如果需要,您可以将所有这些内容移至Jenkins预制执行外壳程序中:)