Skip to content
Browse files

Merge branch 'release/1.4.1'

  • Loading branch information...
2 parents 71a9705 + 820015e commit c76a5e0f1f92c627445ae17d7bb6bce4c2a3dd6e @everzet everzet committed Feb 10, 2013
View
10 .travis.yml
@@ -4,13 +4,19 @@ php:
- 5.3
- 5.4
+env:
+ - SYMFONY_VERSION='2.0.*'
+ - SYMFONY_VERSION='2.1.*'
+ - SYMFONY_VERSION='2.2.*@dev'
+
branches:
only:
- master
- develop
before_script:
- curl http://getcomposer.org/installer | php
- - php composer.phar install
+ - php composer.phar require --no-update symfony/symfony=$SYMFONY_VERSION
+ - php composer.phar install --dev --prefer-source
-script: phpunit
+script: phpunit -v
View
11 CHANGES.md
@@ -1,3 +1,14 @@
+1.4.1 / 2013-02-10
+==================
+
+ * Update dependencies
+ * Add ElementException to element actions
+ * Rel attribute support for named selectors
+ * Add hasClass() helper to traversable elements
+ * Add getScreenshot() method to session
+ * Name attr support in named selector for button
+ * Fix for bunch of bugs
+
1.4.0 / 2012-05-40
==================
View
26 bin/release
@@ -17,12 +17,8 @@
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
use Behat\Mink\Compiler;
-system('rm *.phar *.tgz');
-
if (!isset($argv[1])) {
throw new RuntimeException('You must provide version.');
}
@@ -33,20 +29,24 @@ if (!isset($argv[2])) {
}
$stability = $argv[2];
-$ldr = new Compiler\MapFileCompiler($autoloaderFilename = 'autoload.php', $mapFilename = 'autoload_map.php');
-$ldr->compile();
-echo "Autoloader compiled\n";
+system('rm -rf vendor composer.lock');
+system('cp composer.json composer.json.back');
+system('composer require --no-update "behat/mink-goutte-driver=@dev"');
+system('composer require --no-update "behat/mink-sahi-driver=@dev"');
+system('composer require --no-update "behat/mink-selenium-driver=@dev"');
+system('composer require --no-update "behat/mink-selenium2-driver=@dev"');
+system('composer require --no-update "behat/mink-zombie-driver=@dev"');
+system('composer install --prefer-dist');
-$pear = new Compiler\PearCompiler();
-$pear->compile($version, $stability);
-echo "PEAR package compiled: mink-$version.tgz\n";
+require_once __DIR__ . '/../vendor/autoload.php';
+system('rm *.phar');
$phar = new Compiler\PharCompiler();
$phar->compile($version);
system("cp mink-$version.phar mink.phar");
echo "PHAR package compiled: mink-$version.phar\n";
-unlink($autoloaderFilename);
-unlink($mapFilename);
-
+system('mv composer.json.back composer.json');
+system('rm -rf vendor composer.lock');
+system('composer install --dev --prefer-dist');
exit(0);
View
17 composer.json
@@ -16,16 +16,7 @@
"require": {
"php": ">=5.3.1",
- "symfony/css-selector": ">=2.0.0,<2.2.0-dev"
- },
-
- "require-dev": {
- "behat/mink-goutte-driver": "*",
- "behat/mink-sahi-driver": "*",
- "behat/mink-selenium-driver": "*",
- "behat/mink-selenium2-driver": "*",
- "behat/mink-zombie-driver": "*",
- "symfony/finder": ">=2.0.0,<2.2.0-dev"
+ "symfony/css-selector": ">=2.0,<2.3-dev"
},
"suggest": {
@@ -40,5 +31,11 @@
"psr-0": {
"Behat\\Mink": "src/"
}
+ },
+
+ "extra": {
+ "branch-alias": {
+ "dev-develop": "1.4-dev"
+ }
}
}
View
2 phpunit.xml.dist
@@ -2,7 +2,7 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
- colors="false"
+ colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
View
2 src/Behat/Mink/ClassLoader/MapFileClassLoader.php
@@ -73,4 +73,4 @@ public function findFile($class)
return $this->map[$class];
}
}
-}
+}
View
121 src/Behat/Mink/Compiler/MapFileCompiler.php
@@ -1,121 +0,0 @@
-<?php
-
-namespace Behat\Mink\Compiler;
-
-use Symfony\Component\Finder\Finder;
-
-/*
- * This file is part of the Behat\Mink.
- * (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.
- */
-
-/**
- * Class loader map file compiler.
- *
- * @author Konstantin Kudryashov <ever.zet@gmail.com>
- */
-class MapFileCompiler
-{
- /**
- * Behat lib directory.
- *
- * @var string
- */
- private $libPath;
-
- /**
- * Initializes compiler.
- */
- public function __construct()
- {
- $this->libPath = realpath(__DIR__ . '/../../../../');
- }
-
- /**
- * Compiles map file and autoloader.
- *
- * @param string $version
- */
- public function compile($autoloaderFilename = 'autoload.php', $mapFilename = 'autoload_map.php')
- {
- if (file_exists($mapFilename)) {
- unlink($mapFilename);
- }
- $mappings = '';
-
- // autoload Symfony2
- $mappings .= "\nif (!defined('BEHAT_AUTOLOAD_SF2') || true === BEHAT_AUTOLOAD_SF2) {\n";
- foreach ($this->findPhpFile()->in($this->libPath . '/vendor/symfony') as $file) {
- $path = str_replace(array(
- $this->libPath . '/vendor/symfony/browser-kit/',
- $this->libPath . '/vendor/symfony/css-selector/',
- $this->libPath . '/vendor/symfony/dom-crawler/',
- $this->libPath . '/vendor/symfony/process/',
- ), '', $file->getRealPath());
- $class = str_replace(array('/', '.php'), array('\\', ''), $path);
- $mappings .= " \$mappings['$class'] = '$path';\n";
- }
- $mappings .= "}\n";
-
- $mapContent = <<<MAP_FILE
-<?php
-
-\$mappings = array();
-$mappings
-return \$mappings;
-MAP_FILE;
-
- file_put_contents($mapFilename, $mapContent);
- file_put_contents($autoloaderFilename, $this->getAutoloadScript($mapFilename));
- }
-
- /**
- * Returns autoload.php content.
- *
- * @param string $mapFilename
- *
- * @return string
- */
- protected function getAutoloadScript($mapFilename)
- {
- return sprintf(<<<'EOF'
-<?php
-
-/*
- * This file is part of the Behat\Mink.
- * (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.
- */
-
-if (!class_exists('Behat\Mink\ClassLoader\MapFileClassLoader')) {
- require_once __DIR__ . '/src/Behat/Mink/ClassLoader/MapFileClassLoader.php';
-}
-
-use Behat\Mink\ClassLoader\MapFileClassLoader;
-
-$loader = new MapFileClassLoader(__DIR__ . '/%s');
-$loader->register();
-
-require_once __DIR__ . '/vendor/autoload.php';
-
-EOF
- , $mapFilename);
- }
-
- /**
- * Creates finder instance to search php files.
- *
- * @return Symfony\Component\Finder\Finder
- */
- private function findPhpFile()
- {
- $finder = new Finder();
-
- return $finder->files()->ignoreVCS(true)->name('*.php');
- }
-}
View
227 src/Behat/Mink/Compiler/PearCompiler.php
@@ -1,227 +0,0 @@
-<?php
-
-namespace Behat\Mink\Compiler;
-
-use Symfony\Component\Finder\Finder;
-
-/*
- * This file is part of the Behat\Mink.
- * (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.
- */
-
-/**
- * Pear package compiler.
- *
- * @author Konstantin Kudryashov <ever.zet@gmail.com>
- */
-class PearCompiler
-{
- /**
- * Behat lib directory.
- *
- * @var string
- */
- private $libPath;
-
- /**
- * Initializes compiler.
- */
- public function __construct()
- {
- $this->libPath = realpath(__DIR__ . '/../../../../');
- }
-
- /**
- * Compiles pear package.
- *
- * @param string $version
- */
- public function compile($version, $stability)
- {
- if (file_exists('package.xml')) {
- unlink('package.xml');
- }
- file_put_contents('package.xml', $this->getPackageTemplate());
-
- $finder = new Finder();
- $finder->files()
- ->ignoreVCS(true)
- ->name('*.php')
- ->name('*.xliff')
- ->name('*.xml')
- ->name('*.js')
- ->name('*.feature')
- ->name('LICENSE')
- ->name('LICENSE.txt')
- ->notName('test')
- ->notName('tests')
- ->exclude(array(
- 'Compiler',
- 'finder',
- 'test',
- 'tests',
- 'vendor',
- ))
- ->in($this->libPath . '/src')
- ->in($this->libPath . '/vendor/composer')
- ->in($this->libPath . '/vendor/alexandresalome')
- ->in($this->libPath . '/vendor/behat')
- ->in($this->libPath . '/vendor/fabpot')
- ->in($this->libPath . '/vendor/kriswallsmith')
- ->in($this->libPath . '/vendor/guzzle')
- ->in($this->libPath . '/vendor/instaclick')
- ;
-
- $xmlSourceFiles = '';
- foreach ($finder as $file) {
- if (!$file instanceof \SplFileInfo) {
- $file = new \SplFileInfo($file);
- }
-
- $path = str_replace($this->libPath . '/', '', $file->getRealPath());
- $xmlSourceFiles .=
- '<file role="php" baseinstalldir="mink" install-as="'.$path.'" name="'.$path.'" />'."\n";
- }
-
- $this->replaceTokens('package.xml', '##', '##', array(
- 'MINK_VERSION' => $version,
- 'CURRENT_DATE' => date('Y-m-d'),
- 'SOURCE_FILES' => $xmlSourceFiles,
- 'STABILITY' => $stability
- ));
-
- system('pear package');
- unlink('package.xml');
- }
-
- /**
- * Replaces tokens in specified path.
- *
- * @param string|array $files files array or single file
- * @param string $tokenStart token start symbol
- * @param string $tokenFinish token finish symbol
- * @param array $tokens replace tokens array
- */
- protected function replaceTokens($files, $tokenStart, $tokenFinish, array $tokens)
- {
- if (!is_array($files)) {
- $files = array($files);
- }
-
- foreach ($files as $file) {
- $content = file_get_contents($file);
- foreach ($tokens as $key => $value) {
- $content = str_replace($tokenStart . $key . $tokenFinish, $value, $content, $count);
- }
- file_put_contents($file, $content);
- }
- }
-
- /**
- * Returns pear package template.
- *
- * @return string
- */
- protected function getPackageTemplate()
- {
- return <<<'EOF'
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.8.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
- http://pear.php.net/dtd/tasks-1.0.xsd
- http://pear.php.net/dtd/package-2.0
- http://pear.php.net/dtd/package-2.0.xsd">
- <name>mink</name>
- <channel>pear.behat.org</channel>
- <summary>Behat\Mink is an browser emulation framework for PHP</summary>
- <description>
- Behat\Mink is an open source browser emulation framework for php 5.3.
- </description>
- <lead>
- <name>Konstantin Kudryashov</name>
- <user>everzet</user>
- <email>ever.zet@gmail.com</email>
- <active>yes</active>
- </lead>
- <date>##CURRENT_DATE##</date>
- <version>
- <release>##MINK_VERSION##</release>
- <api>1.0.0</api>
- </version>
- <stability>
- <release>##STABILITY##</release>
- <api>##STABILITY##</api>
- </stability>
- <license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
- <notes>-</notes>
- <contents>
- <dir name="/">
- ##SOURCE_FILES##
-
- <file role="php" baseinstalldir="mink" name="autoload.php" />
- <file role="php" baseinstalldir="mink" name="autoload_map.php" />
- <file role="php" baseinstalldir="mink" name="CHANGES.md" />
- <file role="php" baseinstalldir="mink" name="LICENSE" />
- <file role="php" baseinstalldir="mink" name="README.md" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>5.3.1</min>
- </php>
- <pearinstaller>
- <min>1.4.0</min>
- </pearinstaller>
- <package>
- <name>BrowserKit</name>
- <channel>pear.symfony.com</channel>
- </package>
- <package>
- <name>CssSelector</name>
- <channel>pear.symfony.com</channel>
- </package>
- <package>
- <name>DomCrawler</name>
- <channel>pear.symfony.com</channel>
- </package>
- <package>
- <name>Process</name>
- <channel>pear.symfony.com</channel>
- </package>
- <extension>
- <name>pcre</name>
- </extension>
- <extension>
- <name>simplexml</name>
- </extension>
- <extension>
- <name>xml</name>
- </extension>
- </required>
- <optional>
- <package>
- <name>PHPUnit</name>
- <channel>pear.phpunit.de</channel>
- </package>
- </optional>
- </dependencies>
- <phprelease />
-</package>
-EOF;
- }
-
- /**
- * Creates finder instance to search php files.
- *
- * @return Symfony\Component\Finder\Finder
- */
- private function findPhpFile()
- {
- $finder = new Finder();
-
- return $finder->files()->ignoreVCS(true)->name('*.php');
- }
-}
View
11 src/Behat/Mink/Compiler/PharCompiler.php
@@ -37,7 +37,7 @@ public function __construct()
/**
* Compiles phar archive.
*
- * @param string $version
+ * @param string $version
*/
public function compile($version)
{
@@ -87,6 +87,7 @@ public function compile($version)
$this->addFileToPhar($file, $phar);
}
+ $this->addFileToPhar(new \SplFileInfo('vendor/autoload.php'), $phar);
// stub
$phar->setStub($this->getStub($version));
@@ -98,8 +99,8 @@ public function compile($version)
/**
* Adds a file to phar archive.
*
- * @param SplFileInfo $file file info
- * @param Phar $phar phar packager
+ * @param SplFileInfo $file file info
+ * @param Phar $phar phar packager
*/
protected function addFileToPhar(\SplFileInfo $file, \Phar $phar)
{
@@ -110,9 +111,9 @@ protected function addFileToPhar(\SplFileInfo $file, \Phar $phar)
/**
* Returns autoloader stub.
*
- * @param string $version
+ * @param string $version
*
- * @return string
+ * @return string
*/
protected function getStub($version)
{
View
107 src/Behat/Mink/Driver/DriverInterface.php
@@ -24,103 +24,103 @@
*
* @param Session $session
*/
- function setSession(Session $session);
+ public function setSession(Session $session);
/**
* Starts driver.
*/
- function start();
+ public function start();
/**
* Checks whether driver is started.
*
* @return Boolean
*/
- function isStarted();
+ public function isStarted();
/**
* Stops driver.
*/
- function stop();
+ public function stop();
/**
* Resets driver.
*/
- function reset();
+ public function reset();
/**
* Visit specified URL.
*
* @param string $url url of the page
*/
- function visit($url);
+ public function visit($url);
/**
* Returns current URL address.
*
* @return string
*/
- function getCurrentUrl();
+ public function getCurrentUrl();
/**
* Reloads current page.
*/
- function reload();
+ public function reload();
/**
* Moves browser forward 1 page.
*/
- function forward();
+ public function forward();
/**
* Moves browser backward 1 page.
*/
- function back();
+ public function back();
/**
* Sets HTTP Basic authentication parameters
*
* @param string|Boolean $user user name or false to disable authentication
* @param string $password password
*/
- function setBasicAuth($user, $password);
+ public function setBasicAuth($user, $password);
/**
* Switches to specific browser window.
*
* @param string $name window name (null for switching back to main window)
*/
- function switchToWindow($name = null);
+ public function switchToWindow($name = null);
/**
* Switches to specific iFrame.
*
* @param string $name iframe name (null for switching back)
*/
- function switchToIFrame($name = null);
+ public function switchToIFrame($name = null);
/**
* Sets specific request header on client.
*
* @param string $name
* @param string $value
*/
- function setRequestHeader($name, $value);
+ public function setRequestHeader($name, $value);
/**
* Returns last response headers.
*
* @return array
*/
- function getResponseHeaders();
+ public function getResponseHeaders();
/**
* Sets cookie.
*
* @param string $name
* @param string $value
*/
- function setCookie($name, $value = null);
+ public function setCookie($name, $value = null);
/**
* Returns cookie by name.
@@ -129,21 +129,29 @@ function setCookie($name, $value = null);
*
* @return string|null
*/
- function getCookie($name);
+ public function getCookie($name);
/**
* Returns last response status code.
*
* @return integer
*/
- function getStatusCode();
+ public function getStatusCode();
/**
* Returns last response content.
*
* @return string
*/
- function getContent();
+ public function getContent();
+
+ /**
+ * Capture a screenshot of the current window.
+ *
+ * @return string screenshot of MIME type image/* depending
+ * on driver (e.g., image/png, image/jpeg)
+ */
+ public function getScreenshot();
/**
* Finds elements with specified XPath query.
@@ -152,7 +160,7 @@ function getContent();
*
* @return array array of NodeElements
*/
- function find($xpath);
+ public function find($xpath);
/**
* Returns element's tag name by it's XPath query.
@@ -161,7 +169,7 @@ function find($xpath);
*
* @return string
*/
- function getTagName($xpath);
+ public function getTagName($xpath);
/**
* Returns element's text by it's XPath query.
@@ -170,7 +178,7 @@ function getTagName($xpath);
*
* @return string
*/
- function getText($xpath);
+ public function getText($xpath);
/**
* Returns element's html by it's XPath query.
@@ -179,7 +187,7 @@ function getText($xpath);
*
* @return string
*/
- function getHtml($xpath);
+ public function getHtml($xpath);
/**
* Returns element's attribute by it's XPath query.
@@ -189,7 +197,7 @@ function getHtml($xpath);
*
* @return mixed
*/
- function getAttribute($xpath, $name);
+ public function getAttribute($xpath, $name);
/**
* Returns element's value by it's XPath query.
@@ -198,29 +206,29 @@ function getAttribute($xpath, $name);
*
* @return mixed
*/
- function getValue($xpath);
+ public function getValue($xpath);
/**
* Sets element's value by it's XPath query.
*
* @param string $xpath
* @param string $value
*/
- function setValue($xpath, $value);
+ public function setValue($xpath, $value);
/**
* Checks checkbox by it's XPath query.
*
* @param string $xpath
*/
- function check($xpath);
+ public function check($xpath);
/**
* Unchecks checkbox by it's XPath query.
*
* @param string $xpath
*/
- function uncheck($xpath);
+ public function uncheck($xpath);
/**
* Checks whether checkbox checked located by it's XPath query.
@@ -229,7 +237,7 @@ function uncheck($xpath);
*
* @return Boolean
*/
- function isChecked($xpath);
+ public function isChecked($xpath);
/**
* Selects option from select field located by it's XPath query.
@@ -238,36 +246,36 @@ function isChecked($xpath);
* @param string $value
* @param Boolean $multiple
*/
- function selectOption($xpath, $value, $multiple = false);
+ public function selectOption($xpath, $value, $multiple = false);
/**
* Clicks button or link located by it's XPath query.
*
* @param string $xpath
*/
- function click($xpath);
+ public function click($xpath);
/**
* Double-clicks button or link located by it's XPath query.
*
* @param string $xpath
*/
- function doubleClick($xpath);
+ public function doubleClick($xpath);
/**
* Right-clicks button or link located by it's XPath query.
*
* @param string $xpath
*/
- function rightClick($xpath);
+ public function rightClick($xpath);
/**
* Attaches file path to file field located by it's XPath query.
*
* @param string $xpath
* @param string $path
*/
- function attachFile($xpath, $path);
+ public function attachFile($xpath, $path);
/**
* Checks whether element visible located by it's XPath query.
@@ -276,28 +284,28 @@ function attachFile($xpath, $path);
*
* @return Boolean
*/
- function isVisible($xpath);
+ public function isVisible($xpath);
/**
* Simulates a mouse over on the element.
*
* @param string $xpath
*/
- function mouseOver($xpath);
+ public function mouseOver($xpath);
/**
* Brings focus to element.
*
* @param string $xpath
*/
- function focus($xpath);
+ public function focus($xpath);
/**
* Removes focus from element.
*
* @param string $xpath
*/
- function blur($xpath);
+ public function blur($xpath);
/**
* Presses specific keyboard key.
@@ -306,7 +314,7 @@ function blur($xpath);
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
- function keyPress($xpath, $char, $modifier = null);
+ public function keyPress($xpath, $char, $modifier = null);
/**
* Pressed down specific keyboard key.
@@ -315,7 +323,7 @@ function keyPress($xpath, $char, $modifier = null);
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
- function keyDown($xpath, $char, $modifier = null);
+ public function keyDown($xpath, $char, $modifier = null);
/**
* Pressed up specific keyboard key.
@@ -324,22 +332,22 @@ function keyDown($xpath, $char, $modifier = null);
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
- function keyUp($xpath, $char, $modifier = null);
+ public function keyUp($xpath, $char, $modifier = null);
/**
* Drag one element onto another.
*
* @param string $sourceXpath
* @param string $destinationXpath
*/
- function dragTo($sourceXpath, $destinationXpath);
+ public function dragTo($sourceXpath, $destinationXpath);
/**
* Executes JS script.
*
* @param string $script
*/
- function executeScript($script);
+ public function executeScript($script);
/**
* Evaluates JS script.
@@ -348,13 +356,22 @@ function executeScript($script);
*
* @return mixed
*/
- function evaluateScript($script);
+ public function evaluateScript($script);
/**
* Waits some time or until JS condition turns true.
*
* @param integer $time time in milliseconds
* @param string $condition JS condition
*/
- function wait($time, $condition);
+ public function wait($time, $condition);
+
+ /**
+ * Set the dimensions of the window.
+ *
+ * @param integer $width set the window width, measured in pixels
+ * @param integer $height set the window height, measured in pixels
+ * @param string $name window name (null for the main window)
+ */
+ public function resizeWindow($width, $height, $name = null);
}
View
14 src/Behat/Mink/Element/ElementInterface.php
@@ -24,14 +24,14 @@
*
* @return string
*/
- function getXpath();
+ public function getXpath();
/**
* Returns element's session.
*
* @return Session
*/
- function getSession();
+ public function getSession();
/**
* Checks whether element with specified selector exists.
@@ -41,7 +41,7 @@ function getSession();
*
* @return Boolean
*/
- function has($selector, $locator);
+ public function has($selector, $locator);
/**
* Finds first element with specified selector.
@@ -51,7 +51,7 @@ function has($selector, $locator);
*
* @return NodeElement|null
*/
- function find($selector, $locator);
+ public function find($selector, $locator);
/**
* Finds all elements with specified selector.
@@ -61,19 +61,19 @@ function find($selector, $locator);
*
* @return array
*/
- function findAll($selector, $locator);
+ public function findAll($selector, $locator);
/**
* Returns element text (inside tag).
*
* @return string|null
*/
- function getText();
+ public function getText();
/**
* Returns element html.
*
* @return string|null
*/
- function getHtml();
+ public function getHtml();
}
View
43 src/Behat/Mink/Element/NodeElement.php
@@ -5,6 +5,7 @@
use Behat\Mink\Session,
Behat\Mink\Driver\DriverInterface,
Behat\Mink\Element\ElementInterface,
+ Behat\Mink\Exception\ElementException,
Behat\Mink\Exception\ElementNotFoundException;
/*
@@ -84,7 +85,11 @@ public function getValue()
*/
public function setValue($value)
{
- $this->getSession()->getDriver()->setValue($this->getXpath(), $value);
+ try {
+ $this->getSession()->getDriver()->setValue($this->getXpath(), $value);
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
@@ -116,7 +121,11 @@ public function getAttribute($name)
*/
public function click()
{
- $this->getSession()->getDriver()->click($this->getXpath());
+ try {
+ $this->getSession()->getDriver()->click($this->getXpath());
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
@@ -132,31 +141,47 @@ public function press()
*/
public function doubleClick()
{
- $this->getSession()->getDriver()->doubleClick($this->getXpath());
+ try {
+ $this->getSession()->getDriver()->doubleClick($this->getXpath());
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
* Right-clicks current node.
*/
public function rightClick()
{
- $this->getSession()->getDriver()->rightClick($this->getXpath());
+ try {
+ $this->getSession()->getDriver()->rightClick($this->getXpath());
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
* Checks current node if it's a checkbox field.
*/
public function check()
{
- $this->getSession()->getDriver()->check($this->getXpath());
+ try {
+ $this->getSession()->getDriver()->check($this->getXpath());
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
* Unchecks current node if it's a checkbox field.
*/
public function uncheck()
{
- $this->getSession()->getDriver()->uncheck($this->getXpath());
+ try {
+ $this->getSession()->getDriver()->uncheck($this->getXpath());
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
@@ -207,7 +232,11 @@ public function selectOption($option, $multiple = false)
*/
public function attachFile($path)
{
- $this->getSession()->getDriver()->attachFile($this->getXpath(), $path);
+ try {
+ $this->getSession()->getDriver()->attachFile($this->getXpath(), $path);
+ } catch (\Exception $exception) {
+ throw new ElementException($this, $exception);
+ }
}
/**
View
16 src/Behat/Mink/Element/TraversableElement.php
@@ -92,6 +92,22 @@ public function hasButton($locator)
}
/**
+ * Checks whether an element has a named CSS class
+ *
+ * @param string $className Name of the class
+ *
+ * @return boolean
+ */
+ public function hasClass($className)
+ {
+ if ($this->hasAttribute('class')) {
+ return in_array($className, explode(' ', $this->getAttribute('class')));
+ }
+
+ return false;
+ }
+
+ /**
* Finds button (input[type=submit|image|button], button) with specified locator.
*
* @param string $locator button id, value or alt
View
4 src/Behat/Mink/Exception/DriverException.php
@@ -20,8 +20,8 @@ class DriverException extends Exception
/**
* Initializes exception.
*
- * @param string $message
- * @param int $code
+ * @param string $message
+ * @param int $code
* @param \Exception|null $previous
*/
public function __construct($message, $code = 0, \Exception $previous = null)
View
59 src/Behat/Mink/Exception/ElementException.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Behat\Mink\Exception;
+
+use Behat\Mink\Element\Element;
+
+/*
+ * This file is part of the Behat\Mink.
+ * (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.
+ */
+
+/**
+ * A standard way for elements to re-throw exceptions
+ *
+ * @author Chris Worfolk <xmeltrut@gmail.com>
+ */
+class ElementException extends Exception
+{
+ private $element;
+
+ /**
+ * Initialises exception.
+ *
+ * @param Element $element optional message
+ * @param \Exception $exception exception
+ */
+ public function __construct(Element $element, \Exception $exception)
+ {
+ $this->element = $element;
+
+ parent::__construct(sprintf("Exception thrown by %s\n%s",
+ $element->getXpath(),
+ $exception->getMessage()
+ ));
+ }
+
+ /**
+ * Override default toString so we don't send a full backtrace in verbose mode.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->getMessage();
+ }
+
+ /**
+ * Get the element that caused the exception
+ *
+ * @return Element
+ */
+ public function getElement()
+ {
+ return $this->element;
+ }
+}
View
2 src/Behat/Mink/Exception/Exception.php
@@ -103,7 +103,7 @@ protected function getResponseInfo()
$driver = basename(str_replace('\\', '/', get_class($this->session->getDriver())));
$info = '+--[ ';
- if (!in_array($driver, array('SahiDriver', 'SeleniumDriver'))) {
+ if (!in_array($driver, array('SahiDriver', 'SeleniumDriver', 'Selenium2Driver'))) {
$info .= 'HTTP/1.1 '.$this->session->getStatusCode().' | ';
}
$info .= $this->session->getCurrentUrl().' | '.$driver." ]\n|\n";
View
2 src/Behat/Mink/Exception/ResponseTextException.php
@@ -2,8 +2,6 @@
namespace Behat\Mink\Exception;
-use Behat\Mink\Session;
-
/*
* This file is part of the Behat\Mink.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
View
9 src/Behat/Mink/Mink.php
@@ -130,13 +130,16 @@ public function getSession($name = null)
/**
* Returns session asserter.
*
- * @param string $name session name
+ * @param Session|string $session session object or name
*
* @return WebAssert
*/
- public function assertSession($name = null)
+ public function assertSession($session = null)
{
- return new WebAssert($this->getSession($name));
+ if (!($session instanceof Session)) {
+ $session = $this->getSession($session);
+ }
+ return new WebAssert($session);
}
/**
View
6 src/Behat/Mink/Selector/NamedSelector.php
@@ -25,13 +25,13 @@ class NamedSelector implements SelectorInterface
.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@id = %locator% or ./@name = %locator%) or ./@id = //label[contains(normalize-space(string(.)), %locator%)]/@for) or ./@placeholder = %locator%)] | .//label[contains(normalize-space(string(.)), %locator%)]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]
XPATH
,'link' => <<<XPATH
-.//a[./@href][(((./@id = %locator% or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%)) or .//img[contains(./@alt, %locator%)])] | .//*[./@role = 'link'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
+.//a[./@href][(((./@id = %locator% or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%) or contains(./@rel, %locator%)) or .//img[contains(./@alt, %locator%)])] | .//*[./@role = 'link'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
XPATH
,'button' => <<<XPATH
-.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//button[(((./@id = %locator% or contains(./@value, %locator%)) or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//*[./@role = 'button'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
+.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][(((./@id = %locator% or ./@name = %locator%) or contains(./@value, %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//button[((((./@id = %locator% or ./@name = %locator%) or contains(./@value, %locator%)) or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//*[./@role = 'button'][(((./@id = %locator% or ./@name = %locator%) or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
XPATH
,'link_or_button' => <<<XPATH
-.//a[./@href][(((./@id = %locator% or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%)) or .//img[contains(./@alt, %locator%)])] | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//button[(((./@id = %locator% or contains(./@value, %locator%)) or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//*[(./@role = 'button' or ./@role = 'link')][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
+.//a[./@href][(((./@id = %locator% or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%) or contains(./@rel, %locator%)) or .//img[contains(./@alt, %locator%)])] | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//button[(((./@id = %locator% or contains(./@value, %locator%)) or contains(normalize-space(string(.)), %locator%)) or contains(./@title, %locator%))] | .//input[./@type = 'image'][contains(./@alt, %locator%)] | .//*[(./@role = 'button' or ./@role = 'link')][((./@id = %locator% or contains(./@value, %locator%)) or contains(./@title, %locator%) or contains(normalize-space(string(.)), %locator%))]
XPATH
,'content' => <<<XPATH
./descendant-or-self::*[contains(normalize-space(.), %locator%)]
View
2 src/Behat/Mink/Selector/SelectorInterface.php
@@ -24,5 +24,5 @@
*
* @return string
*/
- function translateToXPath($locator);
+ public function translateToXPath($locator);
}
View
23 src/Behat/Mink/Session.php
@@ -203,6 +203,17 @@ public function getCurrentUrl()
}
/**
+ * Capture a screenshot of the current window.
+ *
+ * @return string screenshot of MIME type image/* depending
+ * on driver (e.g., image/png, image/jpeg)
+ */
+ public function getScreenshot()
+ {
+ return $this->driver->getScreenshot();
+ }
+
+ /**
* Reloads current session page.
*/
public function reload()
@@ -278,4 +289,16 @@ public function wait($time, $condition = 'false')
{
$this->driver->wait($time, $condition);
}
+
+ /**
+ * Set the dimensions of the window.
+ *
+ * @param integer $width set the window width, measured in pixels
+ * @param integer $height set the window height, measured in pixels
+ * @param string $name window name (null for the main window)
+ */
+ public function resizeWindow($width, $height, $name = null)
+ {
+ return $this->driver->resizeWindow($width, $height, $name);
+ }
}
View
48 src/Behat/Mink/WebAssert.php
@@ -2,7 +2,8 @@
namespace Behat\Mink;
-use Behat\Mink\Element\NodeElement,
+use Behat\Mink\Element\Element,
+ Behat\Mink\Element\NodeElement,
Behat\Mink\Exception\ElementNotFoundException,
Behat\Mink\Exception\ExpectationException,
Behat\Mink\Exception\ResponseTextException,
@@ -90,9 +91,28 @@ public function addressMatches($regex)
}
/**
+ * Checks that specified cookie exists and its value equals to a given one
+ *
+ * @param string $name cookie name
+ * @param string $value cookie value
+ *
+ * @throws Behat\Mink\Exception\ExpectationException
+ */
+ public function cookieEquals($name, $value)
+ {
+ $this->cookieExists($name);
+ $actualValue = $this->session->getCookie($name);
+ if ($actualValue != $value) {
+ $message = sprintf('Cookie "%s" value is "%s", but should be "%s".', $name,
+ $actualValue, $value);
+ throw new ExpectationException($message, $this->session);
+ }
+ }
+
+ /**
* Checks that specified cookie exists
*
- * @param string $name cookie name
+ * @param string $name cookie name
*
* @throws Behat\Mink\Exception\ExpectationException
*/
@@ -300,16 +320,18 @@ public function elementsCount($selectorType, $selector, $count)
/**
* Checks that specific element exists on the current page.
*
- * @param string $selectorType element selector type (css, xpath)
- * @param string $selector element selector
+ * @param string $selectorType element selector type (css, xpath)
+ * @param string $selector element selector
+ * @param Element $container document to check against
*
* @return NodeElement
*
* @throws ElementNotFoundException
*/
- public function elementExists($selectorType, $selector)
+ public function elementExists($selectorType, $selector, Element $container = null)
{
- $node = $this->session->getPage()->find($selectorType, $selector);
+ $container = ($container !== null) ? $container : $this->session->getPage();
+ $node = $container->find($selectorType, $selector);
if (null === $node) {
throw new ElementNotFoundException($this->session, 'element', $selectorType, $selector);
@@ -321,14 +343,16 @@ public function elementExists($selectorType, $selector)
/**
* Checks that specific element does not exists on the current page.
*
- * @param string $selectorType element selector type (css, xpath)
- * @param string $selector element selector
+ * @param string $selectorType element selector type (css, xpath)
+ * @param string $selector element selector
+ * @param Element $container document to check against
*
* @throws ExpectationException
*/
- public function elementNotExists($selectorType, $selector)
+ public function elementNotExists($selectorType, $selector, Element $container = null)
{
- $node = $this->session->getPage()->find($selectorType, $selector);
+ $container = ($container !== null) ? $container : $this->session->getPage();
+ $node = $container->find($selectorType, $selector);
if (null !== $node) {
$message = sprintf('An element matching %s "%s" appears on this page, but it should not.', $selectorType, $selector);
@@ -469,7 +493,7 @@ public function fieldValueEquals($field, $value)
{
$node = $this->fieldExists($field);
$actual = $node->getValue();
- $regex = '/^'.preg_quote($value, '$/').'/ui';
+ $regex = '/^'.preg_quote($value, '/').'/ui';
if (!preg_match($regex, $actual)) {
$message = sprintf('The field "%s" value is "%s", but "%s" expected.', $field, $actual, $value);
@@ -489,7 +513,7 @@ public function fieldValueNotEquals($field, $value)
{
$node = $this->fieldExists($field);
$actual = $node->getValue();
- $regex = '/^'.preg_quote($value, '$/').'/ui';
+ $regex = '/^'.preg_quote($value, '/').'/ui';
if (preg_match($regex, $actual)) {
$message = sprintf('The field "%s" value is "%s", but it should not be.', $field, $actual);
View
10 tests/Behat/Mink/Driver/GeneralDriverTest.php
@@ -159,7 +159,15 @@ public function testReset()
$this->getSession()->visit($this->pathTo('/print_cookies.php'));
$this->assertContains(
- "array ( 'client_cookie1' = 'some_val', 'client_cookie2' = '123', '_SESS' = ",
+ "'client_cookie1' = 'some_val'",
+ $this->getSession()->getPage()->getText()
+ );
+ $this->assertContains(
+ "'client_cookie2' = '123'",
+ $this->getSession()->getPage()->getText()
+ );
+ $this->assertContains(
+ "_SESS' = ",
$this->getSession()->getPage()->getText()
);
$this->assertContains(
View
14 tests/Behat/Mink/Driver/JavascriptDriverTest.php
@@ -179,4 +179,18 @@ public function testIssue225()
$this->assertContains('OH AIH!', $this->getSession()->getPage()->getText());
}
+
+ /**
+ * 'change' event should be fired after selecting an <option> in a <select>
+ */
+ public function testIssue255()
+ {
+ $session = $this->getSession();
+ $session->visit($this->pathTo('/issueChangeSelect.php'));
+
+ $session->getPage()->selectFieldOption('foobar', 'Option 3');
+
+ $session->wait(2000, '$("#output").text() != ""');
+ $this->assertEquals('onChange', $session->getPage()->find('css', '#output')->getText());
+ }
}
View
33 tests/Behat/Mink/Driver/web-fixtures/issue255.php
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Issue 255</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <script src="js/jquery-1.6.2-min.js"></script>
+</head>
+<body>
+ <form>
+ <label for="foo_select">Foo</label>
+ <select name="foo_select" id="foo_select">
+ <option value="1" selected="selected" type="text">Option 1</option>
+ <option value="2" type="text">Option 2</option>
+ <option value="3" type="text">Option 3</option>
+ </select>
+ <input type="checkbox" id="foo_check" />
+ <input type="submit" />
+ <p id="output_foo_select"></p>
+ <p id="output_foo_check"></p>
+ </form>
+
+ <script type="text/javascript">
+ (function() {
+ $('#foo_select').change(function () {
+ $('#output_foo_select').text("onChangeSelect");
+ });
+ $('#foo_check').change(function () {
+ $('#output_foo_check').text("onChangeCheck");
+ });
+ })();
+ </script>
+</body>
+</html>
View
8 tests/Behat/Mink/Element/DocumentElementTest.php
@@ -88,7 +88,7 @@ public function testFindField()
public function testFindLink()
{
$xpath = <<<XPATH
-//html/.//a[./@href][(((./@id = 'some link' or contains(normalize-space(string(.)), 'some link')) or contains(./@title, 'some link')) or .//img[contains(./@alt, 'some link')])] | .//*[./@role = 'link'][((./@id = 'some link' or contains(./@value, 'some link')) or contains(./@title, 'some link') or contains(normalize-space(string(.)), 'some link'))]
+//html/.//a[./@href][(((./@id = 'some link' or contains(normalize-space(string(.)), 'some link')) or contains(./@title, 'some link') or contains(./@rel, 'some link')) or .//img[contains(./@alt, 'some link')])] | .//*[./@role = 'link'][((./@id = 'some link' or contains(./@value, 'some link')) or contains(./@title, 'some link') or contains(normalize-space(string(.)), 'some link'))]
XPATH;
$this->session->getDriver()
@@ -104,7 +104,7 @@ public function testFindLink()
public function testFindButton()
{
$xpath = <<<XPATH
-//html/.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = 'some button' or contains(./@value, 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//button[(((./@id = 'some button' or contains(./@value, 'some button')) or contains(normalize-space(string(.)), 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//*[./@role = 'button'][((./@id = 'some button' or contains(./@value, 'some button')) or contains(./@title, 'some button') or contains(normalize-space(string(.)), 'some button'))]
+//html/.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][(((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//button[((((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(normalize-space(string(.)), 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//*[./@role = 'button'][(((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(./@title, 'some button') or contains(normalize-space(string(.)), 'some button'))]
XPATH;
$this->session->getDriver()
@@ -164,7 +164,7 @@ public function testHasContent()
public function testHasLink()
{
$xpath = <<<XPATH
-//html/.//a[./@href][(((./@id = 'some link' or contains(normalize-space(string(.)), 'some link')) or contains(./@title, 'some link')) or .//img[contains(./@alt, 'some link')])] | .//*[./@role = 'link'][((./@id = 'some link' or contains(./@value, 'some link')) or contains(./@title, 'some link') or contains(normalize-space(string(.)), 'some link'))]
+//html/.//a[./@href][(((./@id = 'some link' or contains(normalize-space(string(.)), 'some link')) or contains(./@title, 'some link') or contains(./@rel, 'some link')) or .//img[contains(./@alt, 'some link')])] | .//*[./@role = 'link'][((./@id = 'some link' or contains(./@value, 'some link')) or contains(./@title, 'some link') or contains(normalize-space(string(.)), 'some link'))]
XPATH;
$this->session->getDriver()
@@ -180,7 +180,7 @@ public function testHasLink()
public function testHasButton()
{
$xpath = <<<XPATH
-//html/.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = 'some button' or contains(./@value, 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//button[(((./@id = 'some button' or contains(./@value, 'some button')) or contains(normalize-space(string(.)), 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//*[./@role = 'button'][((./@id = 'some button' or contains(./@value, 'some button')) or contains(./@title, 'some button') or contains(normalize-space(string(.)), 'some button'))]
+//html/.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][(((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//button[((((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(normalize-space(string(.)), 'some button')) or contains(./@title, 'some button'))] | .//input[./@type = 'image'][contains(./@alt, 'some button')] | .//*[./@role = 'button'][(((./@id = 'some button' or ./@name = 'some button') or contains(./@value, 'some button')) or contains(./@title, 'some button') or contains(normalize-space(string(.)), 'some button'))]
XPATH;
$this->session->getDriver()
View
15 tests/Behat/Mink/Element/NodeElementTest.php
@@ -66,6 +66,21 @@ public function testGetAttribute()
$this->assertEquals('http://...', $node->getAttribute('href'));
}
+ public function testHasClass()
+ {
+ $node = new NodeElement('input_tag', $this->session);
+
+ $this->session->getDriver()
+ ->expects($this->exactly(6))
+ ->method('getAttribute')
+ ->with('input_tag', 'class')
+ ->will($this->returnValue('class1 class2'));
+
+ $this->assertTrue($node->hasClass('class1'));
+ $this->assertTrue($node->hasClass('class2'));
+ $this->assertFalse($node->hasClass('class3'));
+ }
+
public function testGetValue()
{
$node = new NodeElement('input_tag', $this->session);
View
45 tests/Behat/Mink/WebAssertTest.php
@@ -75,6 +75,29 @@ public function testAddressMatches()
}
/**
+ * @covers Behat\Mink\WebAssert::cookieEquals
+ */
+ public function testCookieEquals()
+ {
+ $this->session->
+ expects($this->any())->
+ method('getCookie')->
+ will($this->returnValueMap(
+ array(
+ array('foo', 'bar'),
+ array('bar', 'baz'),
+ )
+ ));
+
+ $this->assertCorrectAssertion('cookieEquals', array('foo', 'bar'));
+ $this->assertWrongAssertion(
+ 'cookieEquals', array('bar', 'foo'),
+ 'Behat\Mink\Exception\ExpectationException',
+ 'Cookie "bar" value is "baz", but should be "foo".'
+ );
+ }
+
+ /**
* @covers Behat\Mink\WebAssert::cookieExists
*/
public function testCookieExists()
@@ -372,10 +395,10 @@ public function testElementExists()
;
$page
- ->expects($this->exactly(2))
+ ->expects($this->exactly(4))
->method('find')
->with('css', 'h2 > span')
- ->will($this->onConsecutiveCalls(1, null))
+ ->will($this->onConsecutiveCalls(1, null, 1, null))
;
$this->assertCorrectAssertion('elementExists', array('css', 'h2 > span'));
@@ -384,6 +407,13 @@ public function testElementExists()
'Behat\\Mink\\Exception\\ElementNotFoundException',
'Element matching css "h2 > span" not found.'
);
+
+ $this->assertCorrectAssertion('elementExists', array('css', 'h2 > span', $page));
+ $this->assertWrongAssertion(
+ 'elementExists', array('css', 'h2 > span', $page),
+ 'Behat\\Mink\\Exception\\ElementNotFoundException',
+ 'Element matching css "h2 > span" not found.'
+ );
}
public function testElementNotExists()
@@ -400,10 +430,10 @@ public function testElementNotExists()
;
$page
- ->expects($this->exactly(2))
+ ->expects($this->exactly(4))
->method('find')
->with('css', 'h2 > span')
- ->will($this->onConsecutiveCalls(null, 1))
+ ->will($this->onConsecutiveCalls(null, 1, null, 1))
;
$this->assertCorrectAssertion('elementNotExists', array('css', 'h2 > span'));
@@ -412,6 +442,13 @@ public function testElementNotExists()
'Behat\\Mink\\Exception\\ExpectationException',
'An element matching css "h2 > span" appears on this page, but it should not.'
);
+
+ $this->assertCorrectAssertion('elementNotExists', array('css', 'h2 > span', $page));
+ $this->assertWrongAssertion(
+ 'elementNotExists', array('css', 'h2 > span', $page),
+ 'Behat\\Mink\\Exception\\ExpectationException',
+ 'An element matching css "h2 > span" appears on this page, but it should not.'
+ );
}
public function testElementTextContains()

0 comments on commit c76a5e0

Please sign in to comment.
Something went wrong with that request. Please try again.