4 * This file is part of the Mink package.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Mink\Driver;
13 use Behat\Mink\Element\NodeElement;
14 use Behat\Mink\Exception\DriverException;
15 use Behat\Mink\Exception\UnsupportedDriverActionException;
16 use Behat\Mink\Session;
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 interface DriverInterface
26 * Sets driver's current session.
28 * @param Session $session
30 public function setSession(Session $session);
35 * Once started, the driver should be ready to visit a page.
37 * Calling any action before visiting a page is an undefined behavior.
38 * The only supported method calls on a fresh driver are
40 * - setRequestHeader()
45 * Calling start on a started driver is an undefined behavior. Driver
46 * implementations are free to handle it silently or to fail with an
49 * @throws DriverException When the driver cannot be started
51 public function start();
54 * Checks whether driver is started.
58 public function isStarted();
63 * Once stopped, the driver should be started again before using it again.
65 * Calling any action on a stopped driver is an undefined behavior.
66 * The only supported method call after stopping a driver is starting it again.
68 * Calling stop on a stopped driver is an undefined behavior. Driver
69 * implementations are free to handle it silently or to fail with an
72 * @throws DriverException When the driver cannot be closed
74 public function stop();
77 * Resets driver state.
79 * This should reset cookies, request headers and basic authentication.
80 * When possible, the history should be reset as well, but this is not enforced
81 * as some implementations may not be able to reset it without restarting the
82 * driver entirely. Consumers requiring a clean history should restart the driver
85 * Once reset, the driver should be ready to visit a page.
86 * Calling any action before visiting a page is an undefined behavior.
87 * The only supported method calls on a fresh driver are
89 * - setRequestHeader()
94 * Calling reset on a stopped driver is an undefined behavior.
96 public function reset();
99 * Visit specified URL.
101 * @param string $url url of the page
103 * @throws UnsupportedDriverActionException When operation not supported by the driver
104 * @throws DriverException When the operation cannot be done
106 public function visit($url);
109 * Returns current URL address.
113 * @throws UnsupportedDriverActionException When operation not supported by the driver
114 * @throws DriverException When the operation cannot be done
116 public function getCurrentUrl();
119 * Reloads current page.
121 * @throws UnsupportedDriverActionException When operation not supported by the driver
122 * @throws DriverException When the operation cannot be done
124 public function reload();
127 * Moves browser forward 1 page.
129 * @throws UnsupportedDriverActionException When operation not supported by the driver
130 * @throws DriverException When the operation cannot be done
132 public function forward();
135 * Moves browser backward 1 page.
137 * @throws UnsupportedDriverActionException When operation not supported by the driver
138 * @throws DriverException When the operation cannot be done
140 public function back();
143 * Sets HTTP Basic authentication parameters.
145 * @param string|Boolean $user user name or false to disable authentication
146 * @param string $password password
148 * @throws UnsupportedDriverActionException When operation not supported by the driver
149 * @throws DriverException When the operation cannot be done
151 public function setBasicAuth($user, $password);
154 * Switches to specific browser window.
156 * @param string $name window name (null for switching back to main window)
158 * @throws UnsupportedDriverActionException When operation not supported by the driver
159 * @throws DriverException When the operation cannot be done
161 public function switchToWindow($name = null);
164 * Switches to specific iFrame.
166 * @param string $name iframe name (null for switching back)
168 * @throws UnsupportedDriverActionException When operation not supported by the driver
169 * @throws DriverException When the operation cannot be done
171 public function switchToIFrame($name = null);
174 * Sets specific request header on client.
176 * @param string $name
177 * @param string $value
179 * @throws UnsupportedDriverActionException When operation not supported by the driver
180 * @throws DriverException When the operation cannot be done
182 public function setRequestHeader($name, $value);
185 * Returns last response headers.
189 * @throws UnsupportedDriverActionException When operation not supported by the driver
190 * @throws DriverException When the operation cannot be done
192 public function getResponseHeaders();
197 * @param string $name
198 * @param string $value
200 * @throws UnsupportedDriverActionException When operation not supported by the driver
201 * @throws DriverException When the operation cannot be done
203 public function setCookie($name, $value = null);
206 * Returns cookie by name.
208 * @param string $name
210 * @return string|null
212 * @throws UnsupportedDriverActionException When operation not supported by the driver
213 * @throws DriverException When the operation cannot be done
215 public function getCookie($name);
218 * Returns last response status code.
222 * @throws UnsupportedDriverActionException When operation not supported by the driver
223 * @throws DriverException When the operation cannot be done
225 public function getStatusCode();
228 * Returns last response content.
232 * @throws UnsupportedDriverActionException When operation not supported by the driver
233 * @throws DriverException When the operation cannot be done
235 public function getContent();
238 * Capture a screenshot of the current window.
240 * @return string screenshot of MIME type image/* depending
241 * on driver (e.g., image/png, image/jpeg)
243 * @throws UnsupportedDriverActionException When operation not supported by the driver
244 * @throws DriverException When the operation cannot be done
246 public function getScreenshot();
249 * Return the names of all open windows.
251 * @return array array of all open windows
253 * @throws UnsupportedDriverActionException When operation not supported by the driver
254 * @throws DriverException When the operation cannot be done
256 public function getWindowNames();
259 * Return the name of the currently active window.
261 * @return string the name of the current window
263 * @throws UnsupportedDriverActionException When operation not supported by the driver
264 * @throws DriverException When the operation cannot be done
266 public function getWindowName();
269 * Finds elements with specified XPath query.
271 * @param string $xpath
273 * @return NodeElement[]
275 * @throws UnsupportedDriverActionException When operation not supported by the driver
276 * @throws DriverException When the operation cannot be done
278 public function find($xpath);
281 * Returns element's tag name by it's XPath query.
283 * @param string $xpath
287 * @throws UnsupportedDriverActionException When operation not supported by the driver
288 * @throws DriverException When the operation cannot be done
290 public function getTagName($xpath);
293 * Returns element's text by it's XPath query.
295 * @param string $xpath
299 * @throws UnsupportedDriverActionException When operation not supported by the driver
300 * @throws DriverException When the operation cannot be done
302 public function getText($xpath);
305 * Returns element's inner html by it's XPath query.
307 * @param string $xpath
311 * @throws UnsupportedDriverActionException When operation not supported by the driver
312 * @throws DriverException When the operation cannot be done
314 public function getHtml($xpath);
317 * Returns element's outer html by it's XPath query.
319 * @param string $xpath
323 * @throws UnsupportedDriverActionException When operation not supported by the driver
324 * @throws DriverException When the operation cannot be done
326 public function getOuterHtml($xpath);
329 * Returns element's attribute by it's XPath query.
331 * @param string $xpath
332 * @param string $name
334 * @return string|null
336 * @throws UnsupportedDriverActionException When operation not supported by the driver
337 * @throws DriverException When the operation cannot be done
339 public function getAttribute($xpath, $name);
342 * Returns element's value by it's XPath query.
344 * @param string $xpath
346 * @return string|bool|array
348 * @throws UnsupportedDriverActionException When operation not supported by the driver
349 * @throws DriverException When the operation cannot be done
351 * @see \Behat\Mink\Element\NodeElement::getValue
353 public function getValue($xpath);
356 * Sets element's value by it's XPath query.
358 * @param string $xpath
359 * @param string|bool|array $value
361 * @throws UnsupportedDriverActionException When operation not supported by the driver
362 * @throws DriverException When the operation cannot be done
364 * @see \Behat\Mink\Element\NodeElement::setValue
366 public function setValue($xpath, $value);
369 * Checks checkbox by it's XPath query.
371 * @param string $xpath
373 * @throws UnsupportedDriverActionException When operation not supported by the driver
374 * @throws DriverException When the operation cannot be done
376 * @see \Behat\Mink\Element\NodeElement::check
378 public function check($xpath);
381 * Unchecks checkbox by it's XPath query.
383 * @param string $xpath
385 * @throws UnsupportedDriverActionException When operation not supported by the driver
386 * @throws DriverException When the operation cannot be done
388 * @see \Behat\Mink\Element\NodeElement::uncheck
390 public function uncheck($xpath);
393 * Checks whether checkbox or radio button located by it's XPath query is checked.
395 * @param string $xpath
399 * @throws UnsupportedDriverActionException When operation not supported by the driver
400 * @throws DriverException When the operation cannot be done
402 * @see \Behat\Mink\Element\NodeElement::isChecked
404 public function isChecked($xpath);
407 * Selects option from select field or value in radio group located by it's XPath query.
409 * @param string $xpath
410 * @param string $value
411 * @param Boolean $multiple
413 * @throws UnsupportedDriverActionException When operation not supported by the driver
414 * @throws DriverException When the operation cannot be done
416 * @see \Behat\Mink\Element\NodeElement::selectOption
418 public function selectOption($xpath, $value, $multiple = false);
421 * Checks whether select option, located by it's XPath query, is selected.
423 * @param string $xpath
427 * @throws UnsupportedDriverActionException When operation not supported by the driver
428 * @throws DriverException When the operation cannot be done
430 * @see \Behat\Mink\Element\NodeElement::isSelected
432 public function isSelected($xpath);
435 * Clicks button or link located by it's XPath query.
437 * @param string $xpath
439 * @throws UnsupportedDriverActionException When operation not supported by the driver
440 * @throws DriverException When the operation cannot be done
442 public function click($xpath);
445 * Double-clicks button or link located by it's XPath query.
447 * @param string $xpath
449 * @throws UnsupportedDriverActionException When operation not supported by the driver
450 * @throws DriverException When the operation cannot be done
452 public function doubleClick($xpath);
455 * Right-clicks button or link located by it's XPath query.
457 * @param string $xpath
459 * @throws UnsupportedDriverActionException When operation not supported by the driver
460 * @throws DriverException When the operation cannot be done
462 public function rightClick($xpath);
465 * Attaches file path to file field located by it's XPath query.
467 * @param string $xpath
468 * @param string $path
470 * @throws UnsupportedDriverActionException When operation not supported by the driver
471 * @throws DriverException When the operation cannot be done
473 * @see \Behat\Mink\Element\NodeElement::attachFile
475 public function attachFile($xpath, $path);
478 * Checks whether element visible located by it's XPath query.
480 * @param string $xpath
484 * @throws UnsupportedDriverActionException When operation not supported by the driver
485 * @throws DriverException When the operation cannot be done
487 public function isVisible($xpath);
490 * Simulates a mouse over on the element.
492 * @param string $xpath
494 * @throws UnsupportedDriverActionException When operation not supported by the driver
495 * @throws DriverException When the operation cannot be done
497 public function mouseOver($xpath);
500 * Brings focus to element.
502 * @param string $xpath
504 * @throws UnsupportedDriverActionException When operation not supported by the driver
505 * @throws DriverException When the operation cannot be done
507 public function focus($xpath);
510 * Removes focus from element.
512 * @param string $xpath
514 * @throws UnsupportedDriverActionException When operation not supported by the driver
515 * @throws DriverException When the operation cannot be done
517 public function blur($xpath);
520 * Presses specific keyboard key.
522 * @param string $xpath
523 * @param string|int $char could be either char ('b') or char-code (98)
524 * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
526 * @throws UnsupportedDriverActionException When operation not supported by the driver
527 * @throws DriverException When the operation cannot be done
529 public function keyPress($xpath, $char, $modifier = null);
532 * Pressed down specific keyboard key.
534 * @param string $xpath
535 * @param string|int $char could be either char ('b') or char-code (98)
536 * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
538 * @throws UnsupportedDriverActionException When operation not supported by the driver
539 * @throws DriverException When the operation cannot be done
541 public function keyDown($xpath, $char, $modifier = null);
544 * Pressed up specific keyboard key.
546 * @param string $xpath
547 * @param string|int $char could be either char ('b') or char-code (98)
548 * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
550 * @throws UnsupportedDriverActionException When operation not supported by the driver
551 * @throws DriverException When the operation cannot be done
553 public function keyUp($xpath, $char, $modifier = null);
556 * Drag one element onto another.
558 * @param string $sourceXpath
559 * @param string $destinationXpath
561 * @throws UnsupportedDriverActionException When operation not supported by the driver
562 * @throws DriverException When the operation cannot be done
564 public function dragTo($sourceXpath, $destinationXpath);
567 * Executes JS script.
569 * @param string $script
571 * @throws UnsupportedDriverActionException When operation not supported by the driver
572 * @throws DriverException When the operation cannot be done
574 public function executeScript($script);
577 * Evaluates JS script.
579 * The "return" keyword is optional in the script passed as argument. Driver implementations
580 * must accept the expression both with and without the keyword.
582 * @param string $script
586 * @throws UnsupportedDriverActionException When operation not supported by the driver
587 * @throws DriverException When the operation cannot be done
589 public function evaluateScript($script);
592 * Waits some time or until JS condition turns true.
594 * @param int $timeout timeout in milliseconds
595 * @param string $condition JS condition
599 * @throws UnsupportedDriverActionException When operation not supported by the driver
600 * @throws DriverException When the operation cannot be done
602 public function wait($timeout, $condition);
605 * Set the dimensions of the window.
607 * @param int $width set the window width, measured in pixels
608 * @param int $height set the window height, measured in pixels
609 * @param string $name window name (null for the main window)
611 * @throws UnsupportedDriverActionException When operation not supported by the driver
612 * @throws DriverException When the operation cannot be done
614 public function resizeWindow($width, $height, $name = null);
617 * Maximizes the window if it is not maximized already.
619 * @param string $name window name (null for the main window)
621 * @throws UnsupportedDriverActionException When operation not supported by the driver
622 * @throws DriverException When the operation cannot be done
624 public function maximizeWindow($name = null);
629 * @param string $xpath Xpath.
631 * @throws UnsupportedDriverActionException When operation not supported by the driver
632 * @throws DriverException When the operation cannot be done
634 * @see \Behat\Mink\Element\NodeElement::submitForm
636 public function submitForm($xpath);