-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
40 lines (34 loc) · 987 Bytes
/
Copy pathfunctions.php
File metadata and controls
40 lines (34 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace CoStack\StackTest;
use Exception;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverElement;
use function is_string;
function resolveElementText(WebDriverElement $element): string
{
return match ($element->getTagName()) {
'textarea', 'input' => $element->getAttribute('value'),
'select' => throw new Exception('TODO implementation'),
default => $element->getText(),
};
}
/**
* @param WebDriver $driver
* @param WebDriverBy|array<WebDriverBy>|string $by
* @return WebDriverElement|array<WebDriverElement>
*/
function resolve(WebDriver $driver, WebDriverBy|array|string $by): WebDriverElement|array|string
{
if ($by instanceof WebDriverBy) {
return $driver->findElement($by);
}
if (is_string($by)) {
return $by;
}
foreach ($by as $index => $bye) {
$by[$index] = resolve($driver, $bye);
}
return $by;
}