Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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

            base_url: http://dev.local
            goutte: ~
                wd_host: "http://localhost:8643/wd/hub" 

        name:               pretty,html
            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 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=
  3. Now you can use your normal webdriver client with and just request browserName: phantomjs

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


This comment has been minimized.

Copy link

@gimler gimler commented Mar 11, 2013

save my day ;)


This comment has been minimized.

Copy link

@jverdeyen jverdeyen commented Jul 10, 2013

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


This comment has been minimized.

Copy link

@iNdioNicarao iNdioNicarao commented Aug 22, 2013



This comment has been minimized.

Copy link

@IslandUsurper IslandUsurper commented Jun 18, 2014

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.


This comment has been minimized.

Copy link

@mpycio 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.


This comment has been minimized.

Copy link

@Natshah Natshah commented Nov 18, 2015

Thanks .. It's a clear one.


This comment has been minimized.

Copy link

@aaronbauman aaronbauman commented Feb 12, 2016

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
You can’t perform that action at this time.