diff --git a/src/Operations/AssertMissing.php b/src/Operations/AssertMissing.php new file mode 100644 index 0000000..b033dde --- /dev/null +++ b/src/Operations/AssertMissing.php @@ -0,0 +1,29 @@ +selector); + + return "await expect(page.locator('{$escapedSelector}')).toBeHidden();"; + } +} diff --git a/src/Operations/AssertVisible.php b/src/Operations/AssertVisible.php new file mode 100644 index 0000000..3f7d9c2 --- /dev/null +++ b/src/Operations/AssertVisible.php @@ -0,0 +1,29 @@ +selector); + + return "await expect(page.locator('{$escapedSelector}')).toBeVisible();"; + } +} diff --git a/src/PendingTest.php b/src/PendingTest.php index 5970e4a..05596ce 100644 --- a/src/PendingTest.php +++ b/src/PendingTest.php @@ -137,6 +137,26 @@ public function clickLink(string $text, string $selector = 'a'): self return $this; } + /** + * Checks if the given element is visible. + */ + public function assertVisible(string $selector): self + { + $this->operations[] = new Operations\AssertVisible($selector); + + return $this; + } + + /** + * Checks if the given element is not visible. + */ + public function assertMissing(string $selector): self + { + $this->operations[] = new Operations\AssertMissing($selector); + + return $this; + } + /** * Compile the JavaScript test file. */ diff --git a/tests/Browser/Operations/AssertMissingTest.php b/tests/Browser/Operations/AssertMissingTest.php new file mode 100644 index 0000000..2c99c85 --- /dev/null +++ b/tests/Browser/Operations/AssertMissingTest.php @@ -0,0 +1,17 @@ +visit('https://laravel.com') + ->assertMissing('.DocSearch-Button-Keys'); + }); + + it('fails when the given element is visible', function () { + $this->visit('https://laravel.com') + ->assertMissing('body'); + })->throws(ProcessFailedException::class); +}); diff --git a/tests/Browser/Operations/AssertVisibleTest.php b/tests/Browser/Operations/AssertVisibleTest.php new file mode 100644 index 0000000..42dbfe7 --- /dev/null +++ b/tests/Browser/Operations/AssertVisibleTest.php @@ -0,0 +1,17 @@ +visit('https://laravel.com') + ->assertVisible('body'); + }); + + it('fails when the given element is not visible', function () { + $this->visit('https://laravel.com') + ->assertVisible('.DocSearch-Button-Keys'); + })->throws(ProcessFailedException::class); +});