Skip to content

marvin-neumann/ansible-chrome-headless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible playbook for headless Chrome with ChromeDriver

This playbook will download and install the latest version of Chrome and ChromeDriver.

The latest version of ChromeDriver allows you to run Chrome browser in headless mode without Selenium and doesn't need any Display server or Xvfb.

Requirements

  • git
  • ansible
  • codeception (for tests)

Setup

  1. Clone this repo with git
    $ git clone https://github.com/marvin-neumann/ansible-chrome-headless.git
  1. Then run the playbook with ansible-playbook
    $ ansible-playbook -l localhost ansible-chrome-headless/playbook.yml --ask-sudo-pass

Codeception Acceptance testing with Chrome headless

  1. Change the acceptance.suite.yml in your tests directory, put everything below in the Webdriver part und change the url.
        WebDriver:
            url: 'http://example.com/'
            browser: chrome
            port: 9515
            window_size: false
            capabilities:
                chromeOptions:
                    args: ["--headless", "--disable-gpu", "window-size=1920x1080"]
                    binary: "/usr/bin/google-chrome"
  1. Start ChromeDriver, the binary is placed in /usr/local/bin so you can call it from anywhere
    $ chromedriver --url-base=/wd/hub --whitelisted-ips='' --verbose
  1. Then run your tests.

Acceptance test issues with ChromeDriver v2.31

Even though you are writing valid tests, there are a few problems that can occur when running some versions of ChromeDriver.

  • If an element cannot be clicked because it is outside the viewport, you have to scroll to the element first, then click the element.
    $I->scrollTo('button.outside-viewport');
    $I->click(['css' => 'button.outside-viewport']);;
  • If filling a date input field with the fillField action doesn't work, use the pressKey action instead.
    # if this doesn't work  
    $I->fillField('input#date', '2017-08-31');  
    # use this instead  
    $I->pressKey('input#date', '2017-08-31');