Skip to content

Instantly share code, notes, and snippets.

@up1
Last active January 3, 2020 20:28
Show Gist options
  • Save up1/0d299f6aebfd3bdcf7e863bcc98c0be7 to your computer and use it in GitHub Desktop.
Save up1/0d299f6aebfd3bdcf7e863bcc98c0be7 to your computer and use it in GitHub Desktop.
Robotframework + Google Chrome headless
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary");
chromeOptions.addArguments("--headless");
WebDriver Driver = new ChromeDriver(chromeOptions);
*** Settings ***
Library Collections
Library Selenium2Library
*** Test Cases ***
Hello chrome headless
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${options.set_binary}= Set Variable set_binary=/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary
${options.add_argument}= Set Variable add_argument=--headless
Create WebDriver Chrome chrome_options=${options}
Open Browser http://www.google.com chrome
Wait Until Page Contains ffgdfgdfgdfgdfg
Close Browser
@samratashok87
Copy link

Thanks for the update headless chrome beta version 60 does not seem to work with websites which have self signed SSL Certificates.
Please update if Chrome Canary version works with url having SSL error.

@arnaudruffin
Copy link

I found that the robot example won't work for me. I would replace the add_argument part with the following:

    ${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
     Call Method    ${chrome_options}    add_argument    headless

@asmilyanetc
Copy link

For robotframework I found better solution - https://github.com/drobota/robotframework-xvfb

@rameshho
Copy link

rameshho commented Dec 3, 2018

Exactly Below code worked for me, for headless chrome

*** Settings ***
Library  Selenium2Library

*** Test Cases ***
Test title
    ${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
    Call Method    ${options}    add_argument    --headless
    #my_create_webdriver   Chrome  ${options}
    create webdriver  Chrome  chrome_options=${options}
    Maximize Browser Window
    go to   https://google.com
    Maximize Browser Window
    capture page screenshot
    close browser

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