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:

Display when XVFB starts

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

Ubuntu desktop via VNCviewer

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. Using Chorme manually via VNCViewer

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://stackoverflow.com/questions/63217945/how-to-view-live-headless-selenium-tests-on-ec2-ubuntu-using-vncserver-and-xvfb?noredirect=1#comment111814101_63217945

Looking for a solution to run selenium tests on EC2 with GUI

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

  • 1
    Headless means you cannot see UI. , Try doing the same with non headless mode and verify whether you can see chrome opening – PDHide Aug 21 at 20:23
  • 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 22 at 6:11
  • options.addArguments("--no-sandbox") try adding this – PDHide Aug 22 at 7:47
  • options.merge(capabilities);options.addArguments("start-maximized"); options.addArguments("enable-automation"); options.addArguments("--no-sandbox"); options.addArguments("--disable-infobars"); options.addArguments("--disable-dev-shm-usage"); options.addArguments("--disable-browser-side-navigation"); options.addArguments("--disable-gpu"); No sandbox is already added. This is my current code. – Afsal Aug 22 at 7:59
  • options.addArgument("--remote-debugging-port=9222") try this – PDHide Aug 22 at 11:24
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 : https://stackoverflow.com/questions/63935935/xvfb-on-jenkins-connecting-to-wrong-display-display-shows-black-screen

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.