X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Finstaclick%2Fphp-webdriver%2Flib%2FWebDriver%2FTimeouts.php;fp=vendor%2Finstaclick%2Fphp-webdriver%2Flib%2FWebDriver%2FTimeouts.php;h=4ce725157769aea592ba209f319b879d548cf961;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/instaclick/php-webdriver/lib/WebDriver/Timeouts.php b/vendor/instaclick/php-webdriver/lib/WebDriver/Timeouts.php new file mode 100644 index 000000000..4ce725157 --- /dev/null +++ b/vendor/instaclick/php-webdriver/lib/WebDriver/Timeouts.php @@ -0,0 +1,76 @@ + + */ + +namespace WebDriver; + +use WebDriver\Exception as WebDriverException; + +/** + * WebDriver\Timeouts class + * + * @package WebDriver + * + * @method void async_script($json) Set the amount of time, in milliseconds, that asynchronous scripts (executed by execute_async) are permitted to run before they are aborted and a timeout error is returned to the client. + * @method void implicit_wait($json) Set the amount of time the driver should wait when searching for elements. + */ +final class Timeouts extends AbstractWebDriver +{ + /** + * {@inheritdoc} + */ + protected function methods() + { + return array( + 'async_script' => array('POST'), + 'implicit_wait' => array('POST'), + ); + } + + /** + * helper method to wait until user-defined condition is met + * + * @param function $callback callback which returns non-false result if wait condition was met + * @param integer $maxIterations maximum number of iterations + * @param integer $sleep sleep duration in seconds between iterations + * @param array $args optional args; if the callback needs $this, then pass it here + * + * @return mixed result from callback function + * + * @throws \Exception if thrown by callback, or \WebDriver\Exception\Timeout if helper times out + */ + public function wait($callback, $maxIterations = 1, $sleep = 0, $args = array()) + { + $i = max(1, $maxIterations); + + while ($i-- > 0) { + $result = call_user_func_array($callback, $args); + + if ($result !== false) { + return $result; + } + + // don't sleep on the last iteration + $i && sleep($sleep); + } + + throw WebDriverException::factory(WebDriverException::TIMEOUT, 'wait() method timed out'); + } +}