I'm trying to use Behat/Mink in order to load a website.
I've used Composer for the installation, this is my composer.json:
{
"require": {
"behat/mink": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*",
"behat/mink-zombie-driver": "*"
}
}
In order to make the installation I've ran the following commands:
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
All was installed smoothly without any error messages.
This is my index.php file:
require 'vendor/autoload.php';
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\GoutteDriver,
Behat\Mink\Driver\Goutte\Client as GoutteClient,
Behat\Mink\Driver\SahiDriver;
$startUrl = 'www.example.com';
// init Mink and register sessions
$mink = new Mink(array(
'goutte1' => new Session(new GoutteDriver(GoutteClient($startUrl))),
'goutte2' => new Session(new GoutteDriver(GoutteClient($startUrl))),
'javascript' => new Session(new SahiDriver('firefox')),
'custom' => new Session(new MyCustomDriver($startUrl))
));
And I've tried to run it using this command:
$ php index.php
However I get the following error message:
PHP Fatal error: Call to undefined function GoutteClient() in index.php on line 14
Which refers to this line:
'goutte1' => new Session(new GoutteDriver(GoutteClient($startUrl))),
The installation was done using the following documentation:
The example was done following the documentation:
Any suggestions of what could I be doing wrong?
You forgot the "new" keyword before GoutClient. You should write:
$mink = new Mink(array(
'goutte1' => new Session(new GoutteDriver(new GoutteClient($startUrl))),
'goutte2' => new Session(new GoutteDriver(new GoutteClient($startUrl))),
'javascript' => new Session(new SahiDriver('firefox')),
'custom' => new Session(new MyCustomDriver($startUrl))
));
BTW: you don't have to initialize the GouteClient at all, GouteDriver should work just fine.
Here's a working example of Mink standalone: https://github.com/jakzal/web-scraper-demo