Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Nov 4, 2011
2 parents d0c2d91 + 5b919f5 commit 904514e
Show file tree
Hide file tree
Showing 40 changed files with 1,384 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -22,3 +22,6 @@
[submodule "vendor/Symfony/Component/DomCrawler"]
path = vendor/Symfony/Component/DomCrawler
url = git://github.com/symfony/DomCrawler.git
[submodule "vendor/php-selenium"]
path = vendor/php-selenium
url = https://github.com/alexandresalome/PHP-Selenium
11 changes: 11 additions & 0 deletions CHANGES.md
@@ -1,3 +1,14 @@
1.2.0 / 2011-11-04
==================

* Brand new SeleniumDriver (thanks @alexandresalome)
* Multiselect support (multiple options selection), including new Behat steps
* Ability to select option by it's text (in addition to value)
* ZombieDriver updates
* Use SuiteHooks to populate parameters (no need to call parent __construct anymore)
* Updated Goutte and all vendors
* Lot of bugfixes and new tests

1.1.1 / 2011-08-12
==================

Expand Down
1 change: 1 addition & 0 deletions autoload.php.dist
Expand Up @@ -21,5 +21,6 @@ $loader->registerNamespaces(array(
'Buzz' => __DIR__ . '/vendor/Buzz/lib',
'Goutte' => __DIR__ . '/vendor/Goutte/src',
'Zend' => __DIR__ . '/vendor/Goutte/vendor/zend/library',
'Selenium' => __DIR__ . '/vendor/php-selenium/src',
));
$loader->register();
5 changes: 3 additions & 2 deletions behat.yml
@@ -1,5 +1,6 @@
default:
context:
parameters:
base_url: http://test.mink.dev/
show_cmd: open %s
javascript_session: selenium
base_url: http://test.mink.dev/
show_cmd: open %s
49 changes: 48 additions & 1 deletion src/Behat/Mink/Behat/Context/BaseMinkContext.php
Expand Up @@ -208,6 +208,18 @@ public function selectOption($select, $option)
$this->getSession()->getPage()->selectFieldOption($select, $option);
}

/**
* Selects additional option in select field with specified id|name|label|value.
*
* @When /^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
*/
public function additionallySelectOption($select, $option)
{
$select = str_replace('\\"', '"', $select);
$option = str_replace('\\"', '"', $option);
$this->getSession()->getPage()->selectFieldOption($select, $option, true);
}

/**
* Checks checkbox with specified id|name|label|value.
*
Expand Down Expand Up @@ -303,6 +315,23 @@ public function assertResponseStatus($code)
}
}

/**
* Checks, that current page response status is not equal to specified.
*
* @Then /^the response status code should not be (?P<code>\d+)$/
*/
public function assertResponseStatusIsNot($code)
{
$actual = $this->getSession()->getStatusCode();

try {
assertNotEquals($actual, $code);
} catch (AssertException $e) {
$message = sprintf('Current response status code is %d, but should not be', $actual);
throw new ExpectationException($message, $this->getSession(), $e);
}
}

/**
* Checks, that page contains specified text.
*
Expand Down Expand Up @@ -552,6 +581,22 @@ public function assertCheckboxNotChecked($checkbox)
}
}

/**
* Checks, that (?P<num>\d+) CSS elements exist on the page
*
* @Then /^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/
*/
public function assertNumElements($num, $element)
{
$nodes = $world->getSession()->getPage()->findAll('css', $element);

if (null === $nodes) {
throw new ElementNotFoundException($world->getSession(), 'element: '.$element.' ');
}

assertSame((int) $num, count($nodes));
}

/**
* Prints last response to console.
*
Expand All @@ -578,7 +623,7 @@ public function showLastResponse()

$filename = rtrim($this->getParameter('show_tmp_dir'), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.uniqid().'.html';
file_put_contents($filename, $this->getSession()->getPage()->getContent());
system(sprintf($this->getParameter('show_cmd'), $filename));
system(sprintf($this->getParameter('show_cmd'), escapeshellarg($filename)));
}

/**
Expand All @@ -595,6 +640,8 @@ public function getTranslationResources()
__DIR__ . '/translations/es.xliff',
__DIR__ . '/translations/nl.xliff',
__DIR__ . '/translations/pt.xliff',
__DIR__ . '/translations/sv.xliff',
__DIR__ . '/translations/de.xliff',
);
}
}
58 changes: 38 additions & 20 deletions src/Behat/Mink/Behat/Context/MinkContext.php
Expand Up @@ -8,7 +8,8 @@
Behat\Mink\Session,
Behat\Mink\Driver\GoutteDriver,
Behat\Mink\Driver\SahiDriver,
Behat\Mink\Driver\ZombieDriver;
Behat\Mink\Driver\ZombieDriver,
Behat\Mink\Driver\SeleniumDriver;

use Goutte\Client as GoutteClient;

Expand All @@ -18,6 +19,8 @@
use Behat\Mink\Driver\Zombie\Connection as ZombieConnection,
Behat\Mink\Driver\Zombie\Server as ZombieServer;

use Selenium\Client as SeleniumClient;

/*
* This file is part of the Behat\Mink.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
Expand All @@ -34,19 +37,7 @@
class MinkContext extends BaseMinkContext
{
private static $mink;
private $parameters;

/**
* Initializes Mink environment.
*
* @param array $parameters list of context parameters
*/
public function __construct(array $parameters = array())
{
$this->parameters = static::mergeConfigWithDefaults(
static::getDefaultParameters(), $parameters
);
}
private static $parameters;

/**
* {@inheritdoc}
Expand All @@ -67,19 +58,19 @@ public function getMink()
*/
public function getParameters()
{
return $this->parameters;
return self::$parameters;
}

/**
* {@inheritdoc}
*/
public function getParameter($name)
{
if (!isset($this->parameters[$name])) {
if (!isset(self::$parameters[$name])) {
return;
}

return $this->parameters[$name];
return self::$parameters[$name];
}

/**
Expand All @@ -91,15 +82,15 @@ public function getParameter($name)
*/
public static function initMinkSessions(SuiteEvent $event)
{
$parameters = static::mergeConfigWithDefaults(
self::$parameters = static::mergeConfigWithDefaults(
static::getDefaultParameters(), $event->getContextParameters()
);

if (null === self::$mink) {
self::$mink = new Mink();
}

static::registerMinkSessions(self::$mink, $parameters);
static::registerMinkSessions(self::$mink, self::$parameters);
}

/**
Expand Down Expand Up @@ -140,6 +131,13 @@ protected static function registerMinkSessions(Mink $mink, array $parameters)
$params['host'], $params['port'], $params['auto_server'], $params['node_bin']
));
}

if (!$mink->hasSession('selenium')) {
$params = $parameters['selenium'];
$mink->registerSession('selenium', static::initSeleniumSession(
$parameters['browser'], $parameters['base_url'], $params['host'], $params['port']
));
}
}

/**
Expand All @@ -152,6 +150,8 @@ protected static function registerMinkSessions(Mink $mink, array $parameters)
*/
protected static function initGoutteSession(array $zendConfig = array(), array $serverParameters = array())
{
$zendConfig = array_merge(array('encodecookies' => false), $zendConfig);

return new Session(new GoutteDriver(new GoutteClient($zendConfig, $serverParameters)));
}

Expand Down Expand Up @@ -189,6 +189,20 @@ protected static function initZombieSession($host = '127.0.0.1', $port = 8124,
return new Session(new ZombieDriver($connection, $server, $autoServer));
}

/**
* Initizalizes and returns new SeleniumDriver session.
*
* @param string $browser browser name to use (default = firefox)
* @param string $host sahi proxy host
* @param integer $port port number
*
* @return Behat\Mink\Session
*/
protected static function initSeleniumSession($browser, $baseUrl, $host, $port)
{
return new Session(new SeleniumDriver($browser, $baseUrl, new SeleniumClient($host, $port)));
}

/**
* Returns list of default parameters.
*
Expand Down Expand Up @@ -217,7 +231,11 @@ protected static function getDefaultParameters()
'port' => 8124,
'node_bin' => 'node',
'auto_server' => true
)
),
'selenium' => array(
'host' => 'localhost',
'port' => 4444
),
);
}

Expand Down
131 changes: 131 additions & 0 deletions src/Behat/Mink/Behat/Context/translations/de.xliff
@@ -0,0 +1,131 @@
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="global" source-language="en" target-language="de" datatype="plaintext">
<header />
<body>
<trans-unit id="i-am-on-page">
<source><![CDATA[/^(?:|I )am on "(?P<page>[^"]+)"$/]]></source>
<target><![CDATA[/^(?:|ich )bin auf "(?P<page>[^"]+)"$/]]></target>
</trans-unit>
<trans-unit id="i-go-to-page">
<source><![CDATA[/^(?:|I )go to "(?P<page>[^"]+)"$/]]></source>
<target><![CDATA[/^(?:|ich )gehe nach "(?P<page>[^"]+)"$/]]></target>
</trans-unit>
<trans-unit id="reload-the-page">
<source><![CDATA[/^(?:|I )reload the page$/]]></source>
<target><![CDATA[/^(?:|ich )aktualisiere die Seite$/]]></target>
</trans-unit>
<trans-unit id="move-backward-one-page">
<source><![CDATA[/^(?:|I )move backward one page$/]]></source>
<target><![CDATA[/^(?:|ich )gehe eine Seite zurück$/]]></target>
</trans-unit>
<trans-unit id="move-forward-one-page">
<source><![CDATA[/^(?:|I )move forward one page$/]]></source>
<target><![CDATA[/^(?:|ich )gehe eine Seite vorwärts$/]]></target>
</trans-unit>
<trans-unit id="i-press-button">
<source><![CDATA[/^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )drücke "(?P<button>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-follow-link">
<source><![CDATA[/^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )folge "(?P<link>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-fill-in-field-with-value">
<source><![CDATA[/^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )gebe in das Feld "(?P<field>(?:[^"]|\\")*)" "(?P<value>(?:[^"]|\\")*)" ein$/]]></target>
</trans-unit>
<trans-unit id="i-fill-in-value-for-field">
<source><![CDATA[/^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )gebe "(?P<value>(?:[^"]|\\")*)" in "(?P<field>(?:[^"]|\\")*)"ein$/]]></target>
</trans-unit>
<trans-unit id="i-fill-in-the-following">
<source><![CDATA[/^(?:|I )fill in the following:$/]]></source>
<target><![CDATA[/^(?:|ich )gebe das folgende ein:$/]]></target>
</trans-unit>
<trans-unit id="i-select-option-from-select">
<source><![CDATA[/^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )wähle "(?P<option>(?:[^"]|\\")*)" von "(?P<select>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-check-option">
<source><![CDATA[/^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )aktiviere "(?P<option>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-uncheck-option">
<source><![CDATA[/^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )deaktiviere "(?P<option>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-attach-the-file-to-field">
<source><![CDATA[/^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )lade die Datei "(?P<path>[^"]*)" in "(?P<field>(?:[^"]|\\")*)"$/]]></target>
</trans-unit>
<trans-unit id="i-should-see-text">
<source><![CDATA[/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )sollte "(?P<text>(?:[^"]|\\")*)" sehen$/]]></target>
</trans-unit>
<trans-unit id="the-response-should-contain">
<source><![CDATA[/^the response should contain "(?P<text>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^die Rückmeldung sollte "(?P<text>(?:[^"]|\\")*)" enthalten$/]]></target>
</trans-unit>
<trans-unit id="i-should-not-see-text">
<source><![CDATA[/^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^(?:|ich )sollte nicht "(?P<text>(?:[^"]|\\")*)" sehen$/]]></target>
</trans-unit>
<trans-unit id="the-response-should-not-contain">
<source><![CDATA[/^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^die Rückmeldung sollte nicht "(?P<text>(?:[^"]|\\")*)" enthalten$/]]></target>
</trans-unit>
<trans-unit id="the-field-should-contain-value">
<source><![CDATA[/^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^das "(?P<field>(?:[^"]|\\")*)" Feld sollte "(?P<value>(?:[^"]|\\")*)" enthalten$/]]></target>
</trans-unit>
<trans-unit id="the-field-should-not-contain-value">
<source><![CDATA[/^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^das "(?P<field>(?:[^"]|\\")*)" Feld sollte nicht "(?P<value>(?:[^"]|\\")*)" enthalten$/]]></target>
</trans-unit>
<trans-unit id="the-checkbox-should-be-checked">
<source><![CDATA[/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/]]></source>
<target><![CDATA[/^die "(?P<checkbox>(?:[^"]|\\")*)" checkbox sollte aktiviert sein$/]]></target>
</trans-unit>
<trans-unit id="the-checkbox-should-not-be-checked">
<source><![CDATA[/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should not be checked$/]]></source>
<target><![CDATA[/^die "(?P<checkbox>(?:[^"]|\\")*)" checkbox sollte nicht aktiviert sein$/]]></target>
</trans-unit>
<trans-unit id="i-should-be-on-page">
<source><![CDATA[/^(?:|I )should be on "(?P<page>[^"]+)"$/]]></source>
<target><![CDATA[/^(?:|ich )sollte auf "(?P<page>[^"]+) sein"$/]]></target>
</trans-unit>
<trans-unit id="the-url-should-match">
<source><![CDATA[/^the url should match "(?P<pattern>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^die Webadresse sollte mit "(?P<pattern>(?:[^"]|\\")*)" übereinstimmen$/]]></target>
</trans-unit>
<trans-unit id="the-element-should-contain">
<source><![CDATA[/^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/]]></source>
<target><![CDATA[/^das "(?P<element>[^"]*)" Element sollte "(?P<value>(?:[^"]|\\")*)" enthalten$/]]></target>
</trans-unit>
<trans-unit id="i-should-see-text-in-element">
<source><![CDATA[/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/]]></source>
<target><![CDATA[/^(?:|ich )sollte "(?P<text>(?:[^"]|\\")*)" im "(?P<element>[^"]*)" Element sehen$/]]></target>
</trans-unit>
<trans-unit id="i-should-see-element">
<source><![CDATA[/^(?:|I )should see an? "(?P<element>[^"]*)" element$/]]></source>
<target><![CDATA[/^(?:|ich )sollte ein "(?P<element>[^"]*)" Element sehen$/]]></target>
</trans-unit>
<trans-unit id="i-should-not-see-element">
<source><![CDATA[/^(?:|I )should not see an? "(?P<element>[^"]*)" element$/]]></source>
<target><![CDATA[/^(?:|ich )sollte kein "(?P<element>[^"]*)" Element sehen$/]]></target>
</trans-unit>
<trans-unit id="the-response-status-code-should-be">
<source><![CDATA[/^the response status code should be (?P<code>\d+)$/]]></source>
<target><![CDATA[/^die Status-Code-Rückmeldung sollte (?P<code>\d+) sein$/]]></target>
</trans-unit>
<trans-unit id="print-last-response">
<source><![CDATA[/^print last response$/]]></source>
<target><![CDATA[/^gib die letzte Rückmeldung aus$/]]></target>
</trans-unit>
<trans-unit id="show-last-response">
<source><![CDATA[/^show last response$/]]></source>
<target><![CDATA[/^zeige die letzte Rückmeldung$/]]></target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 904514e

Please sign in to comment.