Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run browsers(chrome, IE and firefox) in headless mode?

I want to integrate JSTestDriver with jenkins-CI. problem is that the build server does not have display. is there a way to run browsers headlessly?

Thanks

like image 351
Mukesh Kumar Avatar asked Mar 08 '13 08:03

Mukesh Kumar


2 Answers

Google Chrome now (Chrome 59 for Mac and Linux, Chrome 60 for Windows) has a headless mode built-in. It works cross-platform, and doesn't require any messing around with display devices, virtual machines, or anything like that. You can find a great Getting Started article by Eric Bidelman here, but here are the most key points:

You must launch the Chrome binary (on macOS it is located inside the Google Chrome.app bundle in the the Contents/MacOS directory) using --headless flag. It is currently also necessary to add the --disable-gpu flag, because GPU acceleration does not work properly in headless mode.

chrome --headless --disable-gpu [url/path/flags...]

As with standard non-headless Chrome, your test runner can communicate with Chrome using the dev tools interface if it's enabled by the --remote-debugging-port=[SOME_PORT] flag. However, if you'd just like to test it quickly by yourself you can use the --screenshot or --dump-dom flags to check out the contents of the page after loading.

chrome --headless --disable-gpu --dump-dom https://stackoverflow.com/
like image 32
Jeremy Avatar answered Oct 23 '22 11:10

Jeremy


If your server is Linux, as mentioned, you can't run IE. But you can run other browsers like Firefox. The trick is to install XVFB on your Jenkins server which allows Firefox to run headless. I've used this setup and it works well.

http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

like image 198
ProgrammerGuy Avatar answered Oct 23 '22 09:10

ProgrammerGuy