-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathInteractsWithScreen.php
More file actions
45 lines (35 loc) · 1.12 KB
/
InteractsWithScreen.php
File metadata and controls
45 lines (35 loc) · 1.12 KB
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
<?php
declare(strict_types=1);
namespace Pest\Browser\Api\Concerns;
trait InteractsWithScreen
{
/**
* Performs a screenshot of the current page and saves it to the given path.
*/
public function screenshot(bool $fullPage = true, ?string $filename = null, ?string $scale = null): self
{
$filename = $this->getFilename($filename);
$this->page->screenshot($fullPage, $filename, $scale);
return $this;
}
/**
* Performs a screenshot of an element and saves it to the given path.
*/
public function screenshotElement(string $selector, ?string $filename = null, ?string $scale = null): self
{
$filename = $this->getFilename($filename);
$this->page->screenshotElement($selector, $filename, $scale);
return $this;
}
/**
* Get the filename for the screenshot.
*/
private function getFilename(?string $filename = null): string
{
if ($filename === null) {
// @phpstan-ignore-next-line
return str_replace('__pest_evaluable_', '', test()->name());
}
return $filename;
}
}