Skip to content

Instantly share code, notes, and snippets.

@nottyo
Created May 12, 2017 09:31
Show Gist options
  • Save nottyo/e48e6c352d74e7eef677e1d7c5c2188e to your computer and use it in GitHub Desktop.
Save nottyo/e48e6c352d74e7eef677e1d7c5c2188e to your computer and use it in GitHub Desktop.
Selenium2Library with Chrome Headless Mode
*** Settings ***
Library Selenium2Library
*** Variables ***
${url} https://medium.com/@nottyo/
@{chrome_arguments} --disable-infobars --headless --disable-gpu
${page_text} Test Automation Engineer. Let’s make awesome tests
${timeout} 10s
*** Test Cases ***
TC_EXP_00001
[Documentation] Sample Test For Chrome Headless
[Tags] chrome headless
${chrome_options}= Set Chrome Options
Create Webdriver Chrome chrome_options=${chrome_options}
Go To ${url}
Wait Until Page Contains ${page_text} ${timeout}
Capture Page Screenshot
[Teardown] Close Browser
*** Keywords ***
Set Chrome Options
[Documentation] Set Chrome options for headless mode
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
: FOR ${option} IN @{chrome_arguments}
\ Call Method ${options} add_argument ${option}
[Return] ${options}
@GLMeece
Copy link

GLMeece commented Jul 25, 2017

Nice! I think your approach to having all the Chrome Options in a list makes a lot of sense. I have my line-by-line, which makes it easier to toggle arguments, but I may adopt your approach instead. Here's my take I've used for awhile.

@tompurl
Copy link

tompurl commented Feb 14, 2019

This is a great sample. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment