-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathAutoload.php
More file actions
50 lines (40 loc) · 1.2 KB
/
Autoload.php
File metadata and controls
50 lines (40 loc) · 1.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
<?php
declare(strict_types=1);
namespace Pest\Browser;
use Pest\Browser\Playwright\Client;
use Pest\Browser\Playwright\Page;
use Pest\Browser\Playwright\Playwright;
use Pest\Browser\Playwright\Server;
use Pest\Plugin;
use Pest\Plugins\Parallel;
Plugin::uses(Browser::class);
if (! function_exists('\Pest\Browser\visit')) {
/**
* Visits the given URL, and starts a new browser test.
*/
function visit(string $url): PendingTest
{
Server::instance()->start();
Client::instance()->connectTo(Server::instance()->url('?browser=chromium'));
return (new PendingTest)->visit($url);
}
}
if (! function_exists('\Pest\Browser\page')) {
/**
* Visits the given URL, and starts a new browser test.
*/
function page(string $url = '/'): Page
{
Server::instance()->start();
Client::instance()->connectTo(Server::instance()->url('?browser=chromium'));
$browser = Playwright::chromium()->launch();
$page = $browser->newPage();
$page->goto($url);
return $page;
}
}
register_shutdown_function(function (): void {
if (Parallel::isEnabled() || ! Parallel::isWorker()) {
Server::instance()->stop();
}
});