File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55namespace Pest \Browser ;
66
77use Pest \Browser \Playwright \Client ;
8+ use Pest \Browser \Playwright \Page ;
9+ use Pest \Browser \Playwright \Playwright ;
810use Pest \Browser \Playwright \Server ;
911use Pest \Plugin ;
1012use Pest \Plugins \Parallel ;
@@ -24,6 +26,23 @@ function visit(string $url): PendingTest
2426 }
2527}
2628
29+ if (! function_exists ('\Pest\Browser\page ' )) {
30+ /**
31+ * Visits the given URL, and starts a new browser test.
32+ */
33+ function page (string $ url = '/ ' ): Page
34+ {
35+ Server::instance ()->start ();
36+ Client::instance ()->connectTo (Server::instance ()->url ('?browser=chromium ' ));
37+
38+ $ browser = Playwright::chromium ()->launch ();
39+ $ page = $ browser ->newPage ();
40+ $ page ->goto ($ url );
41+
42+ return $ page ;
43+ }
44+ }
45+
2746register_shutdown_function (function (): void {
2847 if (Parallel::isEnabled () || ! Parallel::isWorker ()) {
2948 Server::instance ()->stop ();
Original file line number Diff line number Diff line change 44
55namespace Pest \Browser ;
66
7+ use Pest \Browser \Playwright \Page ;
8+
79/**
810 * @internal
911 */
@@ -16,4 +18,12 @@ public function visit(string $url): PendingTest
1618 {
1719 return visit ($ url );
1820 }
21+
22+ /**
23+ * gets the page instance for given URL.
24+ */
25+ public function page (string $ url ): Page
26+ {
27+ return page ($ url );
28+ }
1929}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use PHPUnit \Framework \ExpectationFailedException ;
6+
7+ describe ('assertChecked ' , function () {
8+ it ('passes when checkbox is checked ' , function () {
9+ $ page = $ this ->page (playgroundUrl ('/test/form-inputs ' ));
10+
11+ expect ($ page ->querySelector ('input[name="checked-checkbox"] ' ))->toBeChecked ();
12+ });
13+
14+ it ('fails when checkbox is not checked ' , function () {
15+ $ page = $ this ->page (playgroundUrl ('/test/form-inputs ' ));
16+
17+ expect ($ page ->querySelector ('input[name="unchecked-checkbox"] ' ))->toBeChecked ();
18+ })->throws (ExpectationFailedException::class);
19+ });
Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5+ use Pest \Browser \Playwright \Element ;
6+ use Pest \Expectation ;
57use Pest \TestSuite ;
68
79pest ()
@@ -27,3 +29,12 @@ function playgroundUrl(string $path = '/'): string
2729{
2830 return 'http://localhost:9357/ ' .mb_ltrim ($ path , '/ ' );
2931}
32+
33+ // todo: move this to Pest core
34+ expect ()->extend ('toBeChecked ' , function (): Expectation {
35+
36+ expect ($ this ->value )->toBeInstanceOf (Element::class)
37+ ->and ($ this ->value ->isChecked ())->toBeTrue ();
38+
39+ return $ this ;
40+ });
You can’t perform that action at this time.
0 commit comments