Skip to content

Instantly share code, notes, and snippets.

@callado4
Last active January 24, 2021 17:10
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save callado4/5068836 to your computer and use it in GitHub Desktop.
Save callado4/5068836 to your computer and use it in GitHub Desktop.
Instructions on how to make behat (with mink) use the phantomjs webdriver to run headless browser tests

Making behat use phantomjs for the tests

If you want to run it on phantomjs (a headless browser) you can add this profile to your behat.yml and you need phantomjs >= 1.8.0

phantomjs:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://dev.local
            goutte: ~
            selenium2:
                wd_host: "http://localhost:8643/wd/hub" 

    formatter:
        name:               pretty,html
        parameters:
            output_path:    null,jm_behat_report.html

start up the phantomjs web driver using: $ phantomjs --webdriver=8643

then run using:

$ ./bin/behat -p phantomjs

Note: You don't need to have selenium running as it communicates directly with the webdriver server that phantomjs/ghostdriver starts

Note2: apparently there is also a way to have it run by registering with a selenium hub and requesting the browserName 'phantomjs' but I couldn't get it to work, see https://github.com/detro/ghostdriver#register-ghostdriver-with-a-selenium-grid-hub or the copied instructions below

========== copied from ghostdriver ============

  1. Launch the grid server, which listens on 4444 by default: java -jar /path/to/selenium-server-standalone-2.25.0.jar -role hub
  2. Register with the hub: phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444
  3. Now you can use your normal webdriver client with http://127.0.0.1:4444 and just request browserName: phantomjs

========== copied from ghostdriver ============

@gimler
Copy link

gimler commented Mar 11, 2013

save my day ;)

@jverdeyen
Copy link

Any idea if xpath is working with phantomjs? Because it never returns elements in my case. Thanks!

@iNdioNicarao
Copy link

Thanks!

@IslandUsurper
Copy link

I have that problem @jverdeyen! Did you ever get a solution?

I don't have that problem. I have a problem with remembering to specify the profile to behat, because I don't have a default base_url.

@mpycio
Copy link

mpycio commented Nov 3, 2014

I had same problem with phantom but in my case I had something else alreaby bind to 8080, changing port helped.

@Natshah
Copy link

Natshah commented Nov 18, 2015

Thanks .. It's a clear one.

@aaronbauman
Copy link

If you are testing against an https base url and running a self-signed certificate, you will want to start the server with an additional --ignore-ssl-errors=true flag:

phantomjs --webdriver=8643 --ignore-ssl-errors=true

Otherwise i was getting enigmatic ElementNotFoundException errors for all my features / profiles.

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