-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathScreenshotTest.php
More file actions
69 lines (46 loc) · 2 KB
/
ScreenshotTest.php
File metadata and controls
69 lines (46 loc) · 2 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Pest\Browser\Support\Screenshot;
it('captures a full-page screenshot', function (): void {
Route::get('/', fn (): string => 'Hello World');
$page = visit('/');
$page->screenshot(filename: 'full-page-screenshot.png');
expect(file_exists(Screenshot::path('full-page-screenshot.png')))
->toBeTrue();
});
it('captures a full-page screenshot with default filename', function (): void {
Route::get('/', fn (): string => 'Hello World');
$page = visit('/');
$page->screenshot();
$defaultFilename = str_replace('__pest_evaluable_', '', test()->name());
expect(file_exists(Screenshot::path($defaultFilename)))
->toBeTrue();
});
it('captures a screenshot with device scale', function (): void {
Route::get('/', fn (): string => 'Hello World');
$page = visit('/');
$page->screenshot(filename: 'device-scale-screenshot.png', scale: 'device');
expect(file_exists(Screenshot::path('device-scale-screenshot.png')))
->toBeTrue();
});
it('captures a screenshot of an specific element', function (): void {
Route::get('/', fn (): string => '<div>
<h1>Text outside of screenshot element</h1>
<div id="screenshot-element">Text inside of screenshot element</div>
</div>');
$page = visit('/');
$page->screenshotElement('#screenshot-element', 'element-screenshot.png');
expect(file_exists(Screenshot::path('element-screenshot.png')))
->toBeTrue();
});
it('captures a screenshot of an element with device scale', function (): void {
Route::get('/', fn (): string => '<div>
<h1>Text outside of screenshot element</h1>
<div id="screenshot-element">Text inside of screenshot element</div>
</div>');
$page = visit('/');
$page->screenshotElement('#screenshot-element', 'element-device-scale-screenshot.png', scale: 'device');
expect(file_exists(Screenshot::path('element-device-scale-screenshot.png')))
->toBeTrue();
});