0

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:

http://mink.behat.org/

The example was done following the documentation:

https://github.com/Behat/Mink

Any suggestions of what could I be doing wrong?

rfc1484
  • 9,441
  • 16
  • 72
  • 123
  • To run behat you don't run a php file you call behat from the command line. Consider reading all of the documentation because it feels like you stopped reading and went down another path. You start it by using the bin/behat command. The behat.yml file is for loading goutte and other drivers you want to use. You don't have to load it directly with php code. Let the framework do that for you. – branchgabriel Jan 08 '13 at 04:57

1 Answers1

1

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

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125