From d7a4bc711c15f5eb9daeb9c0580e10e1a1e42879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 2 Jul 2021 15:40:29 +0200 Subject: [PATCH] Post-installation of laravel/dusk --- tests/Browser/ExampleTest.php | 23 +++++++++++ tests/Browser/Pages/HomePage.php | 41 +++++++++++++++++++ tests/Browser/Pages/Page.php | 20 +++++++++ tests/Browser/console/.gitignore | 2 + tests/Browser/screenshots/.gitignore | 2 + tests/DuskTestCase.php | 61 ++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 tests/Browser/ExampleTest.php create mode 100644 tests/Browser/Pages/HomePage.php create mode 100644 tests/Browser/Pages/Page.php create mode 100644 tests/Browser/console/.gitignore create mode 100644 tests/Browser/screenshots/.gitignore create mode 100644 tests/DuskTestCase.php diff --git a/tests/Browser/ExampleTest.php b/tests/Browser/ExampleTest.php new file mode 100644 index 000000000000..9d8968b2f00c --- /dev/null +++ b/tests/Browser/ExampleTest.php @@ -0,0 +1,23 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Laravel'); + }); + } +} diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 000000000000..e01f999980d5 --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,41 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 000000000000..f8d76222c01b --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 000000000000..d6b7ef32c847 --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/screenshots/.gitignore b/tests/Browser/screenshots/.gitignore new file mode 100644 index 000000000000..d6b7ef32c847 --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 000000000000..b4394174318d --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,61 @@ +addArguments(collect([ + '--window-size=1920,1080', + ])->unless($this->hasHeadlessDisabled(), function ($items) { + return $items->merge([ + '--disable-gpu', + '--headless', + ]); + })->all()); + + return RemoteWebDriver::create( + $_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515', + DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } + + /** + * Determine whether the Dusk command has disabled headless mode. + * + * @return bool + */ + protected function hasHeadlessDisabled() + { + return isset($_SERVER['DUSK_HEADLESS_DISABLED']) || + isset($_ENV['DUSK_HEADLESS_DISABLED']); + } +}