Selenium using a virtual screen display in Ubuntu

7th October, 2022

Selenium is very commonly used for end to end testing for websites. However due to the rise of javascript based websites, it is often needed to mimic an exact browser session rather than using the seleniun driver in headless mode. In order to achieve this in remote server, a virtual screen is required where chrome or firefox can open a session using X server.

Following steps can help us to mimic a browser session using X server in an Ubuntu based machine.

 

  1. sudo apt-get install xvfb
  2. Xvfb :99 &
  3. export DISPLAY=:99

That's it. The above mentioned commands will initiate X server which will allow any browser to open without headless mode.