comparison vendor/instaclick/php-webdriver/lib/WebDriver/Timeouts.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /**
3 * Copyright 2011-2017 Anthon Pang. All Rights Reserved.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 * @package WebDriver
18 *
19 * @author Anthon Pang <apang@softwaredevelopment.ca>
20 */
21
22 namespace WebDriver;
23
24 use WebDriver\Exception as WebDriverException;
25
26 /**
27 * WebDriver\Timeouts class
28 *
29 * @package WebDriver
30 *
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.
33 */
34 final class Timeouts extends AbstractWebDriver
35 {
36 /**
37 * {@inheritdoc}
38 */
39 protected function methods()
40 {
41 return array(
42 'async_script' => array('POST'),
43 'implicit_wait' => array('POST'),
44 );
45 }
46
47 /**
48 * helper method to wait until user-defined condition is met
49 *
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
54 *
55 * @return mixed result from callback function
56 *
57 * @throws \Exception if thrown by callback, or \WebDriver\Exception\Timeout if helper times out
58 */
59 public function wait($callback, $maxIterations = 1, $sleep = 0, $args = array())
60 {
61 $i = max(1, $maxIterations);
62
63 while ($i-- > 0) {
64 $result = call_user_func_array($callback, $args);
65
66 if ($result !== false) {
67 return $result;
68 }
69
70 // don't sleep on the last iteration
71 $i && sleep($sleep);
72 }
73
74 throw WebDriverException::factory(WebDriverException::TIMEOUT, 'wait() method timed out');
75 }
76 }