1

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.

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

and I see the test is running successfully.

Now I do SSH to EC2 from Mac terminal by

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

Then I execute:

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

This starts XVFB and I see:

enter image description here

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

enter image description here

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

I am also able to use Chrome via VncViewer. enter image description here

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

How to view live headless Selenium tests on EC2-Ubuntu using vncserver and xvfb

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

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

Afsal
  • 404
  • 3
  • 7
  • 24
  • You talking about Selenium "headless". Are you running ChromeDriver with headless flags? If Chrome runs in headless mode you will never see the UI. – Marc Sances Aug 20 '20 at 17:36
  • Yes. I have set chrome options to headless. If I don't, I believe it will throw 'Cannot find Chome Binary' error. Or at least before installing Xvfb it did. Are you suggesting to remove headless flags and try in xvfb? – Afsal Aug 20 '20 at 18:16
  • Yes. You must remove headless flags. Chrome headless flags, well, actually make the browser not spawn graphically. If you have a different error, edit the question after removing the flags or even better ask another question and we check that out. – Marc Sances Aug 20 '20 at 18:21
  • I get below error if I remove options.addArguments("--headless"); from my code. org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' – Afsal Aug 20 '20 at 18:30
  • Does Chrome open from that VNC session you have? Like double click the shortcut and see if it works – Marc Sances Aug 20 '20 at 18:31
  • Yes it does. Will add a screenshot of that to the question. Also, withou XVFB, I am able to run tests in EC2 in headless mode without any issues. But a new requirement has come where in we need to watch the live UI test. I am trying to achieve that using XVFB. Update: Added chrome screenshot to the question. – Afsal Aug 20 '20 at 18:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220169/discussion-between-marc-sances-and-afsal). – Marc Sances Aug 20 '20 at 19:29
  • Update: http://antonina.burlachenko.com/2013/09/sharing-of-remote-screen-for-selenium.html#comment-form This is exactly what I am trying to do and I am almost there. I followed the steps and the only issue now is that I see a black screen when I do the final localhost connection step to remote Ubuntu. I guess Chrome will be displayed on this screen but I am missing something. – Afsal Aug 21 '20 at 15:41
  • @MarcSances, posted the solution. :) – Afsal Sep 21 '20 at 05:53
  • Glad you managed to fix it finally... – Marc Sances Sep 21 '20 at 06:12

1 Answers1

2

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

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);

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

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

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

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

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

Afsal
  • 404
  • 3
  • 7
  • 24