-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathBrowser.php
89 lines (69 loc) · 2.43 KB
/
Browser.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Tests;
use Facebook\WebDriver\Remote\LocalFileDetector;
use Illuminate\Support\Str;
use Laravel\Dusk\Browser as BaseBrowser;
use PHPUnit\Framework\Assert as PHPUnit;
class Browser extends BaseBrowser
{
/**
* The default wait time in seconds.
*
* @var int
*/
public static $waitSeconds = 10;
public function getTextIn($selector): string
{
return $this->resolver->findOrFail($selector)->getText();
}
public function assertLinkCanonical($href)
{
$driverHref = $this->driver->executeScript('return document.querySelector("link[rel=\"canonical\"]")?.getAttribute("href")');
PHPUnit::assertEquals(
$href,
$driverHref,
"Canonical link expected href [{$href}] does not equal actual href [{$driverHref}]."
);
return $this;
}
public function assertMetaByName($name, $content)
{
$driverContent = $this->driver->executeScript('return document.querySelector("meta[name=\"' . $name . '\"]")?.getAttribute("content")');
PHPUnit::assertEquals(
$content,
$driverContent,
"Meta with name [{$name}] expected content [{$content}] does not equal actual title [{$driverContent}]."
);
return $this;
}
public function attachToFilepond($path)
{
$element = $this->resolver->firstOrFail(['input[type=file].filepond--browser']);
$element->setFileDetector(new LocalFileDetector)->sendKeys($path);
$filename = pathinfo($path, PATHINFO_BASENAME);
if ($element->getAttribute('data-server') === 'false') {
return $this->waitForText($filename)->pause(250);
}
$assistants = $this->resolver->all('.filepond--assistant');
return $this->waitUsing(10, 50, function () use ($assistants, $filename) {
foreach ($assistants as $assistant) {
if (Str::contains($assistant->getText(), ["{$filename} Upload complete"])) {
return true;
}
}
return false;
})->pause(250);
}
/**
* Scroll screen to element at the given selector.
*
* @param string $selector
* @return $this
*/
public function scrollToOffset($top)
{
$this->ensurejQueryIsAvailable();
$this->driver->executeScript("jQuery(\"html, body\").animate({scrollTop: {$top}}, 0);");
return $this;
}
}