MonkeyStorm
MonkeyStorm

Reputation: 51

Run behat chrome headless (without selenium?)

I ran Behat test on PhantomJS without issue. I was starting it with this:

bin/phantomjs --webdriver=8643

It works, but I want to run a Chrome headless instead of PhantomJS. To do that I tried this:

google-chrome --headless --remote-debugging-port=8643

But Behat doesn't seem to start anything on this Chrome. I found a lot of docs for Chrome with Selenium but I wanted to know if it's possible to run it like I was running PhantomJS with the Selenium driver, but without Selenium server?

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Behat\MinkExtension\Context\MinkContext
  extensions:
    Behat\MinkExtension:
      base_url: 'http://myurl.com/'
      sessions:
        default:
          selenium2:
            wd_host: 'http://localhost:8643'

Upvotes: 1

Views: 4312

Answers (2)

michfuer
michfuer

Reputation: 119

This worked for me on Ubuntu 16.04 LTS

default:    
  extensions:
    Behat\MinkExtension:
      sessions:
        default_session:
          selenium2:
            browser: chrome
            wd_host: http://127.0.0.1:9515
            capabilities:
              chrome:
                switches:
                  - "--headless"
                  - "--disable-gpu"

Upvotes: -1

romaricdrigon
romaricdrigon

Reputation: 1587

To run your tests on Google Chrome, you will need chromedriver
Then you can use the port chromedriver is listening to (9515 by default) instead of PhantomJs 8643. You don't need Selenium anymore then.
Finally, you pass the --headless flag to chrome so you don't need xfvb.

A config example:

# behat.yml
default:
    extensions:
        # ...
        Behat\MinkExtension:
            base_url: 'http://myurl.com/'
            sessions:
                default:
                    selenium2:
                        browser: chrome
                        # Note: I'm not totally sure you still need the /wd/hub path
                        wd_host: http://localhost:9515/wd/hub
                        capabilities:
                            chrome:
                                switches:
                                    - "--headless"

More documentation: https://developers.google.com/web/updates/2017/04/headless-chrome

Upvotes: 1

Related Questions