TimeTrex Community Edition v16.2.0

This commit is contained in:
2022-12-13 07:10:06 +01:00
commit 472f000c1b
6810 changed files with 2636142 additions and 0 deletions

View File

@ -0,0 +1,638 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions;
use Exception;
use InvalidArgumentException;
use PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\Element\Select;
use PHPUnit\Extensions\Selenium2TestCase\ElementCriteria;
use PHPUnit\Extensions\Selenium2TestCase\KeysHolder;
use PHPUnit\Extensions\Selenium2TestCase\NoSeleniumException;
use PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\Session\Timeouts;
use PHPUnit\Extensions\Selenium2TestCase\SessionStrategy;
use PHPUnit\Extensions\Selenium2TestCase\SessionStrategy\Isolated;
use PHPUnit\Extensions\Selenium2TestCase\SessionStrategy\Shared;
use PHPUnit\Extensions\Selenium2TestCase\URL;
use PHPUnit\Extensions\Selenium2TestCase\WaitUntil;
use PHPUnit\Extensions\Selenium2TestCase\Window;
use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestResult;
use PHPUnit\Util\InvalidArgumentHelper;
use RuntimeException;
use Throwable;
/**
* TestCase class that uses Selenium 2
* (WebDriver API and JsonWire protocol) to provide
* the functionality required for web testing.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
* @method void acceptAlert() Press OK on an alert, or confirms a dialog
* @method mixed alertText() alertText($value = NULL) Gets the alert dialog text, or sets the text for a prompt dialog
* @method void back()
* @method Element byClassName() byClassName($value)
* @method Element byCssSelector() byCssSelector($value)
* @method Element byId() byId($value)
* @method Element byLinkText() byLinkText($value)
* @method Element byPartialLinkText() byPartialLinkText($value)
* @method Element byName() byName($value)
* @method Element byTag() byTag($value)
* @method Element byXPath() byXPath($value)
* @method void click() click(int $button = 0) Click any mouse button (at the coordinates set by the last moveto command).
* @method void clickOnElement() clickOnElement($id)
* @method string currentScreenshot() BLOB of the image file
* @method void dismissAlert() Press Cancel on an alert, or does not confirm a dialog
* @method void doubleclick() Double clicks (at the coordinates set by the last moveto command).
* @method Element element() element(ElementCriteria $criteria) Retrieves an element
* @method array elements() elements(ElementCriteria $criteria) Retrieves an array of Element instances
* @method string execute() execute($javaScriptCode) Injects arbitrary JavaScript in the page and returns the last
* @method string executeAsync() executeAsync($javaScriptCode) Injects arbitrary JavaScript and wait for the callback (last element of arguments) to be called
* @method void forward()
* @method void frame() frame(mixed $element) Changes the focus to a frame in the page (by frameCount of type int, htmlId of type string, htmlName of type string or element of type Element)
* @method void moveto() moveto(Element $element) Move the mouse by an offset of the specificed element.
* @method void refresh()
* @method Select select() select($element)
* @method string source() Returns the HTML source of the page
* @method Timeouts timeouts()
* @method string title()
* @method void|string url() url($url = NULL)
* @method ElementCriteria using() using($strategy) Factory Method for Criteria objects
* @method void window() window($name) Changes the focus to another window
* @method string windowHandle() Retrieves the current window handle
* @method string windowHandles() Retrieves a list of all available window handles
* @method string keys($string) Send a sequence of key strokes to the active element.
* @method string file($file_path) Upload a local file. Returns the fully qualified path to the transferred file.
* @method array log(string $type) Get the log for a given log type. Log buffer is reset after each request.
* @method array logTypes() Get available log types.
* @method void closeWindow() Close the current window.
* @method void stop() Close the current window and clear session data.
* @method Element active() Get the element on the page that currently has focus.
* @method Window currentWindow() get the current Window Object
*/
abstract class Selenium2TestCase extends TestCase
{
const VERSION = '9.0.0';
/**
* @var string override to provide code coverage data from the server
*/
protected $coverageScriptUrl;
/**
* @var Session
*/
private $session;
/**
* @var array
*/
private $parameters;
/**
* @var SessionStrategy
*/
protected static $sessionStrategy;
/**
* @var SessionStrategy
*/
protected static $browserSessionStrategy;
/**
* Default timeout for wait until, ms
*
* @var int
*/
private static $defaultWaitUntilTimeout = 0;
/**
* Default timeout for wait until, ms
*
* @var int
*/
private static $defaultWaitUntilSleepInterval = 500;
/**
* @var SessionStrategy
*/
protected $localSessionStrategy;
/**
* @var array
*/
private static $lastBrowserParams;
/**
* @var string
*/
private $testId;
/**
* @var boolean
*/
private $collectCodeCoverageInformation;
/**
* @var KeysHolder
*/
private $keysHolder;
/**
* @param boolean
*/
private static $keepSessionOnFailure = FALSE;
/**
* @param boolean
*/
public static function shareSession($shareSession)
{
if (!is_bool($shareSession)) {
throw new InvalidArgumentException("The shared session support can only be switched on or off.");
}
if (!$shareSession) {
self::$sessionStrategy = self::defaultSessionStrategy();
} else {
self::$sessionStrategy = new Shared(
self::defaultSessionStrategy(), self::$keepSessionOnFailure
);
}
}
public static function keepSessionOnFailure($keepSession)
{
if (!is_bool($keepSession)) {
throw new InvalidArgumentException("The keep session on fail support can only be switched on or off.");
}
if ($keepSession){
self::$keepSessionOnFailure = TRUE;
}
}
private static function sessionStrategy()
{
if (!self::$sessionStrategy) {
self::$sessionStrategy = self::defaultSessionStrategy();
}
return self::$sessionStrategy;
}
private static function defaultSessionStrategy()
{
return new Isolated;
}
/**
* Get the default timeout for WaitUntil
* @return int the default timeout
*/
public static function defaultWaitUntilTimeout(){
return self::$defaultWaitUntilTimeout;
}
/**
* Set the default timeout for WaitUntil
* @param int $timeout the new default timeout
*/
public static function setDefaultWaitUntilTimeout($timeout){
$timeout = (int) $timeout;
self::$defaultWaitUntilTimeout = $timeout > 0 ? $timeout : 0;
}
/**
* Get the default sleep delay for WaitUntil
* @return int
*/
public static function defaultWaitUntilSleepInterval(){
return self::$defaultWaitUntilSleepInterval;
}
/**
* Set default sleep delay for WaitUntil
* @param int $sleepDelay the new default sleep delay
*/
public static function setDefaultWaitUntilSleepInterval($sleepDelay){
$sleepDelay = (int) $sleepDelay;
self::$defaultWaitUntilSleepInterval = $sleepDelay > 0 ? $sleepDelay : 0;
}
public function __construct($name = NULL, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->parameters = array(
'host' => 'localhost',
'port' => 4444,
'browser' => NULL,
'browserName' => NULL,
'desiredCapabilities' => array(),
'seleniumServerRequestsTimeout' => 60,
'secure' => FALSE
);
$this->keysHolder = new KeysHolder();
}
public function setupSpecificBrowser($params)
{
if (isset($params['keepSession'])) {
$this->keepSessionOnFailure(TRUE);
}
$this->setUpSessionStrategy($params);
$params = array_merge($this->parameters, $params);
$this->setHost($params['host']);
$this->setPort($params['port']);
$this->setBrowser($params['browserName']);
$this->parameters['browser'] = $params['browser'];
$this->setDesiredCapabilities($params['desiredCapabilities']);
$this->setSeleniumServerRequestsTimeout(
$params['seleniumServerRequestsTimeout']);
}
protected function setUpSessionStrategy($params)
{
// This logic enables us to have a session strategy reused for each
// item in self::$browsers. We don't want them both to share one
// and we don't want each test for a specific browser to have a
// new strategy
if ($params == self::$lastBrowserParams) {
// do nothing so we use the same session strategy for this
// browser
} elseif (isset($params['sessionStrategy'])) {
$strat = $params['sessionStrategy'];
if ($strat != "isolated" && $strat != "shared") {
throw new InvalidArgumentException("Session strategy must be either 'isolated' or 'shared'");
} elseif ($strat == "isolated") {
self::$browserSessionStrategy = new Isolated;
} else {
self::$browserSessionStrategy = new Shared(self::defaultSessionStrategy(), self::$keepSessionOnFailure);
}
} else {
self::$browserSessionStrategy = self::defaultSessionStrategy();
}
self::$lastBrowserParams = $params;
$this->localSessionStrategy = self::$browserSessionStrategy;
}
private function getStrategy()
{
if ($this->localSessionStrategy) {
return $this->localSessionStrategy;
} else {
return self::sessionStrategy();
}
}
public function prepareSession()
{
try {
if (!$this->session) {
$this->session = $this->getStrategy()->session($this->parameters);
}
} catch (NoSeleniumException $e) {
$this->markTestSkipped("The Selenium Server is not active on host {$this->parameters['host']} at port {$this->parameters['port']}.");
}
return $this->session;
}
public function run(TestResult $result = NULL): TestResult
{
$this->testId = get_class($this) . '__' . $this->getName();
if ($result === NULL) {
$result = $this->createResult();
}
$this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation() && $this->coverageScriptUrl;
parent::run($result);
if ($this->collectCodeCoverageInformation) {
$coverage = new RemoteCoverage(
$this->coverageScriptUrl,
$this->testId
);
$result->getCodeCoverage()->append(
$coverage->get(), $this
);
}
// do not call this before to give the time to the Listeners to run
$this->getStrategy()->endOfTest($this->session);
return $result;
}
/**
* @throws RuntimeException
* @throws Exception
*/
protected function runTest()
{
$this->prepareSession();
$thrownException = NULL;
if ($this->collectCodeCoverageInformation) {
$this->url($this->coverageScriptUrl); // phpunit_coverage.php won't do anything if the cookie isn't set, which is exactly what we want
$this->session->cookie()->add('PHPUNIT_SELENIUM_TEST_ID', $this->testId)->set();
}
try {
$this->setUpPage();
$result = parent::runTest();
if (!empty($this->verificationErrors)) {
$this->fail(implode("\n", $this->verificationErrors));
}
} catch (Exception $e) {
$thrownException = $e;
}
if ($this->collectCodeCoverageInformation) {
$this->session->cookie()->remove('PHPUNIT_SELENIUM_TEST_ID');
}
if (NULL !== $thrownException) {
throw $thrownException;
}
return $result;
}
public static function suite($className)
{
return SeleniumTestSuite::fromTestCaseClass($className);
}
public function onNotSuccessfulTest(Throwable $e): void
{
$this->getStrategy()->notSuccessfulTest();
parent::onNotSuccessfulTest($e);
}
/**
* Delegate method calls to the Session.
*
* @param string $command
* @param array $arguments
* @return mixed
*/
public function __call($command, $arguments)
{
if ($this->session === NULL) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception("There is currently no active session to execute the '$command' command. You're probably trying to set some option in setUp() with an incorrect setter name. You may consider using setUpPage() instead.");
}
$result = call_user_func_array(
array($this->session, $command), $arguments
);
return $result;
}
/**
* @param string $host
* @throws InvalidArgumentException
*/
public function setHost($host)
{
if (!is_string($host)) {
throw InvalidArgumentHelper::factory(1, 'string');
}
$this->parameters['host'] = $host;
}
public function getHost()
{
return $this->parameters['host'];
}
/**
* @param integer $port
* @throws InvalidArgumentException
*/
public function setPort($port)
{
if (!is_int($port)) {
throw InvalidArgumentHelper::factory(1, 'integer');
}
$this->parameters['port'] = $port;
}
public function getPort()
{
return $this->parameters['port'];
}
/**
* @param boolean $secure
* @throws InvalidArgumentException
*/
public function setSecure($secure)
{
if(!is_bool($secure)) {
throw InvalidArgumentHelper::factory(1, 'boolean');
}
$this->parameters['secure'] = $secure;
}
public function getSecure()
{
return $this->parameters['secure'];
}
/**
* @param string $browser
* @throws InvalidArgumentException
*/
public function setBrowser($browserName)
{
if (!is_string($browserName)) {
throw InvalidArgumentHelper::factory(1, 'string');
}
$this->parameters['browserName'] = $browserName;
}
public function getBrowser()
{
return $this->parameters['browserName'];
}
/**
* @param string $browserUrl
* @throws InvalidArgumentException
*/
public function setBrowserUrl($browserUrl)
{
if (!is_string($browserUrl)) {
throw InvalidArgumentHelper::factory(1, 'string');
}
$this->parameters['browserUrl'] = new URL($browserUrl);
}
public function getBrowserUrl()
{
if (isset($this->parameters['browserUrl'])) {
return $this->parameters['browserUrl'];
}
return '';
}
/**
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
*/
public function setDesiredCapabilities(array $capabilities)
{
$this->parameters['desiredCapabilities'] = $capabilities;
}
public function getDesiredCapabilities()
{
return $this->parameters['desiredCapabilities'];
}
/**
* @param int $timeout seconds
*/
public function setSeleniumServerRequestsTimeout($timeout)
{
$this->parameters['seleniumServerRequestsTimeout'] = $timeout;
}
public function getSeleniumServerRequestsTimeout()
{
return $this->parameters['seleniumServerRequestsTimeout'];
}
/**
* Get test id (generated internally)
* @return string
*/
public function getTestId()
{
return $this->testId;
}
/**
* Get Selenium2 current session id
* @return string
*/
public function getSessionId()
{
if ($this->session) {
return $this->session->id();
}
return FALSE;
}
/**
* Wait until callback isn't null or timeout occurs
*
* @param $callback
* @param null $timeout
* @return mixed
*/
public function waitUntil($callback, $timeout = NULL)
{
$waitUntil = new WaitUntil($this);
return $waitUntil->run($callback, $timeout);
}
/**
* Sends a special key
* Deprecated due to issues with IE webdriver. Use keys() method instead
* @deprecated
* @param string $name
* @throws \PHPUnit\Extensions\Selenium2TestCase\Exception
* @see KeysHolder
*/
public function keysSpecial($name)
{
$names = explode(',', $name);
foreach ($names as $key) {
$this->keys($this->keysHolder->specialKey(trim($key)));
}
}
/**
* setUp method that is called after the session has been prepared.
* It is possible to use session-specific commands like url() here.
*/
public function setUpPage()
{
}
/**
* Check whether an alert box is present
*/
public function alertIsPresent()
{
try {
$this->alertText();
return TRUE;
} catch (Exception $e) {
return NULL;
}
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use InvalidArgumentException;
/**
* Base class for implementing commands with special semantics.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
abstract class Command
{
protected $jsonParameters;
private $commandName;
/**
* @param array $jsonParameters null in case of no parameters
*/
public function __construct($jsonParameters, URL $url)
{
if (!is_array($jsonParameters) && $jsonParameters !== NULL) {
throw new InvalidArgumentException("The JSON parameters must be an array, or a NULL value in case they are not required.");
}
$this->jsonParameters = $jsonParameters;
$this->url = $url;
}
public function url()
{
return $this->url;
}
/**
* @return string
*/
abstract public function httpMethod();
/**
* @param array $jsonParameters null in case of no parameters
*/
public function jsonParameters()
{
return $this->jsonParameters;
}
}

View File

@ -0,0 +1,161 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
/**
* Object representing elements, or everything that may have subcommands.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
abstract class CommandsHolder
{
/**
* @var Driver
*/
protected $driver;
/**
* @var string the API URL for this element,
*/
protected $url;
/**
* @var array instances of
* PHPUnit_Extensions_Selenium2TestCase_ElementCommand
*/
protected $commands;
public function __construct($driver, URL $url)
{
$this->driver = $driver;
$this->url = $url;
$this->commands = array();
foreach ($this->initCommands() as $commandName => $handler) {
if (is_string($handler)) {
$this->commands[$commandName] = $this->factoryMethod($handler);
} else if (is_callable($handler)) {
$this->commands[$commandName] = $handler;
} else {
throw new InvalidArgumentException("Command $commandName is not configured correctly.");
}
}
}
/**
* @return array class names, or
* callables of the form function($parameter, $commandUrl)
*/
protected abstract function initCommands();
public function __call($commandName, $arguments)
{
$jsonParameters = $this->extractJsonParameters($arguments);
$response = $this->driver->execute($this->newCommand($commandName, $jsonParameters));
return $response->getValue();
}
protected function postCommand($name, ElementCriteria $criteria)
{
$response = $this->driver->curl('POST',
$this->url->addCommand($name),
$criteria->getArrayCopy());
return $response->getValue();
}
/**
* @params string $commandClass a class name, descending from Command
* @return callable
*/
private function factoryMethod($commandClass)
{
return function($jsonParameters, $url) use ($commandClass) {
return new $commandClass($jsonParameters, $url);
};
}
private function extractJsonParameters($arguments)
{
$this->checkArguments($arguments);
if (count($arguments) == 0) {
return NULL;
}
return $arguments[0];
}
private function checkArguments($arguments)
{
if (count($arguments) > 1) {
throw new Exception('You cannot call a command with multiple method arguments.');
}
}
/**
* @param string $commandName The called method name
* defined as a key in initCommands()
* @param array $jsonParameters
* @return Command
*/
protected function newCommand($commandName, $jsonParameters)
{
if (isset($this->commands[$commandName])) {
$factoryMethod = $this->commands[$commandName];
$url = $this->url->addCommand($commandName);
$command = $factoryMethod($jsonParameters, $url);
return $command;
}
throw new BadMethodCallException("The command '$commandName' is not existent or not supported yet.");
}
}

View File

@ -0,0 +1,180 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use BadMethodCallException;
use PHPUnit\Extensions\Selenium2TestCase\Session\Timeouts;
/**
* Driver for creating browser session with Selenium 2 (WebDriver API).
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Driver
{
private $seleniumServerUrl;
private $seleniumServerRequestsTimeout;
public function __construct(URL $seleniumServerUrl, $timeout = 60)
{
$this->seleniumServerUrl = $seleniumServerUrl;
$this->seleniumServerRequestsTimeout = $timeout;
}
public function startSession(array $desiredCapabilities, URL $browserUrl)
{
$sessionCreation = $this->seleniumServerUrl->descend("/wd/hub/session");
$response = $this->curl('POST', $sessionCreation, array(
'desiredCapabilities' => $desiredCapabilities
));
$sessionPrefix = $response->getURL();
$timeouts = new Timeouts(
$this,
$sessionPrefix->descend('timeouts'),
$this->seleniumServerRequestsTimeout * 1000
);
return new Session(
$this,
$sessionPrefix,
$browserUrl,
$timeouts
);
}
/**
* Performs an HTTP request to the Selenium 2 server.
*
* @param string $method 'GET'|'POST'|'DELETE'|...
* @param string $url
* @param array $params JSON parameters for POST requests
*/
public function curl($http_method, URL $url, $params = NULL)
{
$curl = curl_init($url->getValue());
curl_setopt($curl, CURLOPT_TIMEOUT, $this->seleniumServerRequestsTimeout);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl,
CURLOPT_HTTPHEADER,
array(
'Content-type: application/json;charset=UTF-8',
'Accept: application/json;charset=UTF-8'
));
if ($http_method === 'POST') {
curl_setopt($curl, CURLOPT_POST, TRUE);
if ($params && is_array($params)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
} else {
curl_setopt($curl, CURLOPT_POSTFIELDS, '');
}
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
} else if ($http_method == 'DELETE') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
$rawResponse = trim(curl_exec($curl));
if (curl_errno($curl)) {
throw new NoSeleniumException(
'Error connection[' . curl_errno($curl) . '] to ' .
$url->getValue() . ': ' . curl_error($curl)
);
}
$info = curl_getinfo($curl);
if ($info['http_code'] == 0) {
throw new NoSeleniumException();
}
if ($info['http_code'] == 404) {
throw new BadMethodCallException("The command $url is not recognized by the server.");
}
if (($info['http_code'] >= 400) && ($info['http_code'] < 500)) {
throw new BadMethodCallException("Something unexpected happened: '$rawResponse'");
}
curl_close($curl);
$content = json_decode($rawResponse, TRUE);
if ($content === null && json_last_error() !== JSON_ERROR_NONE) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception(
sprintf(
"JSON decoding of remote response failed.\n".
"Error code: %d\n".
"The response: '%s'\n",
json_last_error(),
$rawResponse
)
);
}
$value = null;
if (is_array($content) && array_key_exists('value', $content)) {
$value = $content['value'];
}
$message = null;
if (is_array($value) && array_key_exists('message', $value)) {
$message = $value['message'];
}
$status = isset($content['status']) ? $content['status'] : 0;
if ($status !== WebDriverException::Success) {
throw new WebDriverException($message, $status);
}
return new Response($content, $info);
}
public function execute(Command $command)
{
return $this->curl($command->httpMethod(),
$command->url(),
$command->jsonParameters());
}
}

View File

@ -0,0 +1,190 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use InvalidArgumentException;
use PHPUnit\Extensions\Selenium2TestCase\Element\Accessor;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Attribute;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Click;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Css;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Equals;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericAccessor;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericPost;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Rect;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\Value;
/**
* Object representing a DOM element.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
* @method string attribute($name) Retrieves an element's attribute
* @method void clear() Empties the content of a form element.
* @method void click() Clicks on element
* @method string css($propertyName) Retrieves the value of a CSS property
* @method bool displayed() Checks an element's visibility
* @method bool enabled() Checks a form element's state
* @method bool equals(Element $another) Checks if the two elements are the same on the page
* @method array rect() Retrieves the element's coordinates: keys 'x', 'y', 'width' and 'height' in the returned array
* @method array location() Retrieves the element's position in the page: keys 'x' and 'y' in the returned array
* @method bool selected() Checks the state of an option or other form element
* @method array size() Retrieves the dimensions of the element: 'width' and 'height' of the returned array
* @method void submit() Submits a form; can be called on its children
* @method string text() Get content of ordinary elements
*/
class Element extends Accessor
{
/**
* @return \self
* @throws InvalidArgumentException
*/
public static function fromResponseValue(array $value, URL $parentFolder, Driver $driver)
{
if (!isset($value['ELEMENT'])) {
throw new InvalidArgumentException('Element not found.');
}
$url = $parentFolder->descend($value['ELEMENT']);
return new self($driver, $url);
}
/**
* @return integer
*/
public function getId()
{
return $this->url->lastSegment();
}
/**
* @return array class names
*/
protected function initCommands()
{
return array(
'attribute' => Attribute::class,
'clear' => GenericPost::class,
'click' => Click::class,
'css' => Css::class,
'displayed' => GenericAccessor::class,
'enabled' => GenericAccessor::class,
'equals' => Equals::class,
'location' => GenericAccessor::class,
'name' => GenericAccessor::class,
'rect' => Rect::class,
'selected' => GenericAccessor::class,
'size' => GenericAccessor::class,
'submit' => GenericPost::class,
'text' => GenericAccessor::class,
'value' => Value::class,
'tap' => $this->touchCommandFactoryMethod('touch/click'),
'scroll' => $this->touchCommandFactoryMethod('touch/scroll'),
'doubletap' => $this->touchCommandFactoryMethod('touch/doubleclick'),
'longtap' => $this->touchCommandFactoryMethod('touch/longclick'),
'flick' => $this->touchCommandFactoryMethod('touch/flick')
);
}
protected function getSessionUrl()
{
return $this->url->ascend()->ascend();
}
private function touchCommandFactoryMethod($urlSegment)
{
$url = $this->getSessionUrl()->addCommand($urlSegment);
$self = $this;
return function ($jsonParameters, $commandUrl) use ($url, $self) {
if ((is_array($jsonParameters) &&
!isset($jsonParameters['element'])) ||
is_null($jsonParameters)) {
$jsonParameters['element'] = $self->getId();
}
return new GenericPost($jsonParameters, $url);
};
}
/**
* Retrieves the tag name
* @return string
*/
public function name()
{
return strtolower(parent::name());
}
/**
* Generates an array that is structured as the WebDriver Object of the JSONWireProtocoll
*
* @return array
*/
public function toWebDriverObject()
{
return array('ELEMENT' => (string)$this->getId());
}
/**
* Get or set value of form elements. If the element already has a value, the set one will be appended to it.
* Created **ONLY** for keeping backward compatibility, since in selenium v2.42.0 it was removed
* The currently recommended solution is to use `$element->attribute('value')`
* @see https://code.google.com/p/selenium/source/detail?r=953007b48e83f90450f3e41b11ec31e2928f1605
* @see https://code.google.com/p/selenium/source/browse/java/CHANGELOG
*
* @param string $newValue
* @return null|string
*/
public function value($newValue = NULL)
{
if ($newValue !== NULL) {
return parent::value($newValue);
}
return $this->attribute('value');
}
}

View File

@ -0,0 +1,181 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\CommandsHolder;
use PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\ElementCriteria;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Provides access to /element and /elements commands
*
* @package PHPUnit_Selenium
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
*/
abstract class Accessor extends CommandsHolder
{
/**
* @param string $value e.g. 'container'
* @return Element
*/
public function byClassName($value)
{
return $this->by('class name', $value);
}
/**
* @param string $value e.g. 'div.container'
* @return Element
*/
public function byCssSelector($value)
{
return $this->by('css selector', $value);
}
/**
* @param string $value e.g. 'uniqueId'
* @return Element
*/
public function byId($value)
{
return $this->by('id', $value);
}
/**
* @param string $value e.g. 'Link text'
* @return Element
*/
public function byLinkText($value)
{
return $this->by('link text', $value);
}
/**
* @param string $value e.g. 'Link te'
* @return Element
*/
public function byPartialLinkText($value)
{
return $this->by('partial link text', $value);
}
/**
* @param string $value e.g. 'email_address'
* @return Element
*/
public function byName($value)
{
return $this->by('name', $value);
}
/**
* @param string $value e.g. 'body'
* @return Element
*/
public function byTag($value)
{
return $this->by('tag name', $value);
}
/**
* @param string $value e.g. '/div[@attribute="value"]'
* @return Element
*/
public function byXPath($value)
{
return $this->by('xpath', $value);
}
/**
* @return Element
*/
public function element(ElementCriteria $criteria)
{
$value = $this->postCommand('element', $criteria);
return Element::fromResponseValue($value, $this->getSessionUrl()->descend('element'), $this->driver);
}
/**
* @return Element[]
*/
public function elements(ElementCriteria $criteria)
{
$values = $this->postCommand('elements', $criteria);
$elements = array();
foreach ($values as $value) {
$elements[] = Element::fromResponseValue($value, $this->getSessionUrl()->descend('element'), $this->driver);
}
return $elements;
}
/**
* @param string $strategy
* @return ElementCriteria
*/
public function using($strategy)
{
return new ElementCriteria($strategy);
}
/**
* @return URL
*/
protected abstract function getSessionUrl();
/**
* @param string $strategy supported by JsonWireProtocol element/ command
* @param string $value
* @return Element
*/
private function by($strategy, $value)
{
return $this->element($this->using($strategy)->value($value));
}
}

View File

@ -0,0 +1,235 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.2
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\ElementCriteria;
/**
* Object representing a <select> element.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.2
*/
class Select extends Element
{
/**
* @return Select
*/
public static function fromElement(Element $element)
{
return new self($element->driver, $element->url);
}
/**
* @return string
*/
public function selectedLabel()
{
$selectedOption = $this->selectedOption();
if ($selectedOption === NULL) {
return '';
}
return $selectedOption->text();
}
/**
* @return string
*/
public function selectedValue()
{
$selectedOption = $this->selectedOption();
if ($selectedOption === NULL) {
return '';
}
return $selectedOption->value();
}
/**
* @return string
*/
public function selectedId()
{
$selectedOption = $this->selectedOption();
if ($selectedOption === NULL) {
return '';
}
return $selectedOption->attribute('id');
}
/**
* @return array
*/
public function selectedLabels()
{
$labels = array();
foreach ($this->selectedOptions() as $option) {
$labels[] = $option->text();
}
return $labels;
}
/**
* @return array
*/
public function selectedValues()
{
$values = array();
foreach ($this->selectedOptions() as $option) {
$values[] = $option->value();
}
return $values;
}
/**
* @return array
*/
public function selectedIds()
{
$id = array();
foreach ($this->selectedOptions() as $option) {
$values[] = $option->attribute('id');
}
return $id;
}
/**
* @param string $label the text appearing in the option
* @return void
*/
public function selectOptionByLabel($label)
{
$toSelect = $this->using('xpath')->value(".//option[.='$label']");
$this->selectOptionByCriteria($toSelect);
}
/**
* @param string $value the value attribute of the option
* @return void
*/
public function selectOptionByValue($value)
{
$toSelect = $this->using('xpath')->value(".//option[@value='$value']");
$this->selectOptionByCriteria($toSelect);
}
/**
* @param ElementCriteria $localCriteria condiotions for selecting an option
* @return void
*/
public function selectOptionByCriteria(ElementCriteria $localCriteria)
{
$option = $this->element($localCriteria);
if (!$option->selected()) {
$option->click();
}
}
/**
* @return array
*/
public function selectOptionValues()
{
$options = array();
foreach ($this->options() as $option) {
$options[] = $option->value();
}
return $options;
}
/**
* @return array
*/
public function selectOptionLabels()
{
$options = array();
foreach ($this->options() as $option) {
$options[] = $option->text();
}
return $options;
}
/***
* @return array
*/
private function selectedOptions()
{
$options = array();
foreach ($this->options() as $option) {
if ($option->selected()) {
$options[] = $option;
}
}
return $options;
}
public function clearSelectedOptions()
{
foreach ($this->selectedOptions() as $option) {
$option->click();
}
}
private function selectedOption()
{
foreach ($this->options() as $option) {
if ($option->selected()) {
return $option;
}
}
return NULL;
}
private function options()
{
$onlyTheOptions = $this->using('css selector')->value('option');
return $this->elements($onlyTheOptions);
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Retrieves an attribute of a DOM element.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Attribute extends Command
{
/**
* @param array $parameter
*/
public function __construct($parameter, URL $attributeResourceBaseUrl)
{
$this->jsonParameters = array();
$this->url = $attributeResourceBaseUrl->descend($parameter);
}
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Clicks ok on an alert popup.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Click extends Command
{
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Retrieves the value of a CSS property.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Css extends Command
{
/**
* @param array $propertyName
*/
public function __construct($propertyName, URL $cssResourceBaseUrl)
{
$this->jsonParameters = array();
$this->url = $cssResourceBaseUrl->descend($propertyName);
}
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use InvalidArgumentException;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Checks equality (same element on the page) with another DOM element.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Equals extends Command
{
/**
* @param array $parameter
*/
public function __construct($parameter, URL $equalsResourceBaseUrl)
{
$this->jsonParameters = array();
if (!($parameter instanceof Element)) {
throw new InvalidArgumentException("Elements can only test equality with other Element instances.");
}
$this->url = $equalsResourceBaseUrl->descend($parameter->getId());
}
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Class for implementing commands that just return a value
* (obtained with GET).
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class GenericAccessor extends Command
{
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2012 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Class for implementing commands that just accomplishes an action (via POST).
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2012 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class GenericPost extends Command
{
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Retrieves the element's coordinates
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Rect extends Command
{
/**
* @param array $parameter
*/
public function __construct($parameter, URL $attributeResourceBaseUrl)
{
$this->jsonParameters = array();
$this->url = $attributeResourceBaseUrl->descend($parameter);
}
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\ElementCommand;
use BadMethodCallException;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Keys;
/**
* Get and set the element's value attribute.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Value extends Keys
{
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
throw new BadMethodCallException("JSON Wire Protocol only supports POST to /value now. To get the value of an element GET /attribute/:naem should be used and this object should never be involved.");
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use ArrayObject;
/**
* Conditions for selecting a DOM element.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element
*/
class ElementCriteria extends ArrayObject
{
public function __construct($strategy)
{
$this['using'] = $strategy;
}
/**
* @return ElementCriteria
*/
public function value($searchTarget)
{
$this['value'] = $searchTarget;
return $this;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use RuntimeException;
/**
* Indicates an exception during the execution of Selenium 2 commands.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Exception extends RuntimeException
{
}

View File

@ -0,0 +1,116 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.12
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Class to hold the special keys Unicode entities
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.3.0
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
*/
class Keys
{
const NULL = "\xEE\x80\x80";
const CANCEL = "\xEE\x80\x81";
const HELP = "\xEE\x80\x82";
const BACKSPACE = "\xEE\x80\x83";
const TAB = "\xEE\x80\x84";
const CLEAR = "\xEE\x80\x85";
const RETURN_ = "\xEE\x80\x86";
const ENTER = "\xEE\x80\x87";
const SHIFT = "\xEE\x80\x88";
const CONTROL = "\xEE\x80\x89";
const ALT = "\xEE\x80\x8A";
const PAUSE = "\xEE\x80\x8B";
const ESCAPE = "\xEE\x80\x8C";
const SPACE = "\xEE\x80\x8D";
const PAGEUP = "\xEE\x80\x8E";
const PAGEDOWN = "\xEE\x80\x8F";
const END = "\xEE\x80\x90";
const HOME = "\xEE\x80\x91";
const LEFT = "\xEE\x80\x92";
const UP = "\xEE\x80\x93";
const RIGHT = "\xEE\x80\x94";
const DOWN = "\xEE\x80\x95";
const INSERT = "\xEE\x80\x96";
const DELETE = "\xEE\x80\x97";
const SEMICOLON = "\xEE\x80\x98";
const EQUALS = "\xEE\x80\x99";
const NUMPAD0 = "\xEE\x80\x9A";
const NUMPAD1 = "\xEE\x80\x9B";
const NUMPAD2 = "\xEE\x80\x9C";
const NUMPAD3 = "\xEE\x80\x9D";
const NUMPAD4 = "\xEE\x80\x9E";
const NUMPAD5 = "\xEE\x80\x9F";
const NUMPAD6 = "\xEE\x80\xA0";
const NUMPAD7 = "\xEE\x80\xA1";
const NUMPAD8 = "\xEE\x80\xA2";
const NUMPAD9 = "\xEE\x80\xA3";
const MULTIPLY = "\xEE\x80\xA4";
const ADD = "\xEE\x80\xA5";
const SEPARATOR = "\xEE\x80\xA6";
const SUBTRACT = "\xEE\x80\xA7";
const DECIMAL = "\xEE\x80\xA8";
const DIVIDE = "\xEE\x80\xA9";
const F1 = "\xEE\x80\xB1";
const F2 = "\xEE\x80\xB2";
const F3 = "\xEE\x80\xB3";
const F4 = "\xEE\x80\xB4";
const F5 = "\xEE\x80\xB5";
const F6 = "\xEE\x80\xB6";
const F7 = "\xEE\x80\xB7";
const F8 = "\xEE\x80\xB8";
const F9 = "\xEE\x80\xB9";
const F10 = "\xEE\x80\xBA";
const F11 = "\xEE\x80\xBB";
const F12 = "\xEE\x80\xBC";
const COMMAND = "\xEE\x80\xBD";
}

View File

@ -0,0 +1,129 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.12
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Class-mapper, that converts requested special key into correspondent Unicode character
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.12
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
*/
class KeysHolder
{
private $_keys = array(
'null' => "\xEE\x80\x80",
'cancel' => "\xEE\x80\x81",
'help' => "\xEE\x80\x82",
'backspace' => "\xEE\x80\x83",
'tab' => "\xEE\x80\x84",
'clear' => "\xEE\x80\x85",
'return' => "\xEE\x80\x86",
'enter' => "\xEE\x80\x87",
'shift' => "\xEE\x80\x88",
'control' => "\xEE\x80\x89",
'alt' => "\xEE\x80\x8A",
'pause' => "\xEE\x80\x8B",
'escape' => "\xEE\x80\x8C",
'space' => "\xEE\x80\x8D",
'pageup' => "\xEE\x80\x8E",
'pagedown' => "\xEE\x80\x8F",
'end' => "\xEE\x80\x90",
'home' => "\xEE\x80\x91",
'left' => "\xEE\x80\x92",
'up' => "\xEE\x80\x93",
'right' => "\xEE\x80\x94",
'down' => "\xEE\x80\x95",
'insert' => "\xEE\x80\x96",
'delete' => "\xEE\x80\x97",
'semicolon' => "\xEE\x80\x98",
'equals' => "\xEE\x80\x99",
'numpad0' => "\xEE\x80\x9A",
'numpad1' => "\xEE\x80\x9B",
'numpad2' => "\xEE\x80\x9C",
'numpad3' => "\xEE\x80\x9D",
'numpad4' => "\xEE\x80\x9E",
'numpad5' => "\xEE\x80\x9F",
'numpad6' => "\xEE\x80\xA0",
'numpad7' => "\xEE\x80\xA1",
'numpad8' => "\xEE\x80\xA2",
'numpad9' => "\xEE\x80\xA3",
'multiply' => "\xEE\x80\xA4",
'add' => "\xEE\x80\xA5",
'separator' => "\xEE\x80\xA6",
'subtract' => "\xEE\x80\xA7",
'decimal' => "\xEE\x80\xA8",
'divide' => "\xEE\x80\xA9",
'f1' => "\xEE\x80\xB1",
'f2' => "\xEE\x80\xB2",
'f3' => "\xEE\x80\xB3",
'f4' => "\xEE\x80\xB4",
'f5' => "\xEE\x80\xB5",
'f6' => "\xEE\x80\xB6",
'f7' => "\xEE\x80\xB7",
'f8' => "\xEE\x80\xB8",
'f9' => "\xEE\x80\xB9",
'f10' => "\xEE\x80\xBA",
'f11' => "\xEE\x80\xBB",
'f12' => "\xEE\x80\xBC",
'command' => "\xEE\x80\xBD",
);
public function specialKey($name)
{
$normalizedName = strtolower($name);
if (!isset($this->_keys[$normalizedName])) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception("There is no special key '$name' defined");
}
return $this->_keys[$normalizedName];
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.9
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.8
*/
class NoSeleniumException extends \PHPUnit\Extensions\Selenium2TestCase\Exception
{
}

View File

@ -0,0 +1,101 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Object representing an HTTP response from the Selenium Server.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Response
{
/**
* @var array decoded response
*/
private $jsonResponse;
/**
* @var array CURL info for the response.
*/
private $info;
public function __construct($jsonResponse, $info)
{
$this->jsonResponse = $jsonResponse;
$this->info = $info;
}
public function getValue()
{
if (isset($this->jsonResponse['value'])) {
return $this->jsonResponse['value'];
}
}
/**
* @return URL
*/
public function getURL()
{
$url = $this->info['url'];
$sessionId = $this->jsonResponse['sessionId'];
// if url doesn't have sessionId included - append it manually
// this change was performed in selenium v2.34
// @see https://code.google.com/p/selenium/issues/detail?id=6089
// @see https://github.com/sebastianbergmann/phpunit-selenium/issues/265
if (strpos($url, $sessionId) === FALSE) {
$url .= '/' . $sessionId;
}
return new URL($url);
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.8
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use PHPUnit\Extensions\Selenium2TestCase;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use Throwable;
/**
* Base class for implementing commands with special semantics.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.8
*/
class ScreenshotListener implements TestListener
{
use TestListenerDefaultImplementation;
private $directory;
public function __construct($directory)
{
$this->directory = $directory;
}
public function addError(Test $test, Throwable $e, float $time): void
{
$this->storeAScreenshot($test);
}
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->storeAScreenshot($test);
}
private function storeAScreenshot(Test $test)
{
if ($test instanceof Selenium2TestCase)
{
$className = str_replace('\\', '_', get_class($test));
try {
$file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.png';
file_put_contents($file, $test->currentScreenshot());
} catch (\Exception $e) {
$file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.txt';
file_put_contents($file, "Screenshot generation doesn't work." . "\n"
. $e->getMessage() . "\n"
. $e->getTraceAsString());
}
}
}
}

View File

@ -0,0 +1,326 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use InvalidArgumentException;
use PHPUnit\Extensions\Selenium2TestCase\Element\Accessor;
use PHPUnit\Extensions\Selenium2TestCase\Element\Select;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericAccessor;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericPost;
use PHPUnit\Extensions\Selenium2TestCase\Session\Cookie;
use PHPUnit\Extensions\Selenium2TestCase\Session\Storage;
use PHPUnit\Extensions\Selenium2TestCase\Session\Timeouts;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\AcceptAlert;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Active;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\AlertText;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Click;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\DismissAlert;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\File;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Frame;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\GenericAccessor as SessionGenericAccessor;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\GenericAttribute;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Keys as SessionKeys;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Location;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Log;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\MoveTo;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Orientation;
use PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Window as SessionWindow;
/**
* Browser session for Selenium 2: main point of entry for functionality.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
* @method void acceptAlert() Press OK on an alert, or confirms a dialog
* @method mixed alertText($value = NULL) Gets the alert dialog text, or sets the text for a prompt dialog
* @method void back()
* @method void dismissAlert() Press Cancel on an alert, or does not confirm a dialog
* @method void doubleclick() Double-clicks at the current mouse coordinates (set by moveto).
* @method string execute(array $javaScriptCode) Injects arbitrary JavaScript in the page and returns the last. See unit tests for usage
* @method string executeAsync(array $javaScriptCode) Injects arbitrary JavaScript and wait for the callback (last element of arguments) to be called. See unit tests for usage
* @method void forward()
* @method void frame(mixed $element) Changes the focus to a frame in the page (by frameCount of type int, htmlId of type string, htmlName of type string or element of type Element)
* @method void moveto(Element $element) Move the mouse by an offset of the specificed element.
* @method void refresh()
* @method string source() Returns the HTML source of the page
* @method string title()
* @method void|string url($url = NULL)
* @method void window($name) Changes the focus to another window
* @method string windowHandle() Retrieves the current window handle
* @method string windowHandles() Retrieves a list of all available window handles
* @method string keys() Send a sequence of key strokes to the active element.
* @method string file($file_path) Upload a local file. Returns the fully qualified path to the transferred file.
* @method array log(string $type) Get the log for a given log type. Log buffer is reset after each request.
* @method array logTypes() Get available log types.
*/
class Session extends Accessor
{
/**
* @var string the base URL for this session,
* which all relative URLs will refer to
*/
private $baseUrl;
/**
* @var Timeouts
*/
private $timeouts;
/**
* @var boolean
*/
private $stopped = FALSE;
public function __construct($driver,
URL $url,
URL $baseUrl,
Timeouts $timeouts)
{
$this->baseUrl = $baseUrl;
$this->timeouts = $timeouts;
parent::__construct($driver, $url);
}
/**
* @return string
*/
public function id()
{
return $this->url->lastSegment();
}
protected function initCommands()
{
$baseUrl = $this->baseUrl;
return array(
'acceptAlert' => AcceptAlert::class,
'alertText' => AlertText::class,
'back' => GenericPost::class,
'click' => Click::class,
'buttondown' => GenericPost::class,
'buttonup' => GenericPost::class,
'dismissAlert' => DismissAlert::class,
'doubleclick' => GenericPost::class,
'execute' => GenericPost::class,
'executeAsync' => GenericPost::class,
'forward' => GenericPost::class,
'frame' => Frame::class,
'keys' => SessionKeys::class,
'moveto' => MoveTo::class,
'refresh' => GenericPost::class,
'screenshot' => GenericAccessor::class,
'source' => SessionGenericAccessor::class,
'title' => SessionGenericAccessor::class,
'log' => Log::class,
'logTypes' => $this->attributeCommandFactoryMethod('log/types'),
'url' => function ($jsonParameters, $commandUrl) use ($baseUrl) {
return new \PHPUnit\Extensions\Selenium2TestCase\SessionCommand\Url($jsonParameters, $commandUrl, $baseUrl);
},
'window' => SessionWindow::class,
'windowHandle' => SessionGenericAccessor::class,
'windowHandles' => SessionGenericAccessor::class,
'touchDown' => $this->touchCommandFactoryMethod('touch/down'),
'touchUp' => $this->touchCommandFactoryMethod('touch/up'),
'touchMove' => $this->touchCommandFactoryMethod('touch/move'),
'touchScroll' => $this->touchCommandFactoryMethod('touch/scroll'),
'flick' => $this->touchCommandFactoryMethod('touch/flick'),
'location' => Location::class,
'orientation' => Orientation::class,
'file' => File::class
);
}
private function attributeCommandFactoryMethod($urlSegment)
{
$url = $this->url->addCommand($urlSegment);
return function ($jsonParameters, $commandUrl) use ($url) {
return new GenericAttribute($jsonParameters, $url);
};
}
private function touchCommandFactoryMethod($urlSegment)
{
$url = $this->url->addCommand($urlSegment);
return function ($jsonParameters, $commandUrl) use ($url) {
return new GenericPost($jsonParameters, $url);
};
}
public function __destruct()
{
$this->stop();
}
/**
* @return URL
*/
public function getSessionUrl()
{
return $this->url;
}
/**
* Closed the browser.
* @return void
*/
public function stop()
{
if ($this->stopped) {
return;
}
try {
$this->driver->curl('DELETE', $this->url);
} catch (Exception $e) {
// sessions which aren't closed because of sharing can time out on the server. In no way trying to close them should make a test fail, as it already finished before arriving here.
"Closing sessions: " . $e->getMessage() . "\n";
}
$this->stopped = TRUE;
if ($this->stopped) {
return;
}
}
/**
* @return Select
*/
public function select(Element $element)
{
$tag = $element->name();
if ($tag !== 'select') {
throw new InvalidArgumentException("The element is not a `select` tag but a `$tag`.");
}
return Select::fromElement($element);
}
/**
* @param array WebElement JSON object
* @return Element
*/
public function elementFromResponseValue($value)
{
return Element::fromResponseValue($value, $this->getSessionUrl()->descend('element'), $this->driver);
}
/**
* @param string $id id attribute, e.g. 'container'
* @return void
*/
public function clickOnElement($id)
{
return $this->element($this->using('id')->value($id))->click();
}
public function timeouts()
{
return $this->timeouts;
}
/**
* @return string a BLOB of a PNG file
*/
public function currentScreenshot()
{
return base64_decode($this->screenshot());
}
/**
* @return Window
*/
public function currentWindow()
{
$url = $this->url->descend('window')->descend(trim($this->windowHandle(), '{}'));
return new Window($this->driver, $url);
}
public function closeWindow()
{
$this->driver->curl('DELETE', $this->url->descend('window'));
}
/**
* Get the element on the page that currently has focus.
*
* @return Element
*/
public function active()
{
$command = new Active(null, $this->url);
$response = $this->driver->execute($command);
return $this->elementFromResponseValue($response->getValue());
}
/**
* @return Cookie
*/
public function cookie()
{
$url = $this->url->descend('cookie');
return new Cookie($this->driver, $url);
}
/**
* @return Storage
*/
public function localStorage()
{
$url = $this->url->addCommand('localStorage');
return new Storage($this->driver, $url);
}
public function landscape()
{
$this->orientation('LANDSCAPE');
}
public function portrait()
{
$this->orientation('PORTRAIT');
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\Driver;
use PHPUnit\Extensions\Selenium2TestCase\Session\Cookie\Builder;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Adds and remove cookies.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Cookie
{
private $driver;
private $url;
public function __construct(Driver $driver, URL $url)
{
$this->driver = $driver;
$this->url = $url;
}
/**
* @param string $name
* @param string $value
* @return Builder
*/
public function add($name, $value)
{
return new Builder($this, $name, $value);
}
/**
* @param string $name
* @return string
*/
public function get($name)
{
$cookies = $this->driver->curl('GET', $this->url)->getValue();
foreach ($cookies as $cookie) {
if ($cookie['name'] == $name) {
return $cookie['value'];
}
}
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception("There is no '$name' cookie available on this page.");
}
/**
* @param string $name
* @return void
*/
public function remove($name)
{
$url = $this->url->descend($name);
$this->driver->curl('DELETE', $url);
}
/**
* @return void
*/
public function clear()
{
$this->driver->curl('DELETE', $this->url);
}
/**
* @internal
* @param array $data
* @return void
*/
public function postCookie(array $data)
{
$this->driver->curl('POST',
$this->url,
array(
'cookie' => $data
));
}
}

View File

@ -0,0 +1,131 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Session\Cookie;
/**
* Adds a cookie.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Builder
{
private $name;
private $value;
private $path;
private $domain;
private $secure = FALSE;
private $expiry;
public function __construct($cookieFacade, $name, $value)
{
$this->cookieFacade = $cookieFacade;
$this->name = $name;
$this->value = $value;
}
/**
* @param string
* @return Builder
*/
public function path($path)
{
$this->path = $path;
return $this;
}
/**
* @param string
* @return Builder
*/
public function domain($domain)
{
$this->domain = $domain;
return $this;
}
/**
* @param boolean
* @return Builder
*/
public function secure($secure)
{
$this->secure = $secure;
return $this;
}
/**
* @param integer
* @return Builder
*/
public function expiry($expiry)
{
$this->expiry = $expiry;
return $this;
}
/**
* @return void
*/
public function set()
{
$cookieData = array(
'name' => $this->name,
'value' => $this->value,
'secure' => $this->secure,
);
foreach (array('path', 'domain', 'expiry') as $parameter) {
if ($this->$parameter !== NULL) {
$cookieData[$parameter] = $this->$parameter;
}
}
$this->cookieFacade->postCookie($cookieData);
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\Driver;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Manage the local storage HTML 5 database.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Storage
{
private $driver;
private $url;
public function __construct(Driver $driver, URL $url)
{
$this->driver = $driver;
$this->url = $url;
}
public function __set($name, $value)
{
$this->driver->curl('POST', $this->url, array(
'key' => $name,
'value' => (string)$value
));
}
public function __get($name)
{
return $this->driver->curl(
'GET',
$this->url->descend('key')->descend($name)
)->getValue();
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\CommandsHolder;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericPost;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Manages timeouts for the current browser session.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
* @method implicitWait(int $ms) Sets timeout when searching for elements
* @method asyncScript(int $ms) Sets timeout for asynchronous scripts executed by Session::executeAsync()
*/
class Timeouts extends CommandsHolder
{
private $maximumTimeout;
private $lastImplicitWaitValue = 0;
public function __construct($driver, URL $url, $maximumTimeout)
{
parent::__construct($driver, $url);
$this->maximumTimeout = $maximumTimeout;
}
protected function initCommands()
{
$self = $this;
return array(
'implicitWait' => function ($milliseconds, $commandUrl) use ($self) {
$self->check($milliseconds);
$self->setLastImplicitWaitValue($milliseconds);
$jsonParameters = array('ms' => $milliseconds);
return new GenericPost($jsonParameters, $commandUrl);
},
'asyncScript' => function ($milliseconds, $commandUrl) use ($self) {
$self->check($milliseconds);
$jsonParameters = array('ms' => $milliseconds);
return new GenericPost($jsonParameters, $commandUrl);
},
);
}
public function setLastImplicitWaitValue($implicitWait)
{
$this->lastImplicitWaitValue = $implicitWait;
}
public function getLastImplicitWaitValue()
{
return $this->lastImplicitWaitValue;
}
public function check($timeout)
{
if ($timeout > $this->maximumTimeout) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception('There is no use in setting this timeout unless you also call $this->setSeleniumServerRequestsTimeout($seconds) in setUp().');
}
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Clicks Ok on an alert popup.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class AcceptAlert extends Command
{
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Gets the active element from the session
*
* @package PHPUnit_Selenium
* @author Marcel Erz <marcel.erz@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release
*/
class Active extends Command
{
public function __construct($jsonParameters, URL $url)
{
$url = $url->addCommand('element')->addCommand('active');
parent::__construct($jsonParameters, $url);
}
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use BadMethodCallException;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Obtains the text of an alert, or types into a prompt.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class AlertText extends Command
{
public function __construct($argument, URL $url)
{
if (is_string($argument)) {
$jsonParameters =array('text' => $argument);
} else if ($argument == NULL) {
$jsonParameters = NULL;
} else {
throw new BadMethodCallException('Wrong parameters for alertText().');
}
parent::__construct($jsonParameters, $url);
}
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.13
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use BadMethodCallException;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Sends session click command for emulating LEFT, MIDDLE or RIGHT mouse buttons
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.13
*/
class Click extends Command
{
const LEFT = 0;
const MIDDLE = 1;
const RIGHT = 2;
public function __construct($argument, URL $url)
{
if (is_null($argument)) {
$jsonParameters = NULL;
} elseif (!is_scalar($argument) || !in_array($argument, array(
self::LEFT, self::RIGHT, self::MIDDLE
))) {
throw new BadMethodCallException('Wrong parameter for click(): expecting 0, 1 or 2.');
} else {
$jsonParameters = array('button' => $argument);
}
parent::__construct($jsonParameters, $url);
}
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Clicks Cancel on an alert popup.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class DismissAlert extends Command
{
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,154 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.3.2
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use BadMethodCallException;
use Exception;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
use ZipArchive;
/**
* Sends a file to a RC
* Returns the FQ path to the transfered file
*
* @package PHPUnit_Selenium
* @author Kevin Ran <heilong24@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.3.2
*/
class File extends Command
{
/**
* @var
*/
private static $_zipArchive;
public function __construct($argument, URL $url)
{
if (!is_file($argument)) {
throw new BadMethodCallException("No such file: {$argument}");
}
$zipfile_path = $this->_zipArchiveFile($argument);
$contents = file_get_contents($zipfile_path);
if ($contents === false) {
throw new Exception("Unable to read generated zip file: {$zipfile_path}");
}
$file = base64_encode($contents);
parent::__construct(array('file' => $file), $url);
unlink($zipfile_path);
}
public function httpMethod()
{
return 'POST';
}
/**
* Creates a zip archive with the given file
*
* @param string $file_path FQ path to file
* @return string Generated zip file
*/
protected function _zipArchiveFile( $file_path )
{
// file MUST be readable
if( !is_readable( $file_path ) ) {
throw new Exception( "Unable to read {$file_path}" );
} // if !file_data
$filename_hash = sha1( time() . $file_path );
$tmp_dir = $this->_getTmpDir();
$zip_filename = "{$tmp_dir}{$filename_hash}.zip";
$zip = $this->_getZipArchiver();
if ($zip->open($zip_filename, ZIPARCHIVE::CREATE) === FALSE) {
throw new Exception( "Unable to create zip archive: {$zip_filename}" );
}
$zip->addFile($file_path, basename($file_path));
$zip->close();
return $zip_filename;
}
/**
* Returns a runtime instance of a ZipArchive
*
* @return ZipArchive
*/
protected function _getZipArchiver()
{
// create ZipArchive if necessary
if (!static::$_zipArchive) {
static::$_zipArchive = new ZipArchive();
}
return static::$_zipArchive;
}
/**
* Calls sys_get_temp_dir and ensures that it has a trailing slash
* ( behavior varies across systems )
*
* @return string
*/
protected function _getTmpDir()
{
return rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\Element;
/**
* Changes the focus to a frame.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Frame extends Command
{
public function __construct($id, $commandUrl)
{
$jsonParameters = array(
'id' => $this->extractId($id)
);
parent::__construct($jsonParameters, $commandUrl);
}
/**
* @param $id
* @return array
*/
private function extractId($id)
{
if ($this->isElement($id)) { //selenium-element
return $id->toWebDriverObject();
}
//html-id or null
return $id;
}
/**
* @param $id
* @return bool
*/
private function isElement($id)
{
return $id instanceof Element;
}
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Gets an attribute from the session (title, alert text, etc.)
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class GenericAccessor extends Command
{
public function httpMethod()
{
return 'GET';
}
}

View File

@ -0,0 +1,69 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Gets or posts an attribute from/to the session (title, alert text, etc.)
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.9
*/
class GenericAttribute extends Command
{
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Christian Soronellas <csoronellas@emagister.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use InvalidArgumentException;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Gets or sets the current URL of the window.
*
* @package PHPUnit_Selenium
* @author Christian Soronellas <csoronellas@emagister.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Keys extends Command
{
public function __construct($jsonParameters, URL $url)
{
if ($jsonParameters === NULL) {
parent::__construct(NULL, $url);
} else {
$jsonParameters = $this->keysForText($jsonParameters);
parent::__construct($jsonParameters, $url);
}
}
/**
* @return string
*/
public function httpMethod()
{
return 'POST';
}
/**
* Given a string returns an array of the characters that compose the string
*
* @param string $text
* @throws InvalidArgumentException
* @return array
*/
public function keysForText($text)
{
if (is_scalar($text)) {
return array('value' => preg_split('//u', (string) $text, -1, PREG_SPLIT_NO_EMPTY));
}
if (is_array($text)) {
return $text;
}
throw new InvalidArgumentException('The "text" argument should be a string or an array of special characters!');
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
/**
* Gets or posts an attribute from/to the session (title, alert text, etc.)
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.9
*/
class Location extends GenericAttribute
{
public function __construct($location, $commandUrl)
{
if ($location !== NULL) {
$jsonParameters = array('location' => $location);
} else {
$jsonParameters = NULL;
}
parent::__construct($jsonParameters, $commandUrl);
}
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Andrew Krasichkov <krasichkovandrew@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.3.2
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Get the log for a given log type. Log buffer is reset after each request.
*
* @package PHPUnit_Selenium
* @author Andrew Krasichkov <krasichkovandrew@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.3.2
*/
class Log extends Command
{
public function __construct($type, $commandUrl)
{
$jsonParameters = array('type' => $type);
parent::__construct($jsonParameters, $commandUrl);
}
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,104 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.8
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\Element;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Moves the mouse pointer.
*
* @author Giorgio Sironi <info@giorgiosironi.com>
* @package PHPUnit_Selenium
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.8
*/
class MoveTo extends Command
{
public function __construct($element, URL $url)
{
if (!is_array($element)) {
$element = array(
'element' => $element,
);
}
$validKeys = array(
'element' => NULL,
'xoffset' => NULL,
'yoffset' => NULL,
);
$jsonParameters = array_intersect_key($element, $validKeys);
if (isset($jsonParameters['element'])) {
if (!($jsonParameters['element'] instanceof Element)) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception(sprintf('Only moving over an element is supported. Please pass a \'%s\' instance.', Element::class));
}
$jsonParameters['element'] = $jsonParameters['element']->getId();
}
if (isset($jsonParameters['xoffset']) || isset($jsonParameters['yoffset'])) {
// @see https://github.com/sebastianbergmann/phpunit-selenium/pull/250#issuecomment-21308153
// @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto
error_log('Even though this method is a part of the WebDriver Wire protocol it might be not supported by your browser yet');
}
parent::__construct($jsonParameters, $url);
}
/**
* @return string
*/
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
/**
* Gets or posts an attribute from/to the session (title, alert text, etc.)
*
* @package PHPUnit_Selenium
* @author Jonathan Lipps <jlipps@gmail.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.9
*/
class Orientation extends GenericAttribute
{
public function __construct($orientation, $commandUrl)
{
if ($orientation !== NULL) {
$jsonParameters = array('orientation' => $orientation);
} else {
$jsonParameters = NULL;
}
parent::__construct($jsonParameters, $commandUrl);
}
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
use PHPUnit\Extensions\Selenium2TestCase\URL as SeleniumURL;
/**
* Gets or sets the current URL of the window.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class Url extends Command
{
public function __construct($url, $commandUrl, SeleniumURL $baseUrl)
{
if ($url !== NULL) {
$absoluteLocation = $baseUrl->jump($url)->getValue();
$jsonParameters = array('url' => $absoluteLocation);
} else {
$jsonParameters = NULL;
}
parent::__construct($jsonParameters, $commandUrl);
}
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionCommand;
use PHPUnit\Extensions\Selenium2TestCase\Command;
/**
* Changes the focus to a window.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class Window extends Command
{
public function __construct($name, $commandUrl)
{
$jsonParameters = array('name' => $name);
parent::__construct($jsonParameters, $commandUrl);
}
public function httpMethod()
{
return 'POST';
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Specifies how to create Session objects for running tests.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
interface SessionStrategy
{
/**
* @param array $parameters 'host' => Selenium Server machine
'port' => Selenium Server port
'secure' => Selenium Server secure flag
'browser' => a browser name
* 'browserUrl' => base URL to use during the test
*/
public function session(array $parameters);
public function notSuccessfulTest();
public function endOfTest(Session $session = NULL);
}

View File

@ -0,0 +1,87 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionStrategy;
use PHPUnit\Extensions\Selenium2TestCase\Driver;
use PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\SessionStrategy;
use PHPUnit\Extensions\Selenium2TestCase\URL;
/**
* Produces a new Session object shared for each test.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Isolated implements SessionStrategy
{
public function session(array $parameters)
{
$seleniumServerUrl = URL::fromHostAndPort($parameters['host'], $parameters['port'], $parameters['secure']);
$driver = new Driver($seleniumServerUrl, $parameters['seleniumServerRequestsTimeout']);
$capabilities = array_merge($parameters['desiredCapabilities'],
array(
'browserName' => $parameters['browserName']
));
$session = $driver->startSession($capabilities, $parameters['browserUrl']);
return $session;
}
public function notSuccessfulTest()
{
}
public function endOfTest(Session $session = NULL)
{
if ($session !== NULL) {
$session->stop();
}
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions\Selenium2TestCase\SessionStrategy;
use PHPUnit\Extensions\Selenium2TestCase\Session;
use PHPUnit\Extensions\Selenium2TestCase\SessionStrategy;
/**
* Keeps a Session object shared between test runs to save time.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class Shared implements SessionStrategy
{
private $original;
private $session;
private $mainWindow;
private $lastTestWasNotSuccessful = FALSE;
private $keepSessionOnFailure;
public function __construct(SessionStrategy $originalStrategy, $keepSessionOnFailure)
{
$this->original = $originalStrategy;
$this->keepSessionOnFailure = $keepSessionOnFailure;
}
public function session(array $parameters)
{
if ($this->lastTestWasNotSuccessful && !$this->keepSessionOnFailure) {
if ($this->session !== NULL) {
$this->session->stop();
$this->session = NULL;
}
$this->lastTestWasNotSuccessful = FALSE;
}
if ($this->session === NULL) {
$this->session = $this->original->session($parameters);
$this->mainWindow = $this->session->windowHandle();
} else {
$this->session->window($this->mainWindow);
}
return $this->session;
}
public function notSuccessfulTest()
{
$this->lastTestWasNotSuccessful = TRUE;
}
public function endOfTest(Session $session = NULL)
{
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.5
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Gets or sets an attribute of an object.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.5
*/
class StateCommand extends Command
{
public function httpMethod()
{
if ($this->jsonParameters) {
return 'POST';
}
return 'GET';
}
}

View File

@ -0,0 +1,172 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.0
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* URL Value Object allowing easy concatenation.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
final class URL
{
/**
* @var string
*/
private $value;
/**
* @param string $value
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* @param string $host
* @param int port
* @param bool secure
* @return URL
*/
public static function fromHostAndPort($host, $port, $secure)
{
$prefix = "http://";
if ($secure) {
$prefix = "https://";
}
return new self($prefix.$host.":".$port);
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
public function __toString()
{
return $this->getValue();
}
/**
* @param string $addition
* @return URL
*/
public function descend($addition)
{
if ($addition == '') {
// if we're adding nothing, respect the current url's choice of
// whether or not to include a trailing slash; prevents inadvertent
// adding of slashes to urls that can't handle it
$newValue = $this->value;
} else {
$newValue = rtrim($this->value, '/')
. '/'
. ltrim($addition, '/');
}
return new self($newValue);
}
/**
* @return URL
*/
public function ascend()
{
$lastSlash = strrpos($this->value, "/");
$newValue = substr($this->value, 0, $lastSlash);
return new self($newValue);
}
/**
* @return string
*/
public function lastSegment()
{
$segments = explode('/', $this->value);
return end($segments);
}
/**
* @param string $command
* @return URL
*/
public function addCommand($command)
{
return $this->descend($this->camelCaseToUnderScores($command));
}
/**
* @param string $newUrl
* @return URL
*/
public function jump($newUrl)
{
if ($this->isAbsolute($newUrl)) {
return new self($newUrl);
} else {
return $this->descend($newUrl);
}
}
private function camelCaseToUnderScores($string)
{
$string = preg_replace('/([A-Z]{1,1})/', ' \1', $string);
$string = strtolower($string);
return str_replace(' ', '_', $string);
}
private function isAbsolute($urlValue)
{
return preg_match('/^(http|https):\/\//', $urlValue) > 0;
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.12
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use PHPUnit\Extensions\Selenium2TestCase;
/**
* The WaitUntil implementation, inspired by Java and .NET clients
*
* @package PHPUnit_Selenium
* @author Ivan Kurnosov <zerkms@zerkms.com>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.12
* @see http://selenium.googlecode.com/svn/trunk/dotnet/src/WebDriver.Support/UI/WebDriverWait.cs
* @see http://selenium.googlecode.com/svn/trunk/java/client/src/org/openqa/selenium/support/ui/FluentWait.java
*/
class WaitUntil
{
/**
* PHPUnit Test Case instance
*
* @var Selenium2TestCase
*/
private $_testCase;
/**
* @param Selenium2TestCase $testCase
*/
public function __construct(Selenium2TestCase $testCase)
{
$this->_testCase = $testCase;
}
/**
* @param $callback Callback to run until it returns not null or timeout occurs
* @param null|int $timeout
* @param null|int $sleepInterval the delay between 2 iterations of the callback
* @return mixed
* @throws \PHPUnit\Extensions\Selenium2TestCase\Exception
* @throws WebDriverException
*/
public function run($callback, $timeout = NULL, $sleepInterval = NULL)
{
if (!is_callable($callback)) {
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception('The valid callback is expected');
}
// if there was an implicit timeout specified - remember it and temporarily turn it off
$implicitWait = $this->_testCase->timeouts()->getLastImplicitWaitValue();
if ($implicitWait) {
$this->_testCase->timeouts()->implicitWait(0);
}
if(is_null($sleepInterval)){
$sleepInterval = Selenium2TestCase::defaultWaitUntilSleepInterval();
}
$sleepInterval *= 1000;
if (is_null($timeout)) {
$timeout = Selenium2TestCase::defaultWaitUntilTimeout();
}
$timeout /= 1000;
$endTime = microtime(TRUE) + $timeout;
$lastException = NULL;
while (TRUE) {
try {
$result = call_user_func($callback, $this->_testCase);
if (!is_null($result)) {
if ($implicitWait) {
$this->_testCase->timeouts()->implicitWait($implicitWait);
}
return $result;
}
} catch(\Exception $e) {
$lastException = $e;
}
if (microtime(TRUE) > $endTime) {
if ($implicitWait) {
$this->_testCase->timeouts()->implicitWait($implicitWait);
}
$message = "Timed out after {$timeout} second" . ($timeout != 1 ? 's' : '');
throw new WebDriverException($message, WebDriverException::Timeout, $lastException);
}
usleep($sleepInterval);
}
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Christian Becker <chris@beckr.org>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
/**
* Indicates an exception as a result of a non-sucessful WebDriver response status code.
*
* @package PHPUnit_Selenium
* @author Christian Becker <chris@beckr.org>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since
*/
class WebDriverException extends \PHPUnit\Extensions\Selenium2TestCase\Exception
{
/* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes */
const Success = 0;
const NoSuchDriver = 6;
const NoSuchElement = 7;
const NoSuchFrame = 8;
const UnknownCommand = 9;
const StaleElementReference = 10;
const ElementNotVisible = 11;
const InvalidElementState = 12;
const UnknownError = 13;
const ElementIsNotSelectable = 15;
const JavaScriptError = 17;
const XPathLookupError = 19;
const Timeout = 21;
const NoSuchWindow = 23;
const InvalidCookieDomain = 24;
const UnableToSetCookie = 25;
const UnexpectedAlertOpen = 26;
const NoAlertOpenError = 27;
const ScriptTimeout = 28;
const InvalidElementCoordinates = 29;
const IMENotAvailable = 30;
const IMEEngineActivationFailed = 31;
const InvalidSelector = 32;
const SessionNotCreatedException = 33;
const MoveTargetOutOfBounds = 34;
}

View File

@ -0,0 +1,77 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.5
*/
namespace PHPUnit\Extensions\Selenium2TestCase;
use PHPUnit\Extensions\Selenium2TestCase\ElementCommand\GenericPost;
/**
* Object representing a browser window.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.5
* @method array size(array $size = null) Window size as array('width' => $x, 'height' => $y)
* @method array position(array $position = null) Window position as array('x' => $x, 'y' => $y)
* @method array maximize() Maximize window
*/
class Window extends CommandsHolder
{
/**
* @return array class names
*/
protected function initCommands()
{
return array(
'size' => StateCommand::class,
'position' => StateCommand::class,
'maximize' => GenericPost::class,
);
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.6
*/
namespace PHPUnit\Extensions;
use PHPUnit\Framework\TestSuite;
use ReflectionClass;
use ReflectionMethod;
/**
* TestSuite class for a set of tests from a single Testcase Class
* executed with a particular browser.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.6
*/
class SeleniumBrowserSuite extends TestSuite
{
/**
* Overriding the default: Selenium suites are always built from a TestCase class.
* @var boolean
*/
protected $testCase = TRUE;
public function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
{
parent::addTestMethod($class, $method);
}
public static function fromClassAndBrowser($className, array $browser)
{
$browserSuite = new self();
if (isset($browser['browserName'])) {
$name = $browser['browserName'];
} else if (isset($browser['name'])) {
$name = $browser['name'];
} else {
$name = $browser['browser'];
}
$browserSuite->setName($className . ': ' . $name);
return $browserSuite;
}
public function setupSpecificBrowser(array $browser)
{
$this->browserOnAllTests($this, $browser);
}
private function browserOnAllTests(TestSuite $suite, array $browser)
{
foreach ($suite->tests() as $test) {
if ($test instanceof TestSuite) {
$this->browserOnAllTests($test, $browser);
} else {
$test->setupSpecificBrowser($browser);
}
}
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2002-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2002-2010 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.1.0
*/
require_once 'File/Iterator/Autoload.php';
spl_autoload_register(
function ($class) {
static $classes = NULL;
static $path = NULL;
if ($classes === NULL) {
$classes = array(
'phpunit_extensions_selenium2testcase' => '/Extensions/Selenium2TestCase.php',
'phpunit_extensions_selenium2testcase_command' => '/Extensions/Selenium2TestCase/Command.php',
'phpunit_extensions_selenium2testcase_commandsholder' => '/Extensions/Selenium2TestCase/CommandsHolder.php',
'phpunit_extensions_selenium2testcase_driver' => '/Extensions/Selenium2TestCase/Driver.php',
'phpunit_extensions_selenium2testcase_element' => '/Extensions/Selenium2TestCase/Element.php',
'phpunit_extensions_selenium2testcase_element_accessor' => '/Extensions/Selenium2TestCase/Element/Accessor.php',
'phpunit_extensions_selenium2testcase_element_select' => '/Extensions/Selenium2TestCase/Element/Select.php',
'phpunit_extensions_selenium2testcase_elementcommand_attribute' => '/Extensions/Selenium2TestCase/ElementCommand/Attribute.php',
'phpunit_extensions_selenium2testcase_elementcommand_click' => '/Extensions/Selenium2TestCase/ElementCommand/Click.php',
'phpunit_extensions_selenium2testcase_elementcommand_css' => '/Extensions/Selenium2TestCase/ElementCommand/Css.php',
'phpunit_extensions_selenium2testcase_elementcommand_equals' => '/Extensions/Selenium2TestCase/ElementCommand/Equals.php',
'phpunit_extensions_selenium2testcase_elementcommand_genericaccessor' => '/Extensions/Selenium2TestCase/ElementCommand/GenericAccessor.php',
'phpunit_extensions_selenium2testcase_elementcommand_genericpost' => '/Extensions/Selenium2TestCase/ElementCommand/GenericPost.php',
'phpunit_extensions_selenium2testcase_elementcommand_value' => '/Extensions/Selenium2TestCase/ElementCommand/Value.php',
'phpunit_extensions_selenium2testcase_elementcriteria' => '/Extensions/Selenium2TestCase/ElementCriteria.php',
'phpunit_extensions_selenium2testcase_exception' => '/Extensions/Selenium2TestCase/Exception.php',
'phpunit_extensions_selenium2testcase_keys' => '/Extensions/Selenium2TestCase/Keys.php',
'phpunit_extensions_selenium2testcase_keysholder' => '/Extensions/Selenium2TestCase/KeysHolder.php',
'phpunit_extensions_selenium2testcase_noseleniumexception' => '/Extensions/Selenium2TestCase/NoSeleniumException.php',
'phpunit_extensions_selenium2testcase_response' => '/Extensions/Selenium2TestCase/Response.php',
'phpunit_extensions_selenium2testcase_screenshotlistener' => '/Extensions/Selenium2TestCase/ScreenshotListener.php',
'phpunit_extensions_selenium2testcase_session' => '/Extensions/Selenium2TestCase/Session.php',
'phpunit_extensions_selenium2testcase_session_cookie' => '/Extensions/Selenium2TestCase/Session/Cookie.php',
'phpunit_extensions_selenium2testcase_session_cookie_builder' => '/Extensions/Selenium2TestCase/Session/Cookie/Builder.php',
'phpunit_extensions_selenium2testcase_session_storage' => '/Extensions/Selenium2TestCase/Session/Storage.php',
'phpunit_extensions_selenium2testcase_session_timeouts' => '/Extensions/Selenium2TestCase/Session/Timeouts.php',
'phpunit_extensions_selenium2testcase_sessioncommand_acceptalert' => '/Extensions/Selenium2TestCase/SessionCommand/AcceptAlert.php',
'phpunit_extensions_selenium2testcase_sessioncommand_active' => '/Extensions/Selenium2TestCase/SessionCommand/Active.php',
'phpunit_extensions_selenium2testcase_sessioncommand_alerttext' => '/Extensions/Selenium2TestCase/SessionCommand/AlertText.php',
'phpunit_extensions_selenium2testcase_sessioncommand_click' => '/Extensions/Selenium2TestCase/SessionCommand/Click.php',
'phpunit_extensions_selenium2testcase_sessioncommand_dismissalert' => '/Extensions/Selenium2TestCase/SessionCommand/DismissAlert.php',
'phpunit_extensions_selenium2testcase_sessioncommand_file' => '/Extensions/Selenium2TestCase/SessionCommand/File.php',
'phpunit_extensions_selenium2testcase_sessioncommand_frame' => '/Extensions/Selenium2TestCase/SessionCommand/Frame.php',
'phpunit_extensions_selenium2testcase_sessioncommand_genericaccessor' => '/Extensions/Selenium2TestCase/SessionCommand/GenericAccessor.php',
'phpunit_extensions_selenium2testcase_sessioncommand_genericattribute' => '/Extensions/Selenium2TestCase/SessionCommand/GenericAttribute.php',
'phpunit_extensions_selenium2testcase_sessioncommand_keys' => '/Extensions/Selenium2TestCase/SessionCommand/Keys.php',
'phpunit_extensions_selenium2testcase_sessioncommand_location' => '/Extensions/Selenium2TestCase/SessionCommand/Location.php',
'phpunit_extensions_selenium2testcase_sessioncommand_moveto' => '/Extensions/Selenium2TestCase/SessionCommand/MoveTo.php',
'phpunit_extensions_selenium2testcase_sessioncommand_orientation' => '/Extensions/Selenium2TestCase/SessionCommand/Orientation.php',
'phpunit_extensions_selenium2testcase_sessioncommand_url' => '/Extensions/Selenium2TestCase/SessionCommand/Url.php',
'phpunit_extensions_selenium2testcase_sessioncommand_window' => '/Extensions/Selenium2TestCase/SessionCommand/Window.php',
'phpunit_extensions_selenium2testcase_sessionstrategy' => '/Extensions/Selenium2TestCase/SessionStrategy.php',
'phpunit_extensions_selenium2testcase_sessionstrategy_isolated' => '/Extensions/Selenium2TestCase/SessionStrategy/Isolated.php',
'phpunit_extensions_selenium2testcase_sessionstrategy_shared' => '/Extensions/Selenium2TestCase/SessionStrategy/Shared.php',
'phpunit_extensions_selenium2testcase_statecommand' => '/Extensions/Selenium2TestCase/StateCommand.php',
'phpunit_extensions_selenium2testcase_url' => '/Extensions/Selenium2TestCase/URL.php',
'phpunit_extensions_selenium2testcase_waituntil' => '/Extensions/Selenium2TestCase/WaitUntil.php',
'phpunit_extensions_selenium2testcase_webdriverexception' => '/Extensions/Selenium2TestCase/WebDriverException.php',
'phpunit_extensions_selenium2testcase_window' => '/Extensions/Selenium2TestCase/Window.php',
'phpunit_extensions_seleniumbrowsersuite' => '/Extensions/SeleniumBrowserSuite.php',
'phpunit_extensions_seleniumcommon_remotecoverage' => '/Extensions/SeleniumCommon/RemoteCoverage.php',
'phpunit_extensions_seleniumcommon_exithandler' => '/Extensions/SeleniumCommon/ExitHandler.php',
'phpunit_extensions_seleniumtestsuite' => '/Extensions/SeleniumTestSuite.php'
);
$path = dirname(dirname(dirname(__FILE__)));
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
);

View File

@ -0,0 +1,66 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2002-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2002-2010 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.1.0
*/
require_once 'File/Iterator/Autoload.php';
spl_autoload_register(
function ($class) {
static $classes = NULL;
static $path = NULL;
if ($classes === NULL) {
$classes = array(
___CLASSLIST___
);
$path = dirname(dirname(dirname(__FILE__)));
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
);

View File

@ -0,0 +1,34 @@
<?php
namespace PHPUnit\Extensions\SeleniumCommon;
/**
* If Ececution was stopped by calling exit();
* php does not append append.php, so no code coverage date is collected
* We have to add shutdown handler to append this file manualy.
* @author Arbuzov <info@whitediver.com>
*
*/
class ExitHandler
{
/**
* Register handler.
* If project have own shutdown hanldler user have to add function to handler
*
*/
public static function init()
{
register_shutdown_function(array(ExitHandler::class, 'handle'));
}
/**
* Manual include apendable files
*/
public static function handle()
{
$execFile = ini_get('auto_append_file');
if ($execFile!=='') {
include_once ($execFile);
}
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace PHPUnit\Extensions\SeleniumCommon;
use Exception;
class RemoteCoverage
{
public function __construct($coverageScriptUrl, $testId)
{
$this->coverageScriptUrl = $coverageScriptUrl;
$this->testId = $testId;
}
public function get()
{
if (!empty($this->coverageScriptUrl)) {
$url = sprintf(
'%s?PHPUNIT_SELENIUM_TEST_ID=%s',
$this->coverageScriptUrl,
urlencode($this->testId)
);
$buffer = @file_get_contents($url);
if ($buffer !== FALSE) {
$coverageData = unserialize($buffer);
if (is_array($coverageData)) {
return $this->matchLocalAndRemotePaths($coverageData);
} else {
throw new Exception('Empty or invalid code coverage data received from url "' . $url . '" (' . var_export($buffer, true) . ')');
}
}
}
return array();
}
/**
* @param array $coverage
* @return array
* @author Mattis Stordalen Flister <mattis@xait.no>
*/
protected function matchLocalAndRemotePaths(array $coverage)
{
$coverageWithLocalPaths = array();
foreach ($coverage as $originalRemotePath => $data) {
$remotePath = $originalRemotePath;
$separator = $this->findDirectorySeparator($remotePath);
while (!($localpath = stream_resolve_include_path($remotePath)) &&
strpos($remotePath, $separator) !== FALSE) {
$remotePath = substr($remotePath, strpos($remotePath, $separator) + 1);
}
if ($localpath && md5_file($localpath) == $data['md5']) {
$coverageWithLocalPaths[$localpath] = $data['coverage'];
}
}
return $coverageWithLocalPaths;
}
/**
* @param string $path
* @return string
* @author Mattis Stordalen Flister <mattis@xait.no>
*/
protected function findDirectorySeparator($path)
{
if (strpos($path, '/') !== FALSE) {
return '/';
}
return '\\';
}
}

View File

@ -0,0 +1,69 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.0.0
*/
if ( isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) &&
!isset($_GET['PHPUNIT_SELENIUM_TEST_ID']) &&
extension_loaded('xdebug')) {
$GLOBALS['PHPUNIT_FILTERED_FILES'][] = __FILE__;
$data = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
foreach ($GLOBALS['PHPUNIT_FILTERED_FILES'] as $file) {
unset($data[$file]);
}
if (is_string($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']) &&
is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
$file = $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] .
DIRECTORY_SEPARATOR . md5($_SERVER['SCRIPT_FILENAME']);
} else {
$file = $_SERVER['SCRIPT_FILENAME'];
}
$sanitizedCookieName = str_replace(array('\\'), '_', $_COOKIE['PHPUNIT_SELENIUM_TEST_ID']);
$fullPath = $file . '.' . md5(uniqid(rand(), TRUE)) . '.' . $sanitizedCookieName;
file_put_contents($fullPath, serialize($data));
}

View File

@ -0,0 +1,95 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.0.0
*/
$directory = realpath(__DIR__);
while ($directory != '/') {
$autoloadCandidate = $directory . '/vendor/autoload.php';
if (file_exists($autoloadCandidate)) {
require_once $autoloadCandidate;
break;
}
$directory = realpath($directory . '/..');
}
// Set this to the directory that contains the code coverage files.
// It defaults to getcwd(). If you have configured a different directory
// in prepend.php, you need to configure the same directory here.
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = getcwd();
if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) {
$facade = new \SebastianBergmann\FileIterator\Facade();
$sanitizedCookieName = str_replace(array('\\'), '_', $_GET['PHPUNIT_SELENIUM_TEST_ID']);
$files = $facade->getFilesAsArray(
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'],
$sanitizedCookieName
);
$coverage = array();
foreach ($files as $file) {
$data = unserialize(file_get_contents($file));
unlink($file);
unset($file);
$filter = new \SebastianBergmann\CodeCoverage\Filter();
foreach ($data as $file => $lines) {
if ($filter->isFile($file)) {
if (!isset($coverage[$file])) {
$coverage[$file] = array(
'md5' => md5_file($file), 'coverage' => $lines
);
} else {
foreach ($lines as $line => $flag) {
if (!isset($coverage[$file]['coverage'][$line]) ||
$flag > $coverage[$file]['coverage'][$line]) {
$coverage[$file]['coverage'][$line] = $flag;
}
}
}
}
}
}
print serialize($coverage);
}

View File

@ -0,0 +1,67 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.0.0
*/
use PHPUnit\Extensions\SeleniumCommon\ExitHandler;
// By default the code coverage files are written to the same directory
// that contains the covered sourcecode files. Use this setting to change
// the default behaviour and set a specific directory to write the files to.
// If you change the default setting, please make sure to also configure
// the same directory in phpunit_coverage.php. Also note that the webserver
// needs write access to the directory.
if (!isset($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = FALSE;
}
if ( isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) &&
!isset($_GET['PHPUNIT_SELENIUM_TEST_ID']) &&
extension_loaded('xdebug')) {
$GLOBALS['PHPUNIT_FILTERED_FILES'] = array(__FILE__);
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
}
include ('ExitHandler.php');
ExitHandler::init();

View File

@ -0,0 +1,188 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.2
*/
namespace PHPUnit\Extensions;
use File_Iterator_Facade;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Util\Test as TestUtil;
use ReflectionClass;
use ReflectionMethod;
/**
* TestSuite class for Selenium 1 tests
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <info@giorgiosironi.com>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.0
*/
class SeleniumTestSuite extends TestSuite
{
/**
* Overriding the default: Selenium suites are always built from a TestCase class.
* @var boolean
*/
protected $testCase = TRUE;
/**
* Making the method public.
* @param ReflectionClass $class
* @param ReflectionMethod $method
*/
public function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
{
parent::addTestMethod($class, $method);
}
/**
* @param string $className extending PHPUnit_Extensions_SeleniumTestCase
* @return SeleniumTestSuite
*/
public static function fromTestCaseClass($className)
{
$suite = new self();
$suite->setName($className);
$class = new ReflectionClass($className);
$classGroups = TestUtil::getGroups($className);
$staticProperties = $class->getStaticProperties();
if (isset($staticProperties['browsers'])) {
$browsers = $staticProperties['browsers'];
} else if (is_callable("{$className}::browsers")) {
$browsers = $className::browsers();
} else {
$browsers = null;
}
//BC: renamed seleneseDirectory -> selenesePath
if (!isset($staticProperties['selenesePath']) && isset($staticProperties['seleneseDirectory'])) {
$staticProperties['selenesePath'] = $staticProperties['seleneseDirectory'];
}
// Create tests from Selenese/HTML files.
if (isset($staticProperties['selenesePath']) &&
(is_dir($staticProperties['selenesePath']) || is_file($staticProperties['selenesePath']))) {
if (is_dir($staticProperties['selenesePath'])) {
$files = array_merge(
self::getSeleneseFiles($staticProperties['selenesePath'], '.htm'),
self::getSeleneseFiles($staticProperties['selenesePath'], '.html')
);
} else {
$files[] = realpath($staticProperties['selenesePath']);
}
// Create tests from Selenese/HTML files for multiple browsers.
if ($browsers) {
foreach ($browsers as $browser) {
$browserSuite = SeleniumBrowserSuite::fromClassAndBrowser($className, $browser);
foreach ($files as $file) {
self::addGeneratedTestTo($browserSuite,
new $className($file, array(), '', $browser),
$classGroups
);
}
$suite->addTest($browserSuite);
}
}
else {
// Create tests from Selenese/HTML files for single browser.
foreach ($files as $file) {
self::addGeneratedTestTo($suite,
new $className($file),
$classGroups);
}
}
}
// Create tests from test methods for multiple browsers.
if ($browsers) {
foreach ($browsers as $browser) {
$browserSuite = SeleniumBrowserSuite::fromClassAndBrowser($className, $browser);
foreach ($class->getMethods() as $method) {
$browserSuite->addTestMethod($class, $method);
}
$browserSuite->setupSpecificBrowser($browser);
$suite->addTest($browserSuite);
}
}
else {
// Create tests from test methods for single browser.
foreach ($class->getMethods() as $method) {
$suite->addTestMethod($class, $method);
}
}
return $suite;
}
private static function addGeneratedTestTo(TestSuite $suite, \PHPUnit\Framework\TestCase $test, $classGroups)
{
[$methodName, ] = explode(' ', $test->getName());
$test->setDependencies(
TestUtil::getDependencies(get_class($test), $methodName)
);
$suite->addTest($test, $classGroups);
}
/**
* @param string $directory
* @param string $suffix
* @return array
*/
private static function getSeleneseFiles($directory, $suffix)
{
$facade = new File_Iterator_Facade;
return $facade->getFilesAsArray($directory, $suffix);
}
}