Search code examples
symfonyphantomjsbehatmink

How to get HTML page content using Mink with PhantomJS?


Using the Goutte driver with Behat / Mink, I could get the page content in a feature context method like this:

$this->getSession()->visit('/blog');
$html = $this->getSession()->getPage()->getHtml()

But now that I am using the Selenium2 driver with PhantomJS, the $html variable only contains the following text:

<head></head><body></body>

Did I miss a parameter (like the base URL for instance)?

Here is my behat.yml configuration:

default:
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            base_url: 'http://localhost:8000'
            selenium2:
                wd_host: "http://localhost:8643/wd/hub"

Solution

  • Alright, it's always the same: I looked for the solution for hours before asking here, but I found the solution just a few minutes later after asking.

    So it was indeed a problem with the base URL.

    The generic way to call the visit method is the following:

    $this->getSession()->visit($this->locatePath('/blog'))
    

    The locatePath method is used to retrieve the base URL and is used for Given I am on <page>.