Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Behat\Mink\Driver; Chris@0: Chris@0: use Behat\Mink\Element\NodeElement; Chris@0: use Behat\Mink\Exception\DriverException; Chris@0: use Behat\Mink\Exception\UnsupportedDriverActionException; Chris@0: use Behat\Mink\Session; Chris@0: Chris@0: /** Chris@0: * Driver interface. Chris@0: * Chris@0: * @author Konstantin Kudryashov Chris@0: */ Chris@0: interface DriverInterface Chris@0: { Chris@0: /** Chris@0: * Sets driver's current session. Chris@0: * Chris@0: * @param Session $session Chris@0: */ Chris@0: public function setSession(Session $session); Chris@0: Chris@0: /** Chris@0: * Starts driver. Chris@0: * Chris@0: * Once started, the driver should be ready to visit a page. Chris@0: * Chris@0: * Calling any action before visiting a page is an undefined behavior. Chris@0: * The only supported method calls on a fresh driver are Chris@0: * - visit() Chris@0: * - setRequestHeader() Chris@0: * - setBasicAuth() Chris@0: * - reset() Chris@0: * - stop() Chris@0: * Chris@0: * Calling start on a started driver is an undefined behavior. Driver Chris@0: * implementations are free to handle it silently or to fail with an Chris@0: * exception. Chris@0: * Chris@0: * @throws DriverException When the driver cannot be started Chris@0: */ Chris@0: public function start(); Chris@0: Chris@0: /** Chris@0: * Checks whether driver is started. Chris@0: * Chris@0: * @return Boolean Chris@0: */ Chris@0: public function isStarted(); Chris@0: Chris@0: /** Chris@0: * Stops driver. Chris@0: * Chris@0: * Once stopped, the driver should be started again before using it again. Chris@0: * Chris@0: * Calling any action on a stopped driver is an undefined behavior. Chris@0: * The only supported method call after stopping a driver is starting it again. Chris@0: * Chris@0: * Calling stop on a stopped driver is an undefined behavior. Driver Chris@0: * implementations are free to handle it silently or to fail with an Chris@0: * exception. Chris@0: * Chris@0: * @throws DriverException When the driver cannot be closed Chris@0: */ Chris@0: public function stop(); Chris@0: Chris@0: /** Chris@0: * Resets driver state. Chris@0: * Chris@0: * This should reset cookies, request headers and basic authentication. Chris@0: * When possible, the history should be reset as well, but this is not enforced Chris@0: * as some implementations may not be able to reset it without restarting the Chris@0: * driver entirely. Consumers requiring a clean history should restart the driver Chris@0: * to enforce it. Chris@0: * Chris@0: * Once reset, the driver should be ready to visit a page. Chris@0: * Calling any action before visiting a page is an undefined behavior. Chris@0: * The only supported method calls on a fresh driver are Chris@0: * - visit() Chris@0: * - setRequestHeader() Chris@0: * - setBasicAuth() Chris@0: * - reset() Chris@0: * - stop() Chris@0: * Chris@0: * Calling reset on a stopped driver is an undefined behavior. Chris@0: */ Chris@0: public function reset(); Chris@0: Chris@0: /** Chris@0: * Visit specified URL. Chris@0: * Chris@0: * @param string $url url of the page Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function visit($url); Chris@0: Chris@0: /** Chris@0: * Returns current URL address. Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getCurrentUrl(); Chris@0: Chris@0: /** Chris@0: * Reloads current page. Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function reload(); Chris@0: Chris@0: /** Chris@0: * Moves browser forward 1 page. Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function forward(); Chris@0: Chris@0: /** Chris@0: * Moves browser backward 1 page. Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function back(); Chris@0: Chris@0: /** Chris@0: * Sets HTTP Basic authentication parameters. Chris@0: * Chris@0: * @param string|Boolean $user user name or false to disable authentication Chris@0: * @param string $password password Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function setBasicAuth($user, $password); Chris@0: Chris@0: /** Chris@0: * Switches to specific browser window. Chris@0: * Chris@0: * @param string $name window name (null for switching back to main window) Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function switchToWindow($name = null); Chris@0: Chris@0: /** Chris@0: * Switches to specific iFrame. Chris@0: * Chris@0: * @param string $name iframe name (null for switching back) Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function switchToIFrame($name = null); Chris@0: Chris@0: /** Chris@0: * Sets specific request header on client. Chris@0: * Chris@0: * @param string $name Chris@0: * @param string $value Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function setRequestHeader($name, $value); Chris@0: Chris@0: /** Chris@0: * Returns last response headers. Chris@0: * Chris@0: * @return array Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getResponseHeaders(); Chris@0: Chris@0: /** Chris@0: * Sets cookie. Chris@0: * Chris@0: * @param string $name Chris@0: * @param string $value Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function setCookie($name, $value = null); Chris@0: Chris@0: /** Chris@0: * Returns cookie by name. Chris@0: * Chris@0: * @param string $name Chris@0: * Chris@0: * @return string|null Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getCookie($name); Chris@0: Chris@0: /** Chris@0: * Returns last response status code. Chris@0: * Chris@0: * @return int Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getStatusCode(); Chris@0: Chris@0: /** Chris@0: * Returns last response content. Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getContent(); Chris@0: Chris@0: /** Chris@0: * Capture a screenshot of the current window. Chris@0: * Chris@0: * @return string screenshot of MIME type image/* depending Chris@0: * on driver (e.g., image/png, image/jpeg) Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getScreenshot(); Chris@0: Chris@0: /** Chris@0: * Return the names of all open windows. Chris@0: * Chris@0: * @return array array of all open windows Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getWindowNames(); Chris@0: Chris@0: /** Chris@0: * Return the name of the currently active window. Chris@0: * Chris@0: * @return string the name of the current window Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getWindowName(); Chris@0: Chris@0: /** Chris@0: * Finds elements with specified XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return NodeElement[] Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function find($xpath); Chris@0: Chris@0: /** Chris@0: * Returns element's tag name by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getTagName($xpath); Chris@0: Chris@0: /** Chris@0: * Returns element's text by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getText($xpath); Chris@0: Chris@0: /** Chris@0: * Returns element's inner html by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getHtml($xpath); Chris@0: Chris@0: /** Chris@0: * Returns element's outer html by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getOuterHtml($xpath); Chris@0: Chris@0: /** Chris@0: * Returns element's attribute by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string $name Chris@0: * Chris@0: * @return string|null Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function getAttribute($xpath, $name); Chris@0: Chris@0: /** Chris@0: * Returns element's value by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return string|bool|array Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::getValue Chris@0: */ Chris@0: public function getValue($xpath); Chris@0: Chris@0: /** Chris@0: * Sets element's value by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string|bool|array $value Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::setValue Chris@0: */ Chris@0: public function setValue($xpath, $value); Chris@0: Chris@0: /** Chris@0: * Checks checkbox by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::check Chris@0: */ Chris@0: public function check($xpath); Chris@0: Chris@0: /** Chris@0: * Unchecks checkbox by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::uncheck Chris@0: */ Chris@0: public function uncheck($xpath); Chris@0: Chris@0: /** Chris@0: * Checks whether checkbox or radio button located by it's XPath query is checked. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return Boolean Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::isChecked Chris@0: */ Chris@0: public function isChecked($xpath); Chris@0: Chris@0: /** Chris@0: * Selects option from select field or value in radio group located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string $value Chris@0: * @param Boolean $multiple Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::selectOption Chris@0: */ Chris@0: public function selectOption($xpath, $value, $multiple = false); Chris@0: Chris@0: /** Chris@0: * Checks whether select option, located by it's XPath query, is selected. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return Boolean Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::isSelected Chris@0: */ Chris@0: public function isSelected($xpath); Chris@0: Chris@0: /** Chris@0: * Clicks button or link located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function click($xpath); Chris@0: Chris@0: /** Chris@0: * Double-clicks button or link located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function doubleClick($xpath); Chris@0: Chris@0: /** Chris@0: * Right-clicks button or link located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function rightClick($xpath); Chris@0: Chris@0: /** Chris@0: * Attaches file path to file field located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string $path Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::attachFile Chris@0: */ Chris@0: public function attachFile($xpath, $path); Chris@0: Chris@0: /** Chris@0: * Checks whether element visible located by it's XPath query. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @return Boolean Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function isVisible($xpath); Chris@0: Chris@0: /** Chris@0: * Simulates a mouse over on the element. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function mouseOver($xpath); Chris@0: Chris@0: /** Chris@0: * Brings focus to element. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function focus($xpath); Chris@0: Chris@0: /** Chris@0: * Removes focus from element. Chris@0: * Chris@0: * @param string $xpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function blur($xpath); Chris@0: Chris@0: /** Chris@0: * Presses specific keyboard key. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string|int $char could be either char ('b') or char-code (98) Chris@0: * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function keyPress($xpath, $char, $modifier = null); Chris@0: Chris@0: /** Chris@0: * Pressed down specific keyboard key. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string|int $char could be either char ('b') or char-code (98) Chris@0: * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function keyDown($xpath, $char, $modifier = null); Chris@0: Chris@0: /** Chris@0: * Pressed up specific keyboard key. Chris@0: * Chris@0: * @param string $xpath Chris@0: * @param string|int $char could be either char ('b') or char-code (98) Chris@0: * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function keyUp($xpath, $char, $modifier = null); Chris@0: Chris@0: /** Chris@0: * Drag one element onto another. Chris@0: * Chris@0: * @param string $sourceXpath Chris@0: * @param string $destinationXpath Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function dragTo($sourceXpath, $destinationXpath); Chris@0: Chris@0: /** Chris@0: * Executes JS script. Chris@0: * Chris@0: * @param string $script Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function executeScript($script); Chris@0: Chris@0: /** Chris@0: * Evaluates JS script. Chris@0: * Chris@0: * The "return" keyword is optional in the script passed as argument. Driver implementations Chris@0: * must accept the expression both with and without the keyword. Chris@0: * Chris@0: * @param string $script Chris@0: * Chris@0: * @return mixed Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function evaluateScript($script); Chris@0: Chris@0: /** Chris@0: * Waits some time or until JS condition turns true. Chris@0: * Chris@0: * @param int $timeout timeout in milliseconds Chris@0: * @param string $condition JS condition Chris@0: * Chris@0: * @return bool Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function wait($timeout, $condition); Chris@0: Chris@0: /** Chris@0: * Set the dimensions of the window. Chris@0: * Chris@0: * @param int $width set the window width, measured in pixels Chris@0: * @param int $height set the window height, measured in pixels Chris@0: * @param string $name window name (null for the main window) Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function resizeWindow($width, $height, $name = null); Chris@0: Chris@0: /** Chris@0: * Maximizes the window if it is not maximized already. Chris@0: * Chris@0: * @param string $name window name (null for the main window) Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: */ Chris@0: public function maximizeWindow($name = null); Chris@0: Chris@0: /** Chris@0: * Submits the form. Chris@0: * Chris@0: * @param string $xpath Xpath. Chris@0: * Chris@0: * @throws UnsupportedDriverActionException When operation not supported by the driver Chris@0: * @throws DriverException When the operation cannot be done Chris@0: * Chris@0: * @see \Behat\Mink\Element\NodeElement::submitForm Chris@0: */ Chris@0: public function submitForm($xpath); Chris@0: }