Merge pull request #121 from stof/driver_factory
Refactored the configuration of sessions
This commit is contained in:
@@ -6,4 +6,6 @@ default:
|
|||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
base_url: http://en.wikipedia.org/
|
base_url: http://en.wikipedia.org/
|
||||||
goutte: ~
|
sessions:
|
||||||
|
default:
|
||||||
|
goutte: ~
|
||||||
|
|||||||
137
doc/index.rst
137
doc/index.rst
@@ -60,7 +60,9 @@ The easiest way to keep your suite updated is to use `Composer <http://getcompos
|
|||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
base_url: 'http://example.com'
|
base_url: 'http://example.com'
|
||||||
goutte: ~
|
sessions:
|
||||||
|
default:
|
||||||
|
goutte: ~
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
@@ -161,22 +163,58 @@ Configuration
|
|||||||
MinkExtension comes with flexible configuration system, that gives you
|
MinkExtension comes with flexible configuration system, that gives you
|
||||||
ability to configure Mink inside Behat to fulfil all your needs.
|
ability to configure Mink inside Behat to fulfil all your needs.
|
||||||
|
|
||||||
Drivers
|
Sessions
|
||||||
~~~~~~~
|
--------
|
||||||
|
|
||||||
First of all, there's drivers enabling configuration. MinkExtension comes
|
You can register as many Mink session as you want. For each session, you
|
||||||
with support for 6 drivers out of the box:
|
will need to choose the driver you want to use.
|
||||||
|
|
||||||
* ``GoutteDriver`` - default headless driver. It is used by default, which means
|
|
||||||
that if you didn't changed ``default_session`` (another parameter) - you should
|
|
||||||
always enable it. In order to enable it, modify your ``behat.yml`` profile:
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
goutte: ~
|
sessions:
|
||||||
|
first_session:
|
||||||
|
selenium2: ~
|
||||||
|
second_session:
|
||||||
|
goutte: ~
|
||||||
|
third_session:
|
||||||
|
selenium2: ~
|
||||||
|
|
||||||
|
MinkExtension will set the default Mink session for each scenario based on
|
||||||
|
the configuration settings ``default_session`` and ``javascript_session``
|
||||||
|
and on scenario tags:
|
||||||
|
|
||||||
|
* A scenario tagged with ``@mink:foo`` will use ``foo`` as default session;
|
||||||
|
* A scenario tagged with ``@javascript`` will use the javascript session as default session;
|
||||||
|
* Other scenarios will use the default session.
|
||||||
|
|
||||||
|
If it is not configured explicitly, the javascript session is set to the first
|
||||||
|
session using a javascript driver in the order of the configuration (it would
|
||||||
|
be ``first_session`` in the example above as ``selenium2`` supports Javascript).
|
||||||
|
If it is not configured explicitly, the default session is set to the first
|
||||||
|
session using a non-javascript driver if any, or to the first javascript session
|
||||||
|
otherwise (it would be ``second_session`` above as ``goutte`` does not support
|
||||||
|
javascript).
|
||||||
|
|
||||||
|
Drivers
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
First of all, there's drivers enabling configuration. MinkExtension comes
|
||||||
|
with support for 6 drivers out of the box:
|
||||||
|
|
||||||
|
* ``GoutteDriver`` - headless driver without JavaScript support. In order to use
|
||||||
|
it, modify your ``behat.yml`` profile:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
default:
|
||||||
|
extensions:
|
||||||
|
Behat\MinkExtension\Extension:
|
||||||
|
sessions:
|
||||||
|
my_session:
|
||||||
|
goutte: ~
|
||||||
|
|
||||||
.. Tips : HTTPS and self-signed certificate
|
.. Tips : HTTPS and self-signed certificate
|
||||||
In case you use Behat/Mink/Goutte to test your application, and want to test an
|
In case you use Behat/Mink/Goutte to test your application, and want to test an
|
||||||
@@ -188,28 +226,38 @@ the following parameters to avoid the validation error triggered by Guzzle :
|
|||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
goutte:
|
sessions:
|
||||||
guzzle_parameters:
|
my_session:
|
||||||
ssl.certificate_authority: false
|
goutte:
|
||||||
|
guzzle_parameters:
|
||||||
|
ssl.certificate_authority: false
|
||||||
|
|
||||||
* ``Selenium2Driver`` - default javascript driver. It is used by default for
|
* ``Selenium2Driver`` - javascript driver. In order to use it, modify your
|
||||||
``@javascript`` tagged scenarios, which means that if you didn't changed
|
``behat.yml`` profile:
|
||||||
``javascript_session`` (another parameter) - you should always enable it (only
|
|
||||||
if you use ``@javascript`` scenarios, of course). In order to enable it,
|
|
||||||
modify your ``behat.yml`` profile:
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
selenium2: ~
|
sessions:
|
||||||
|
my_session:
|
||||||
|
selenium2: ~
|
||||||
|
|
||||||
* ``SaucelabsDriver`` - special flavor of the Selenium2Driver configured to use the
|
* ``SaucelabsDriver`` - special flavor of the Selenium2Driver configured to use the
|
||||||
selenium2 hosted installation of saucelabs.com. You could use it by setting it in
|
selenium2 hosted installation of saucelabs.com. In order to use it, modify your
|
||||||
``javascript_session`` to ``saucelabs`` and by marking scenarios as ``@javascript``
|
``behat.yml`` profile:
|
||||||
or simply by marking scenarios with ``mink:saucelabs`` (no need to switch
|
|
||||||
``javascript_session`` in this case). In order to enable it, modify your ``behat.yml``
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
default:
|
||||||
|
extensions:
|
||||||
|
Behat\MinkExtension\Extension:
|
||||||
|
sessions:
|
||||||
|
my_session:
|
||||||
|
saucelabs: ~
|
||||||
|
|
||||||
|
* ``SeleniumDriver`` - javascript driver. In order to use it, modify your ``behat.yml``
|
||||||
profile:
|
profile:
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
@@ -217,12 +265,11 @@ the following parameters to avoid the validation error triggered by Guzzle :
|
|||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
saucelabs: ~
|
sessions:
|
||||||
|
my_session:
|
||||||
|
selenium: ~
|
||||||
|
|
||||||
* ``SeleniumDriver`` - another javascript driver. You could use it by setting it
|
* ``SahiDriver`` - javascript driver. In order to use it, modify your ``behat.yml``
|
||||||
in ``javascript_session`` to ``selenium`` and by marking scenarios as ``@javascript``
|
|
||||||
or simply by marking scenarios with ``mink:selenium`` (no need to switch
|
|
||||||
``javascript_session`` in this case). In order to enable it, modify your ``behat.yml``
|
|
||||||
profile:
|
profile:
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
@@ -230,33 +277,21 @@ the following parameters to avoid the validation error triggered by Guzzle :
|
|||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
selenium: ~
|
sessions:
|
||||||
|
my_session:
|
||||||
|
sahi: ~
|
||||||
|
|
||||||
* ``SahiDriver`` - another javascript driver. You could use it by setting it
|
* ``ZombieDriver`` - zombie.js javascript headless driver. In order to use it, modify
|
||||||
in ``javascript_session`` to ``sahi`` and by marking scenarios as ``@javascript``
|
your ``behat.yml`` profile:
|
||||||
or simply by marking scenarios with ``mink:sahi`` (no need to switch
|
|
||||||
``javascript_session`` in this case). In order to enable it, modify your ``behat.yml``
|
|
||||||
profile:
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
default:
|
default:
|
||||||
extensions:
|
extensions:
|
||||||
Behat\MinkExtension\Extension:
|
Behat\MinkExtension\Extension:
|
||||||
sahi: ~
|
sessions:
|
||||||
|
default:
|
||||||
* ``ZombieDriver`` - zombie.js javascript headless driver. You could use it by setting it
|
zombie: ~
|
||||||
in ``javascript_session`` to ``zombie`` and by marking scenarios as ``@javascript``
|
|
||||||
or simply by marking scenarios with ``mink:zombie`` (no need to switch
|
|
||||||
``javascript_session`` in this case). In order to enable it, modify your ``behat.yml``
|
|
||||||
profile:
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
default:
|
|
||||||
extensions:
|
|
||||||
Behat\MinkExtension\Extension:
|
|
||||||
zombie: ~
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
@@ -300,9 +335,9 @@ There's other useful parameters, that you can use to configure your suite:
|
|||||||
* ``browser_name`` - meta-option, that defines which browser to use for Sahi,
|
* ``browser_name`` - meta-option, that defines which browser to use for Sahi,
|
||||||
Selenium and Selenium2 drivers.
|
Selenium and Selenium2 drivers.
|
||||||
* ``default_session`` - defines default session (driver) to be used for all
|
* ``default_session`` - defines default session (driver) to be used for all
|
||||||
untagged scenarios. Could be any enabled driver name. Defaults to ``goutte``
|
untagged scenarios. Could be any enabled session name.
|
||||||
* ``javascript_session`` - defines javascript session (driver) (the one, which
|
* ``javascript_session`` - defines javascript session (driver) (the one, which
|
||||||
will be used for ``@javascript`` tagged scenarios). Could be any enabled driver
|
will be used for ``@javascript`` tagged scenarios). Could be any enabled session
|
||||||
name. Defaults to ``selenium2``
|
name.
|
||||||
* ``mink_loader`` - path to a file loaded to make Mink available (useful when
|
* ``mink_loader`` - path to a file loaded to make Mink available (useful when
|
||||||
using the PHAR archive for Mink, useless when using Composer)
|
using the PHAR archive for Mink, useless when using Composer)
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ use Behat\Behat\Tester\Event\ScenarioTested;
|
|||||||
use Behat\Gherkin\Node\FeatureNode;
|
use Behat\Gherkin\Node\FeatureNode;
|
||||||
use Behat\Gherkin\Node\ScenarioNode;
|
use Behat\Gherkin\Node\ScenarioNode;
|
||||||
use Behat\Mink\Mink;
|
use Behat\Mink\Mink;
|
||||||
|
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
||||||
use PhpSpec\ObjectBehavior;
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
class SessionsListenerSpec extends ObjectBehavior
|
class SessionsListenerSpec extends ObjectBehavior
|
||||||
{
|
{
|
||||||
function let(Mink $mink, ScenarioTested $event, FeatureNode $feature, ScenarioNode $scenario)
|
function let(Mink $mink, ScenarioTested $event, FeatureNode $feature, ScenarioNode $scenario)
|
||||||
{
|
{
|
||||||
$this->beConstructedWith($mink, array('default_session' => 'goutte', 'javascript_session' => 'selenium2'));
|
$this->beConstructedWith($mink, 'goutte', 'selenium2');
|
||||||
|
|
||||||
$event->getFeature()->willReturn($feature);
|
$event->getFeature()->willReturn($feature);
|
||||||
$event->getScenario()->willReturn($scenario);
|
$event->getScenario()->willReturn($scenario);
|
||||||
@@ -54,6 +55,15 @@ class SessionsListenerSpec extends ObjectBehavior
|
|||||||
$this->prepareDefaultMinkSession($event);
|
$this->prepareDefaultMinkSession($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function it_fails_when_the_javascript_session_is_used_but_not_defined($event, $mink, $feature)
|
||||||
|
{
|
||||||
|
$this->beConstructedWith($mink, 'goutte', null);
|
||||||
|
$feature->getTags()->willReturn(array('javascript'));
|
||||||
|
|
||||||
|
$this->shouldThrow(new ProcessingException('The @javascript tag cannot be used without enabling a javascript session'))
|
||||||
|
->duringPrepareDefaultMinkSession($event);
|
||||||
|
}
|
||||||
|
|
||||||
function it_switches_to_a_named_session($event, $mink, $scenario)
|
function it_switches_to_a_named_session($event, $mink, $scenario)
|
||||||
{
|
{
|
||||||
$scenario->getTags()->willReturn(array('mink:test'));
|
$scenario->getTags()->willReturn(array('mink:test'));
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class GoutteFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_goutte()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('goutte');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_does_not_support_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class SahiFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_sahi()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('sahi');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_supports_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class SaucelabsFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_saucelabs()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('saucelabs');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_supports_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class Selenium2FactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_selenium2()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('selenium2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_supports_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class SeleniumFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_selenium()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('selenium');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_supports_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace spec\Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use PhpSpec\ObjectBehavior;
|
||||||
|
|
||||||
|
class ZombieFactorySpec extends ObjectBehavior
|
||||||
|
{
|
||||||
|
function it_is_a_driver_factory()
|
||||||
|
{
|
||||||
|
$this->shouldHaveType('Behat\MinkExtension\ServiceContainer\Driver\DriverFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_is_named_zombie()
|
||||||
|
{
|
||||||
|
$this->getDriverName()->shouldReturn('zombie');
|
||||||
|
}
|
||||||
|
|
||||||
|
function it_supports_javascript()
|
||||||
|
{
|
||||||
|
$this->supportsJavascript()->shouldBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,11 +11,19 @@
|
|||||||
namespace Behat\MinkExtension;
|
namespace Behat\MinkExtension;
|
||||||
|
|
||||||
use Behat\Behat\Context\ServiceContainer\ContextExtension;
|
use Behat\Behat\Context\ServiceContainer\ContextExtension;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\GoutteFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\SahiFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\SaucelabsFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\SeleniumFactory;
|
||||||
|
use Behat\MinkExtension\ServiceContainer\Driver\ZombieFactory;
|
||||||
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
|
||||||
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
||||||
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
|
||||||
use Behat\Testwork\ServiceContainer\ExtensionManager;
|
use Behat\Testwork\ServiceContainer\ExtensionManager;
|
||||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
@@ -30,9 +38,28 @@ class Extension implements ExtensionInterface
|
|||||||
const MINK_ID = 'mink';
|
const MINK_ID = 'mink';
|
||||||
const SELECTORS_HANDLER_ID = 'mink.selectors_handler';
|
const SELECTORS_HANDLER_ID = 'mink.selectors_handler';
|
||||||
|
|
||||||
const SESSION_TAG = 'mink.session';
|
|
||||||
const SELECTOR_TAG = 'mink.selector';
|
const SELECTOR_TAG = 'mink.selector';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DriverFactory[]
|
||||||
|
*/
|
||||||
|
private $driverFactories = array();
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->registerDriverFactory(new GoutteFactory());
|
||||||
|
$this->registerDriverFactory(new SahiFactory());
|
||||||
|
$this->registerDriverFactory(new SeleniumFactory());
|
||||||
|
$this->registerDriverFactory(new Selenium2Factory());
|
||||||
|
$this->registerDriverFactory(new SaucelabsFactory());
|
||||||
|
$this->registerDriverFactory(new ZombieFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerDriverFactory(DriverFactory $driverFactory)
|
||||||
|
{
|
||||||
|
$this->driverFactories[$driverFactory->getDriverName()] = $driverFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@@ -51,41 +78,17 @@ class Extension implements ExtensionInterface
|
|||||||
$this->loadMink($container);
|
$this->loadMink($container);
|
||||||
$this->loadContextInitializer($container);
|
$this->loadContextInitializer($container);
|
||||||
$this->loadSelectorsHandler($container);
|
$this->loadSelectorsHandler($container);
|
||||||
|
$this->loadSessions($container, $config);
|
||||||
$this->loadSessionsListener($container);
|
$this->loadSessionsListener($container);
|
||||||
|
|
||||||
if ($config['show_auto']) {
|
if ($config['show_auto']) {
|
||||||
$this->loadFailureShowListener($container);
|
$this->loadFailureShowListener($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['goutte'])) {
|
unset($config['sessions']);
|
||||||
$this->loadGoutteSession($container, $config['goutte']);
|
|
||||||
unset($config['goutte']);
|
|
||||||
}
|
|
||||||
if (isset($config['sahi'])) {
|
|
||||||
$this->loadSahiSession($container, $config['sahi']);
|
|
||||||
unset($config['sahi']);
|
|
||||||
}
|
|
||||||
if (isset($config['zombie'])) {
|
|
||||||
$this->loadZombieSession($container, $config['zombie']);
|
|
||||||
unset($config['zombie']);
|
|
||||||
}
|
|
||||||
if (isset($config['selenium'])) {
|
|
||||||
$this->loadSeleniumSession($container, $config['selenium']);
|
|
||||||
unset($config['zombie']);
|
|
||||||
}
|
|
||||||
if (isset($config['selenium2'])) {
|
|
||||||
$this->loadSelenium2Session($container, $config['selenium2']);
|
|
||||||
unset($config['selenium2']);
|
|
||||||
}
|
|
||||||
if (isset($config['saucelabs'])) {
|
|
||||||
$this->loadSaucelabsSession($container, $config['saucelabs']);
|
|
||||||
unset($config['saucelabs']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$container->setParameter('mink.parameters', $config);
|
$container->setParameter('mink.parameters', $config);
|
||||||
$container->setParameter('mink.base_url', $config['base_url']);
|
$container->setParameter('mink.base_url', $config['base_url']);
|
||||||
$container->setParameter('mink.default_session', $config['default_session']);
|
|
||||||
$container->setParameter('mink.javascript_session', $config['javascript_session']);
|
|
||||||
$container->setParameter('mink.browser_name', $config['browser_name']);
|
$container->setParameter('mink.browser_name', $config['browser_name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +97,28 @@ class Extension implements ExtensionInterface
|
|||||||
*/
|
*/
|
||||||
public function configure(ArrayNodeDefinition $builder)
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
{
|
{
|
||||||
|
// Rewrite keys to define a shortcut way without allowing conflicts with real keys
|
||||||
|
$renamedKeys = array_diff(
|
||||||
|
array_keys($this->driverFactories),
|
||||||
|
array('mink_loader', 'base_url', 'files_path', 'show_auto', 'show_cmd', 'show_tmp_dir', 'default_session', 'javascript_session', 'browser_name', 'sessions')
|
||||||
|
);
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
|
->beforeNormalization()
|
||||||
|
->always()
|
||||||
|
->then(function ($v) use ($renamedKeys) {
|
||||||
|
foreach ($renamedKeys as $driverType) {
|
||||||
|
if (!array_key_exists($driverType, $v) || isset($v['sessions'][$driverType])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$v['sessions'][$driverType][$driverType] = $v[$driverType];
|
||||||
|
unset($v[$driverType]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
})
|
||||||
|
->end()
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('mink_loader')->defaultNull()->end()
|
->scalarNode('mink_loader')->defaultNull()->end()
|
||||||
@@ -103,151 +127,38 @@ class Extension implements ExtensionInterface
|
|||||||
->booleanNode('show_auto')->defaultFalse()->end()
|
->booleanNode('show_auto')->defaultFalse()->end()
|
||||||
->scalarNode('show_cmd')->defaultNull()->end()
|
->scalarNode('show_cmd')->defaultNull()->end()
|
||||||
->scalarNode('show_tmp_dir')->defaultValue(sys_get_temp_dir())->end()
|
->scalarNode('show_tmp_dir')->defaultValue(sys_get_temp_dir())->end()
|
||||||
->scalarNode('default_session')->defaultValue('goutte')->end()
|
->scalarNode('default_session')->defaultNull()->info('Defaults to the first non-javascript session if any, or the first session otherwise')->end()
|
||||||
->scalarNode('javascript_session')->defaultValue('selenium2')->end()
|
->scalarNode('javascript_session')->defaultNull()->info('Defaults to the first javascript session if any')->end()
|
||||||
->scalarNode('browser_name')->defaultValue('firefox')->end()
|
->scalarNode('browser_name')->defaultValue('firefox')->end()
|
||||||
->arrayNode('goutte')
|
|
||||||
->children()
|
|
||||||
->arrayNode('server_parameters')
|
|
||||||
->useAttributeAsKey('key')
|
|
||||||
->prototype('variable')->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('guzzle_parameters')
|
|
||||||
->useAttributeAsKey('key')
|
|
||||||
->prototype('variable')->end()
|
|
||||||
->validate()
|
|
||||||
->always()
|
|
||||||
->then(function ($v) {
|
|
||||||
$v['redirect.disable'] = true;
|
|
||||||
|
|
||||||
return $v;
|
|
||||||
})
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('sahi')
|
|
||||||
->children()
|
|
||||||
->scalarNode('sid')->defaultNull()->end()
|
|
||||||
->scalarNode('host')->defaultValue('localhost')->end()
|
|
||||||
->scalarNode('port')->defaultValue(9999)->end()
|
|
||||||
->scalarNode('browser')->defaultNull()->end()
|
|
||||||
->scalarNode('limit')->defaultValue(600)->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('zombie')
|
|
||||||
->children()
|
|
||||||
->scalarNode('host')->defaultValue('127.0.0.1')->end()
|
|
||||||
->scalarNode('port')->defaultValue(8124)->end()
|
|
||||||
->booleanNode('auto_server')->defaultValue(true)->end()
|
|
||||||
->scalarNode('node_bin')->defaultValue('node')->end()
|
|
||||||
->scalarNode('server_path')->defaultNull()->end()
|
|
||||||
->scalarNode('threshold')->defaultValue(2000000)->end()
|
|
||||||
->scalarNode('node_modules_path')->defaultValue('')->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('selenium')
|
|
||||||
->children()
|
|
||||||
->scalarNode('host')->defaultValue('127.0.0.1')->end()
|
|
||||||
->scalarNode('port')->defaultValue(4444)->end()
|
|
||||||
->scalarNode('browser')->defaultValue('*%mink.browser_name%')->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('selenium2')
|
|
||||||
->children()
|
|
||||||
->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
|
|
||||||
->arrayNode('capabilities')
|
|
||||||
->addDefaultsIfNotSet()
|
|
||||||
->normalizeKeys(false)
|
|
||||||
->children()
|
|
||||||
->scalarNode('browserName')->defaultValue('firefox')->end()
|
|
||||||
->scalarNode('version')->defaultValue('9')->end()
|
|
||||||
->scalarNode('platform')->defaultValue('ANY')->end()
|
|
||||||
->scalarNode('browserVersion')->defaultValue('9')->end()
|
|
||||||
->scalarNode('browser')->defaultValue('firefox')->end()
|
|
||||||
->scalarNode('ignoreZoomSetting')->defaultValue('false')->end()
|
|
||||||
->scalarNode('name')->defaultValue('Behat Test')->end()
|
|
||||||
->scalarNode('deviceOrientation')->defaultValue('portrait')->end()
|
|
||||||
->scalarNode('deviceType')->defaultValue('tablet')->end()
|
|
||||||
->scalarNode('selenium-version')->defaultValue('2.31.0')->end()
|
|
||||||
->scalarNode('max-duration')->defaultValue('300')->end()
|
|
||||||
->booleanNode('javascriptEnabled')->end()
|
|
||||||
->booleanNode('databaseEnabled')->end()
|
|
||||||
->booleanNode('locationContextEnabled')->end()
|
|
||||||
->booleanNode('applicationCacheEnabled')->end()
|
|
||||||
->booleanNode('browserConnectionEnabled')->end()
|
|
||||||
->booleanNode('webStorageEnabled')->end()
|
|
||||||
->booleanNode('rotatable')->end()
|
|
||||||
->booleanNode('acceptSslCerts')->end()
|
|
||||||
->booleanNode('nativeEvents')->end()
|
|
||||||
->booleanNode('passed')->end()
|
|
||||||
->booleanNode('record-video')->end()
|
|
||||||
->booleanNode('record-screenshots')->end()
|
|
||||||
->booleanNode('capture-html')->end()
|
|
||||||
->booleanNode('disable-popup-handler')->end()
|
|
||||||
->arrayNode('proxy')
|
|
||||||
->children()
|
|
||||||
->scalarNode('proxyType')->end()
|
|
||||||
->scalarNode('proxyAuthconfigUrl')->end()
|
|
||||||
->scalarNode('ftpProxy')->end()
|
|
||||||
->scalarNode('httpProxy')->end()
|
|
||||||
->scalarNode('sslProxy')->end()
|
|
||||||
->end()
|
|
||||||
->validate()
|
|
||||||
->ifTrue(function ($v) {
|
|
||||||
return empty($v);
|
|
||||||
})
|
|
||||||
->thenUnset()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('firefox')
|
|
||||||
->children()
|
|
||||||
->scalarNode('profile')
|
|
||||||
->validate()
|
|
||||||
->ifTrue(function ($v) {
|
|
||||||
return !file_exists($v);
|
|
||||||
})
|
|
||||||
->thenInvalid('Cannot find profile zip file %s')
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->scalarNode('binary')->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('chrome')
|
|
||||||
->children()
|
|
||||||
->arrayNode('switches')->prototype('scalar')->end()->end()
|
|
||||||
->scalarNode('binary')->end()
|
|
||||||
->arrayNode('extensions')->prototype('scalar')->end()->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->arrayNode('saucelabs')
|
|
||||||
->children()
|
|
||||||
->scalarNode('username')->defaultValue(getenv('SAUCE_USERNAME'))->end()
|
|
||||||
->scalarNode('access_key')->defaultValue(getenv('SAUCE_ACCESS_KEY'))->end()
|
|
||||||
->booleanNode('connect')->defaultFalse()->end()
|
|
||||||
->scalarNode('browser')->defaultValue('firefox')->end()
|
|
||||||
->arrayNode('capabilities')
|
|
||||||
->addDefaultsIfNotSet()
|
|
||||||
->normalizeKeys(false)
|
|
||||||
->children()
|
|
||||||
->scalarNode('name')->defaultValue('Behat feature suite')->end()
|
|
||||||
->scalarNode('platform')->defaultValue('Linux')->end()
|
|
||||||
->scalarNode('version')->defaultValue('21')->end()
|
|
||||||
->scalarNode('selenium-version')->defaultValue('2.31.0')->end()
|
|
||||||
->scalarNode('max-duration')->defaultValue('300')->end()
|
|
||||||
->scalarNode('deviceType')->defaultNull()->end()
|
|
||||||
->scalarNode('deviceOrientation')->defaultNull()->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
|
/** @var ArrayNodeDefinition $sessionsBuilder */
|
||||||
|
$sessionsBuilder = $builder
|
||||||
|
->children()
|
||||||
|
->arrayNode('sessions')
|
||||||
|
->isRequired()
|
||||||
|
->requiresAtLeastOneElement()
|
||||||
|
->useAttributeAsKey('name')
|
||||||
|
->prototype('array')
|
||||||
|
;
|
||||||
|
|
||||||
|
foreach ($this->driverFactories as $factory) {
|
||||||
|
$factoryNode = $sessionsBuilder->children()->arrayNode($factory->getDriverName())->canBeUnset();
|
||||||
|
|
||||||
|
$factory->configure($factoryNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sessionsBuilder
|
||||||
|
->validate()
|
||||||
|
->ifTrue(function ($v) {return count($v) > 1;})
|
||||||
|
->thenInvalid('You cannot set multiple driver types for the same session')
|
||||||
|
->end()
|
||||||
|
->validate()
|
||||||
|
->ifTrue(function ($v) {return count($v) === 0;})
|
||||||
|
->thenInvalid('You must set a driver definition for the session.')
|
||||||
|
->end()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -270,7 +181,6 @@ class Extension implements ExtensionInterface
|
|||||||
*/
|
*/
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$this->processSessions($container);
|
|
||||||
$this->processSelectors($container);
|
$this->processSelectors($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,11 +212,57 @@ class Extension implements ExtensionInterface
|
|||||||
$container->setDefinition(self::SELECTOR_TAG . '.named', $namedSelectorDefinition);
|
$container->setDefinition(self::SELECTOR_TAG . '.named', $namedSelectorDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadSessions(ContainerBuilder $container, array $config)
|
||||||
|
{
|
||||||
|
$defaultSession = $config['default_session'];
|
||||||
|
$javascriptSession = $config['javascript_session'];
|
||||||
|
$javascriptSessions = $nonJavascriptSessions = array();
|
||||||
|
|
||||||
|
$minkDefinition = $container->getDefinition(self::MINK_ID);
|
||||||
|
|
||||||
|
foreach ($config['sessions'] as $name => $session) {
|
||||||
|
$driver = key($session);
|
||||||
|
$factory = $this->driverFactories[$driver];
|
||||||
|
|
||||||
|
$definition = new Definition('Behat\Mink\Session', array(
|
||||||
|
$factory->buildDriver($session[$driver]),
|
||||||
|
new Reference(self::SELECTORS_HANDLER_ID),
|
||||||
|
));
|
||||||
|
$minkDefinition->addMethodCall('registerSession', array($name, $definition));
|
||||||
|
|
||||||
|
if ($factory->supportsJavascript()) {
|
||||||
|
$javascriptSessions[] = $name;
|
||||||
|
} else {
|
||||||
|
$nonJavascriptSessions[] = $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $javascriptSession && !empty($javascriptSessions)) {
|
||||||
|
$javascriptSession = $javascriptSessions[0];
|
||||||
|
} elseif (null !== $javascriptSession && !in_array($javascriptSession, $javascriptSessions)) {
|
||||||
|
throw new InvalidConfigurationException(sprintf(
|
||||||
|
'The javascript session must be one of the enabled javascript sessions (%s), but got %s',
|
||||||
|
json_encode($javascriptSessions),
|
||||||
|
$javascriptSession
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $defaultSession) {
|
||||||
|
$defaultSession = !empty($nonJavascriptSessions) ? $nonJavascriptSessions[0] : $javascriptSessions[0];
|
||||||
|
} elseif (!isset($config['sessions'][$defaultSession])) {
|
||||||
|
throw new InvalidConfigurationException(sprintf('The default session must be one of the enabled sessions, but got %s', $defaultSession));
|
||||||
|
}
|
||||||
|
|
||||||
|
$container->setParameter('mink.default_session', $defaultSession);
|
||||||
|
$container->setParameter('mink.javascript_session', $javascriptSession);
|
||||||
|
}
|
||||||
|
|
||||||
private function loadSessionsListener(ContainerBuilder $container)
|
private function loadSessionsListener(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new Definition('Behat\MinkExtension\Listener\SessionsListener', array(
|
$definition = new Definition('Behat\MinkExtension\Listener\SessionsListener', array(
|
||||||
new Reference(self::MINK_ID),
|
new Reference(self::MINK_ID),
|
||||||
'%mink.parameters%',
|
'%mink.default_session%',
|
||||||
|
'%mink.javascript_session%',
|
||||||
));
|
));
|
||||||
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, array('priority' => 0));
|
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, array('priority' => 0));
|
||||||
$container->setDefinition('mink.listener.sessions', $definition);
|
$container->setDefinition('mink.listener.sessions', $definition);
|
||||||
@@ -322,173 +278,6 @@ class Extension implements ExtensionInterface
|
|||||||
$container->setDefinition('mink.listener.failure_show', $definition);
|
$container->setDefinition('mink.listener.failure_show', $definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadGoutteSession(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\GoutteDriver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkGoutteDriver in order to activate goutte session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$clientDefinition = new Definition('Behat\Mink\Driver\Goutte\Client', array(
|
|
||||||
$config['server_parameters'],
|
|
||||||
));
|
|
||||||
$clientDefinition->addMethodCall('setClient', array(
|
|
||||||
new Definition('Guzzle\Http\Client', array(
|
|
||||||
null,
|
|
||||||
$config['guzzle_parameters'],
|
|
||||||
)),
|
|
||||||
));
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\GoutteDriver', array(
|
|
||||||
$clientDefinition,
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'goutte');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadSahiSession(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\SahiDriver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkSahiDriver in order to activate sahi session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\SahiDriver', array(
|
|
||||||
'%mink.browser_name%',
|
|
||||||
new Definition('Behat\SahiClient\Client', array(
|
|
||||||
new Definition('Behat\SahiClient\Connection', array(
|
|
||||||
$config['sid'],
|
|
||||||
$config['host'],
|
|
||||||
$config['port'],
|
|
||||||
$config['browser'],
|
|
||||||
$config['limit'],
|
|
||||||
)),
|
|
||||||
)),
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'sahi');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadZombieSession(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\ZombieDriver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkZombieDriver in order to activate zombie session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\ZombieDriver', array(
|
|
||||||
new Definition('Behat\Mink\Driver\NodeJS\Server\ZombieServer', array(
|
|
||||||
$config['host'],
|
|
||||||
$config['port'],
|
|
||||||
$config['node_bin'],
|
|
||||||
$config['server_path'],
|
|
||||||
$config['threshold'],
|
|
||||||
$config['node_modules_path'],
|
|
||||||
)),
|
|
||||||
new Definition('Behat\Mink\Driver\NodeJS\Connection', array(
|
|
||||||
$config['host'],
|
|
||||||
$config['port'],
|
|
||||||
)),
|
|
||||||
$config['auto_server'],
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'zombie');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadSeleniumSession(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\SeleniumDriver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkSeleniumDriver in order to activate selenium session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\SeleniumDriver', array(
|
|
||||||
$config['browser'],
|
|
||||||
'%mink.base_url%',
|
|
||||||
new Definition('Selenium\Client', array(
|
|
||||||
$config['host'],
|
|
||||||
$config['port'],
|
|
||||||
)),
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'selenium');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadSelenium2Session(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkSelenium2Driver in order to activate selenium2 session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
|
||||||
$config['browser'],
|
|
||||||
$config['capabilities'],
|
|
||||||
$config['wd_host'],
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'selenium2');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadSaucelabsSession(ContainerBuilder $container, array $config)
|
|
||||||
{
|
|
||||||
if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
|
|
||||||
throw new \RuntimeException(
|
|
||||||
'Install MinkSelenium2Driver in order to activate saucelabs session.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$capabilities = $config['capabilities'];
|
|
||||||
$capabilities['tags'] = array(php_uname('n'), 'PHP '.phpversion());
|
|
||||||
|
|
||||||
if (getenv('TRAVIS_JOB_NUMBER')) {
|
|
||||||
$capabilities['tunnel-identifier'] = getenv('TRAVIS_JOB_NUMBER');
|
|
||||||
$capabilities['build'] = getenv('TRAVIS_BUILD_NUMBER');
|
|
||||||
$capabilities['tags'] = array('Travis-CI', 'PHP '.phpversion());
|
|
||||||
}
|
|
||||||
|
|
||||||
$host = 'ondemand.saucelabs.com';
|
|
||||||
if ($config['connect']) {
|
|
||||||
$host = 'localhost:4445';
|
|
||||||
}
|
|
||||||
|
|
||||||
$driverDefinition = new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
|
||||||
$config['browser'],
|
|
||||||
$capabilities,
|
|
||||||
sprintf('%s:%s@%s/wd/hub', $config['username'], $config['access_key'], $host),
|
|
||||||
));
|
|
||||||
$this->loadSession($container, $driverDefinition, 'saucelabs');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadSession(ContainerBuilder $container, Definition $driverDefinition, $alias)
|
|
||||||
{
|
|
||||||
$definition = new Definition('Behat\Mink\Session', array(
|
|
||||||
$driverDefinition,
|
|
||||||
new Reference(self::SELECTORS_HANDLER_ID),
|
|
||||||
));
|
|
||||||
$definition->addTag(self::SESSION_TAG, array('alias' => $alias));
|
|
||||||
$container->setDefinition(self::SESSION_TAG . '.' . $alias, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processSessions(ContainerBuilder $container)
|
|
||||||
{
|
|
||||||
$handlerDefinition = $container->getDefinition(self::MINK_ID);
|
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds(self::SESSION_TAG) as $id => $tags) {
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
if (!isset($tag['alias'])) {
|
|
||||||
throw new ProcessingException(sprintf(
|
|
||||||
'All `%s` tags should have an `alias` attribute, but `%s` service has none.',
|
|
||||||
$tag,
|
|
||||||
$id
|
|
||||||
));
|
|
||||||
}
|
|
||||||
$handlerDefinition->addMethodCall(
|
|
||||||
'registerSession', array($tag['alias'], new Reference($id))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processSelectors(ContainerBuilder $container)
|
private function processSelectors(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$handlerDefinition = $container->getDefinition(self::SELECTORS_HANDLER_ID);
|
$handlerDefinition = $container->getDefinition(self::SELECTORS_HANDLER_ID);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Behat\Behat\Tester\Event\AbstractScenarioTested;
|
|||||||
use Behat\Behat\Tester\Event\ExampleTested;
|
use Behat\Behat\Tester\Event\ExampleTested;
|
||||||
use Behat\Behat\Tester\Event\ScenarioTested;
|
use Behat\Behat\Tester\Event\ScenarioTested;
|
||||||
use Behat\Mink\Mink;
|
use Behat\Mink\Mink;
|
||||||
|
use Behat\Testwork\ServiceContainer\Exception\ProcessingException;
|
||||||
use Behat\Testwork\Tester\Event\ExerciseCompleted;
|
use Behat\Testwork\Tester\Event\ExerciseCompleted;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
@@ -26,18 +27,21 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|||||||
class SessionsListener implements EventSubscriberInterface
|
class SessionsListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
private $mink;
|
private $mink;
|
||||||
private $parameters;
|
private $defaultSession;
|
||||||
|
private $javascriptSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes initializer.
|
* Initializes initializer.
|
||||||
*
|
*
|
||||||
* @param Mink $mink
|
* @param Mink $mink
|
||||||
* @param array $parameters
|
* @param string $defaultSession
|
||||||
|
* @param string|null $javascriptSession
|
||||||
*/
|
*/
|
||||||
public function __construct(Mink $mink, array $parameters)
|
public function __construct(Mink $mink, $defaultSession, $javascriptSession)
|
||||||
{
|
{
|
||||||
$this->mink = $mink;
|
$this->mink = $mink;
|
||||||
$this->parameters = $parameters;
|
$this->defaultSession = $defaultSession;
|
||||||
|
$this->javascriptSession = $javascriptSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,16 +68,22 @@ class SessionsListener implements EventSubscriberInterface
|
|||||||
* instead of just soft-resetting them
|
* instead of just soft-resetting them
|
||||||
*
|
*
|
||||||
* @param AbstractScenarioTested $event
|
* @param AbstractScenarioTested $event
|
||||||
|
*
|
||||||
|
* @throws ProcessingException when the @javascript tag is used without a javascript session
|
||||||
*/
|
*/
|
||||||
public function prepareDefaultMinkSession(AbstractScenarioTested $event)
|
public function prepareDefaultMinkSession(AbstractScenarioTested $event)
|
||||||
{
|
{
|
||||||
$scenario = $event->getScenario();
|
$scenario = $event->getScenario();
|
||||||
$feature = $event->getFeature();
|
$feature = $event->getFeature();
|
||||||
$session = $this->parameters['default_session'];
|
$session = $this->defaultSession;
|
||||||
|
|
||||||
foreach (array_merge($feature->getTags(), $scenario->getTags()) as $tag) {
|
foreach (array_merge($feature->getTags(), $scenario->getTags()) as $tag) {
|
||||||
if ('javascript' === $tag) {
|
if ('javascript' === $tag) {
|
||||||
$session = $this->parameters['javascript_session'];
|
if (null === $this->javascriptSession) {
|
||||||
|
throw new ProcessingException('The @javascript tag cannot be used without enabling a javascript session');
|
||||||
|
}
|
||||||
|
|
||||||
|
$session = $this->javascriptSession;
|
||||||
} elseif (preg_match('/^mink\:(.+)/', $tag, $matches)) {
|
} elseif (preg_match('/^mink\:(.+)/', $tag, $matches)) {
|
||||||
$session = $matches[1];
|
$session = $matches[1];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christophe Coevoet <stof@notk.org>
|
||||||
|
*/
|
||||||
|
interface DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets the name of the driver being configured.
|
||||||
|
*
|
||||||
|
* This will be the key of the configuration for the driver.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDriverName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether a session using this driver is eligible as default javascript session
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function supportsJavascript();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setups configuration for the driver factory.
|
||||||
|
*
|
||||||
|
* @param ArrayNodeDefinition $builder
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the service definition for the driver.
|
||||||
|
*
|
||||||
|
* @param array $config
|
||||||
|
*
|
||||||
|
* @return Definition
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config);
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christophe Coevoet <stof@notk.org>
|
||||||
|
*/
|
||||||
|
class GoutteFactory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'goutte';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->arrayNode('server_parameters')
|
||||||
|
->useAttributeAsKey('key')
|
||||||
|
->prototype('variable')->end()
|
||||||
|
->end()
|
||||||
|
->arrayNode('guzzle_parameters')
|
||||||
|
->useAttributeAsKey('key')
|
||||||
|
->prototype('variable')->end()
|
||||||
|
->validate()
|
||||||
|
->always()
|
||||||
|
->then(function ($v) {
|
||||||
|
$v['redirect.disable'] = true;
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
})
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\GoutteDriver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkGoutteDriver in order to use goutte driver.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientDefinition = new Definition('Behat\Mink\Driver\Goutte\Client', array(
|
||||||
|
$config['server_parameters'],
|
||||||
|
));
|
||||||
|
$clientDefinition->addMethodCall('setClient', array(
|
||||||
|
new Definition('Guzzle\Http\Client', array(
|
||||||
|
null,
|
||||||
|
$config['guzzle_parameters'],
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\GoutteDriver', array(
|
||||||
|
$clientDefinition,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
class SahiFactory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'sahi';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->scalarNode('sid')->defaultNull()->end()
|
||||||
|
->scalarNode('host')->defaultValue('localhost')->end()
|
||||||
|
->scalarNode('port')->defaultValue(9999)->end()
|
||||||
|
->scalarNode('browser')->defaultNull()->end()
|
||||||
|
->scalarNode('limit')->defaultValue(600)->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\SahiDriver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkSahiDriver in order to use sahi driver.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\SahiDriver', array(
|
||||||
|
'%mink.browser_name%',
|
||||||
|
new Definition('Behat\SahiClient\Client', array(
|
||||||
|
new Definition('Behat\SahiClient\Connection', array(
|
||||||
|
$config['sid'],
|
||||||
|
$config['host'],
|
||||||
|
$config['port'],
|
||||||
|
$config['browser'],
|
||||||
|
$config['limit'],
|
||||||
|
)),
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
class SaucelabsFactory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'saucelabs';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->scalarNode('username')->defaultValue(getenv('SAUCE_USERNAME'))->end()
|
||||||
|
->scalarNode('access_key')->defaultValue(getenv('SAUCE_ACCESS_KEY'))->end()
|
||||||
|
->booleanNode('connect')->defaultFalse()->end()
|
||||||
|
->scalarNode('browser')->defaultValue('firefox')->end()
|
||||||
|
->arrayNode('capabilities')
|
||||||
|
->addDefaultsIfNotSet()
|
||||||
|
->normalizeKeys(false)
|
||||||
|
->children()
|
||||||
|
->scalarNode('name')->defaultValue('Behat feature suite')->end()
|
||||||
|
->scalarNode('platform')->defaultValue('Linux')->end()
|
||||||
|
->scalarNode('version')->defaultValue('21')->end()
|
||||||
|
->scalarNode('selenium-version')->defaultValue('2.31.0')->end()
|
||||||
|
->scalarNode('max-duration')->defaultValue('300')->end()
|
||||||
|
->scalarNode('deviceType')->defaultNull()->end()
|
||||||
|
->scalarNode('deviceOrientation')->defaultNull()->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkSelenium2Driver in order to use saucelabs driver.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$capabilities = $config['capabilities'];
|
||||||
|
$capabilities['tags'] = array(php_uname('n'), 'PHP '.phpversion());
|
||||||
|
|
||||||
|
if (getenv('TRAVIS_JOB_NUMBER')) {
|
||||||
|
$capabilities['tunnel-identifier'] = getenv('TRAVIS_JOB_NUMBER');
|
||||||
|
$capabilities['build'] = getenv('TRAVIS_BUILD_NUMBER');
|
||||||
|
$capabilities['tags'] = array('Travis-CI', 'PHP '.phpversion());
|
||||||
|
}
|
||||||
|
|
||||||
|
$host = 'ondemand.saucelabs.com';
|
||||||
|
if ($config['connect']) {
|
||||||
|
$host = 'localhost:4445';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
||||||
|
$config['browser'],
|
||||||
|
$capabilities,
|
||||||
|
sprintf('%s:%s@%s/wd/hub', $config['username'], $config['access_key'], $host),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
class Selenium2Factory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'selenium2';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
|
||||||
|
->arrayNode('capabilities')
|
||||||
|
->addDefaultsIfNotSet()
|
||||||
|
->normalizeKeys(false)
|
||||||
|
->children()
|
||||||
|
->scalarNode('browserName')->defaultValue('firefox')->end()
|
||||||
|
->scalarNode('version')->defaultValue('9')->end()
|
||||||
|
->scalarNode('platform')->defaultValue('ANY')->end()
|
||||||
|
->scalarNode('browserVersion')->defaultValue('9')->end()
|
||||||
|
->scalarNode('browser')->defaultValue('firefox')->end()
|
||||||
|
->scalarNode('ignoreZoomSetting')->defaultValue('false')->end()
|
||||||
|
->scalarNode('name')->defaultValue('Behat Test')->end()
|
||||||
|
->scalarNode('deviceOrientation')->defaultValue('portrait')->end()
|
||||||
|
->scalarNode('deviceType')->defaultValue('tablet')->end()
|
||||||
|
->scalarNode('selenium-version')->defaultValue('2.31.0')->end()
|
||||||
|
->scalarNode('max-duration')->defaultValue('300')->end()
|
||||||
|
->booleanNode('javascriptEnabled')->end()
|
||||||
|
->booleanNode('databaseEnabled')->end()
|
||||||
|
->booleanNode('locationContextEnabled')->end()
|
||||||
|
->booleanNode('applicationCacheEnabled')->end()
|
||||||
|
->booleanNode('browserConnectionEnabled')->end()
|
||||||
|
->booleanNode('webStorageEnabled')->end()
|
||||||
|
->booleanNode('rotatable')->end()
|
||||||
|
->booleanNode('acceptSslCerts')->end()
|
||||||
|
->booleanNode('nativeEvents')->end()
|
||||||
|
->booleanNode('passed')->end()
|
||||||
|
->booleanNode('record-video')->end()
|
||||||
|
->booleanNode('record-screenshots')->end()
|
||||||
|
->booleanNode('capture-html')->end()
|
||||||
|
->booleanNode('disable-popup-handler')->end()
|
||||||
|
->arrayNode('proxy')
|
||||||
|
->children()
|
||||||
|
->scalarNode('proxyType')->end()
|
||||||
|
->scalarNode('proxyAuthconfigUrl')->end()
|
||||||
|
->scalarNode('ftpProxy')->end()
|
||||||
|
->scalarNode('httpProxy')->end()
|
||||||
|
->scalarNode('sslProxy')->end()
|
||||||
|
->end()
|
||||||
|
->validate()
|
||||||
|
->ifTrue(function ($v) {
|
||||||
|
return empty($v);
|
||||||
|
})
|
||||||
|
->thenUnset()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->arrayNode('firefox')
|
||||||
|
->children()
|
||||||
|
->scalarNode('profile')
|
||||||
|
->validate()
|
||||||
|
->ifTrue(function ($v) {
|
||||||
|
return !file_exists($v);
|
||||||
|
})
|
||||||
|
->thenInvalid('Cannot find profile zip file %s')
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->scalarNode('binary')->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->arrayNode('chrome')
|
||||||
|
->children()
|
||||||
|
->arrayNode('switches')->prototype('scalar')->end()->end()
|
||||||
|
->scalarNode('binary')->end()
|
||||||
|
->arrayNode('extensions')->prototype('scalar')->end()->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkSelenium2Driver in order to use selenium2 driver.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\Selenium2Driver', array(
|
||||||
|
$config['browser'],
|
||||||
|
$config['capabilities'],
|
||||||
|
$config['wd_host'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
class SeleniumFactory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'selenium';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->scalarNode('host')->defaultValue('127.0.0.1')->end()
|
||||||
|
->scalarNode('port')->defaultValue(4444)->end()
|
||||||
|
->scalarNode('browser')->defaultValue('*%mink.browser_name%')->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\SeleniumDriver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkSeleniumDriver in order to activate selenium session.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\SeleniumDriver', array(
|
||||||
|
$config['browser'],
|
||||||
|
'%mink.base_url%',
|
||||||
|
new Definition('Selenium\Client', array(
|
||||||
|
$config['host'],
|
||||||
|
$config['port'],
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Behat MinkExtension.
|
||||||
|
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Behat\MinkExtension\ServiceContainer\Driver;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
class ZombieFactory implements DriverFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDriverName()
|
||||||
|
{
|
||||||
|
return 'zombie';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function supportsJavascript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure(ArrayNodeDefinition $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->children()
|
||||||
|
->scalarNode('host')->defaultValue('127.0.0.1')->end()
|
||||||
|
->scalarNode('port')->defaultValue(8124)->end()
|
||||||
|
->booleanNode('auto_server')->defaultTrue()->end()
|
||||||
|
->scalarNode('node_bin')->defaultValue('node')->end()
|
||||||
|
->scalarNode('server_path')->defaultNull()->end()
|
||||||
|
->scalarNode('threshold')->defaultValue(2000000)->end()
|
||||||
|
->scalarNode('node_modules_path')->defaultValue('')->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildDriver(array $config)
|
||||||
|
{
|
||||||
|
if (!class_exists('Behat\Mink\Driver\ZombieDriver')) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
'Install MinkZombieDriver in order to use zombie driver.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Definition('Behat\Mink\Driver\ZombieDriver', array(
|
||||||
|
new Definition('Behat\Mink\Driver\NodeJS\Server\ZombieServer', array(
|
||||||
|
$config['host'],
|
||||||
|
$config['port'],
|
||||||
|
$config['node_bin'],
|
||||||
|
$config['server_path'],
|
||||||
|
$config['threshold'],
|
||||||
|
$config['node_modules_path'],
|
||||||
|
)),
|
||||||
|
new Definition('Behat\Mink\Driver\NodeJS\Connection', array(
|
||||||
|
$config['host'],
|
||||||
|
$config['port'],
|
||||||
|
)),
|
||||||
|
$config['auto_server'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user