3 * Copyright 2011-2017 Anthon Pang. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Anthon Pang <apang@softwaredevelopment.ca>
24 use WebDriver\Exception as WebDriverException;
27 * WebDriver\Timeouts class
31 * @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.
32 * @method void implicit_wait($json) Set the amount of time the driver should wait when searching for elements.
34 final class Timeouts extends AbstractWebDriver
39 protected function methods()
42 'async_script' => array('POST'),
43 'implicit_wait' => array('POST'),
48 * helper method to wait until user-defined condition is met
50 * @param function $callback callback which returns non-false result if wait condition was met
51 * @param integer $maxIterations maximum number of iterations
52 * @param integer $sleep sleep duration in seconds between iterations
53 * @param array $args optional args; if the callback needs $this, then pass it here
55 * @return mixed result from callback function
57 * @throws \Exception if thrown by callback, or \WebDriver\Exception\Timeout if helper times out
59 public function wait($callback, $maxIterations = 1, $sleep = 0, $args = array())
61 $i = max(1, $maxIterations);
64 $result = call_user_func_array($callback, $args);
66 if ($result !== false) {
70 // don't sleep on the last iteration
74 throw WebDriverException::factory(WebDriverException::TIMEOUT, 'wait() method timed out');