Skip to content

Commit 4c395af

Browse files
committed
configurable checkInterval for waitUntil conditional checks,
extracting error message from the driver response
1 parent 732edb5 commit 4c395af

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/Client/W3CClient.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the ReactPHP WebDriver <https://github.com/itnelo/reactphp-webdriver>.
55
*
6-
* (c) 2020 Pavel Petrov <itnelo@gmail.com>.
6+
* (c) 2020-2021 Pavel Petrov <itnelo@gmail.com>.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -817,10 +817,14 @@ private function onCommandConfirmation(ResponseInterface $response, string $erro
817817
{
818818
$responseValueNode = $this->deserializeResponse($response);
819819

820-
// todo: locate an error message or set it as "undefined error"
821-
if (null !== $responseValueNode) {
822-
throw new RuntimeException($errorMessage);
820+
if (null === $responseValueNode) {
821+
return;
823822
}
823+
824+
$driverMessage = $responseValueNode['message'] ?? 'undefined driver error';
825+
$confirmationErrorMessage = sprintf('%s %s.', $errorMessage, $driverMessage);
826+
827+
throw new RuntimeException($confirmationErrorMessage);
824828
}
825829

826830
/**

src/Routine/Condition/CheckRoutine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(LoopInterface $loop, TimeoutInterceptor $timeoutInte
8484
*
8585
* @throws RuntimeException Whenever the routine is already in the running state
8686
*/
87-
public function run(callable $conditionMetCallback, float $checkInterval = 0.5): PromiseInterface
87+
public function run(callable $conditionMetCallback, float $checkInterval): PromiseInterface
8888
{
8989
if ($this->_evaluationTimer instanceof TimerInterface) {
9090
throw new RuntimeException('Routine is already running.');

src/SeleniumHubDriver.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the ReactPHP WebDriver <https://github.com/itnelo/reactphp-webdriver>.
55
*
6-
* (c) 2020 Pavel Petrov <itnelo@gmail.com>.
6+
* (c) 2020-2021 Pavel Petrov <itnelo@gmail.com>.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -310,15 +310,21 @@ public function wait(float $time = 30.0): PromiseInterface
310310
/**
311311
* {@inheritDoc}
312312
*/
313-
public function waitUntil(callable $conditionMetCallback, float $time = 30.0): PromiseInterface
314-
{
315-
$timeNormalized = max(0.5, $time);
313+
public function waitUntil(
314+
callable $conditionMetCallback,
315+
float $time = 30.0,
316+
float $checkInterval = 0.5
317+
): PromiseInterface {
318+
$timeNormalized = max(0.5, $time);
319+
$checkIntervalNormalized = max(0.1, $checkInterval);
316320

317321
// todo: probably, should be redesigned, to reduce amount of "new" calls
318322
$timeoutInterceptor = new TimeoutInterceptor($this->loop, $timeNormalized);
319323
$checkRoutine = new ConditionCheckRoutine($this->loop, $timeoutInterceptor);
320324

321-
return $checkRoutine->run($conditionMetCallback);
325+
$conditionMetPromise = $checkRoutine->run($conditionMetCallback, $checkIntervalNormalized);
326+
327+
return $conditionMetPromise;
322328
}
323329

324330
/**

src/WebDriverInterface.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the ReactPHP WebDriver <https://github.com/itnelo/reactphp-webdriver>.
55
*
6-
* (c) 2020 Pavel Petrov <itnelo@gmail.com>.
6+
* (c) 2020-2021 Pavel Petrov <itnelo@gmail.com>.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -116,10 +116,15 @@ public function wait(float $time = 30.0): PromiseInterface;
116116
* @param callable $conditionMetCallback A condition to be met, as a callback
117117
* @param float $time Time (in seconds) to wait for successfully resolved promise from the
118118
* condition callback (minimum: 0.5)
119+
* @param float $checkInterval The interval for condition checks, in seconds (minimum: 0.1)
119120
*
120121
* @return PromiseInterface<mixed>
121122
*/
122-
public function waitUntil(callable $conditionMetCallback, float $time = 30.0): PromiseInterface;
123+
public function waitUntil(
124+
callable $conditionMetCallback,
125+
float $time = 30.0,
126+
float $checkInterval = 0.5
127+
): PromiseInterface;
123128

124129
/**
125130
* Returns a promise that will be resolved if a screenshot is successfully received and saved using the specified

0 commit comments

Comments
 (0)