Skip to content

Instantly share code, notes, and snippets.

Embed
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

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

This comment has been minimized.

Copy link

gimler commented Mar 11, 2013

save my day ;)

@jverdeyen

This comment has been minimized.

Copy link

jverdeyen commented Jul 10, 2013

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

@iNdioNicarao

This comment has been minimized.

Copy link

iNdioNicarao commented Aug 22, 2013

Thanks!

@IslandUsurper

This comment has been minimized.

Copy link

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.

@mpycio

This comment has been minimized.

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

This comment has been minimized.

Copy link

Natshah commented Nov 18, 2015

Thanks .. It's a clear one.

@aaronbauman

This comment has been minimized.

Copy link

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.