Skip to content

Commit ae5a90c

Browse files
Consistently use WebDriverWait available API for WaitsForElements trait instead of relying on Carbon. (#1062)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent 3bf31f9 commit ae5a90c

File tree

3 files changed

+166
-80
lines changed

3 files changed

+166
-80
lines changed

src/Concerns/WaitsForElements.php

+6-20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Laravel\Dusk\Concerns;
44

5-
use Carbon\Carbon;
65
use Closure;
7-
use Exception;
86
use Facebook\WebDriver\Exception\NoSuchElementException;
97
use Facebook\WebDriver\Exception\ScriptTimeoutException;
108
use Facebook\WebDriver\Exception\TimeoutException;
@@ -394,26 +392,14 @@ public function waitUsing($seconds, $interval, Closure $callback, $message = nul
394392

395393
$this->pause($interval);
396394

397-
$started = Carbon::now();
398-
399-
while (true) {
400-
try {
395+
$this->driver->wait($seconds, $interval)->until(
396+
function ($driver) use ($callback) {
401397
if ($callback()) {
402-
break;
398+
return true;
403399
}
404-
} catch (Exception $e) {
405-
//
406-
}
407-
408-
if ($started->lt(Carbon::now()->subSeconds($seconds))) {
409-
throw new TimeoutException($message
410-
? sprintf($message, $seconds)
411-
: "Waited {$seconds} seconds for callback."
412-
);
413-
}
414-
415-
$this->pause($interval);
416-
}
400+
},
401+
$message ? sprintf($message, $seconds) : "Waited {$seconds} seconds for callback."
402+
);
417403

418404
return $this;
419405
}

src/ElementResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ElementResolver
2929
/**
3030
* Set the elements the resolver should use as shortcuts.
3131
*
32-
* @var array
32+
* @var array<string, string>
3333
*/
3434
public $elements = [];
3535

@@ -62,7 +62,7 @@ public function __construct($driver, $prefix = 'body')
6262
/**
6363
* Set the page elements the resolver should use as shortcuts.
6464
*
65-
* @param array $elements
65+
* @param array<string, string> $elements
6666
* @return $this
6767
*/
6868
public function pageElements(array $elements)

0 commit comments

Comments
 (0)