I'm trying to run chrome headless with my robot framework tests suites. I managed to do it independtly with python using selenium as follows:
options = webdriver.ChromeOptions()
options.add_argument('--headless')
my_driver = webdriver.Remote(command_executer=my_remote_address, desired_capabilities=options.to_capabilities)
The following code is what I did in robot but didn't work:
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${options.add_argument}= Set Variable add_argument=--headless
Create WebDriver Chrome chrome_options=${options}
Open Browser http://www.google.com chrome
Try out these two keywords:
First one will launch a local chrome, while the second one is to launch a remote chrome. If you need to be able to handle the remote vs. local into a single keyword, you can create a wrapper around these two with a boolean argument that will determine which keyword to call.
I created example repository and instructions how to run Chrome and Firefox native, headless or with docker and also included comparison chart for run times. You can find examples on my github page https://github.com/shnigi/Docker-Headless-Testing-Demo
The main Idea is however In both tests to use the Selenium's webdriver API to tell chromedriver and geckodriver to launch browser with some arguments. SeleniumLibrary's Open Browser keyword does not have this functionality, but Create Webdriver does the trick.
You will need latest browsers and drivers installed.
Please try the below. Run the keyword in Test setup
In newer versions of SeleniumLibrary (3.1.0) and Selenium (3.8.0) you can simply set the browser to
headlesschrome
instead ofchrome
.There's also
headlessfirefox
available.Ex.
http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Open%20Browser
To run headless you need to set the arguments and convert them to capabilities so that they can be used when using the
Remote Driver
option. This works for both theOpen Browser
as well as theCreate Webdriver
way of navigating to a URL.