EC2上的XVFB和Selenium-无法在VNC Viewer上查看Chrome UI [英] XVFB and Selenium on EC2 - Unable to view Chrome UI on VNC Viewer

查看:80
本文介绍了EC2上的XVFB和Selenium-无法在VNC Viewer上查看Chrome UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Selenium无头测试是从Jenkins服务器触发的,并在EC2-Ubuntu中运行.我想在Chrome上实时查看测试,因此我在Jenkins上安装了Xvfb插件.

My Selenium headless tests are triggered from Jenkins server and run in EC2-Ubuntu. I want to view the test live on Chrome so I installed Xvfb plugin on Jenkins.

在EC2上,我安装了Xvfb.当我开始执行构建时,我的测试开始执行,并且我看到以下日志:

On EC2 I installed Xvfb. When I start executing the build, my test starts execution and I see below logs:

Xvfb /usr/bin/Xvfb :1 -fbdir /var/lib/jenkins/xvfb 27-..fbdir13700092919317283985

Parsing POMs
Established TCP socket on 30810

我看到测试运行成功.

现在我通过Mac终端通过SSH到EC2

Now I do SSH to EC2 from Mac terminal by

ssh -L 5901:localhost:5901 qa_user@10.113.x.xxx

然后我执行:

qa_user@jenkins-it:~$ export DISPLAY=: 30810` (Port number from Jenkins logs above)
qa_user@jenkins-it:~$ vncserver "$DISPLAY" -geometry 1280x1024

New 'X' desktop is jenkins-it: 30810

Starting applications specified in /home/qa_user/.vnc/xstartup
Log file is /home/qa_user/.vnc/jenkins-it: 30810.log

qa_user@jenkins-it:~$ x11vnc --listen 0.0.0.0 -rfbport 5901 -display : 30810

这将启动XVFB,我看到:

This starts XVFB and I see:

现在,当我从Mac连接到VNCviewer的localhost:5901时,我将被带到Ubuntu桌面.

Now when I connect from Mac to localhost:5901 from VNCviewer, I am taken to Ubuntu desktop.

但是即使测试正在运行,我也看不到chrome打开,并且在Jenkins上看到了测试日志.

But I don't see chrome opening up even though the test is running and I see test logs on Jenkins.

我还可以通过VncViewer使用Chrome.

I am also able to use Chrome via VncViewer.

我在这里想念什么? 我尝试了许多Xvfb设置说明,并且自一个月以来一直在尝试解决此问题.这是我问的几个问题:

What am I missing here? I tried many Xvfb set up instructions and has been trying to get this right since a month now. Here are few questions I asked:

https://askubuntu.com/questions /1262925/run-selenium-tests-on-ec2-with-gui?noredirect = 1#comment2139716_1262925

https://sqa.stackexchange.com/questions/45376/looking-for-a-solution-to-run-selenium-tests-on-ec2-with-gui/45380#45380

很长一段路要走到现在,现在Stackoverflow是我的最后选择.请帮忙.

Long way till here and now Stackoverflow is my last resort. Please help.

推荐答案

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

I found the solution to this myself. For anyone who's having the same issue:

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

What I did wrong was I used driver = new ChromeDriver(options); in my code instead of driver = new RemoteWebDriver(new URL("http://my.aws.ip:4444/wd/hub"), options);

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

After making this change, I downloaded selenium-server-standalone.jar to in EC2.

然后,在开始测试之前,我对ec2进行ssh -X qa_user@my.aws.ip并执行:

Then, before starting the test, I did ssh -X qa_user@my.aws.ip to EC2 and executed:

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

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

Now, execute the test, in parallel I opened a new terminal and did:

ssh -L 5900:localhost:5900 qa_user@my.aws.ip

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

Once the screen was set, I did:

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

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

Next, open VNC viewer, connect to localhost:5900 and you'll see Chrome execution.

稍后,如果需要,您可以将所有这些移至Jenkins预先构建的执行外壳中:)

Later you can move all this to Jenkins pre-build execute shell if required :)

有关我最新答案的更多详细信息: Jenkins上的XVFB连接到错误的显示器.显示屏显示黑屏

More details on my latest answer : XVFB on Jenkins connecting to wrong display. Display shows black screen

这篇关于EC2上的XVFB和Selenium-无法在VNC Viewer上查看Chrome UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆