From 6c1449cf9213db60ab2177b631c5af5250def18d Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 30 Aug 2024 00:39:43 +0100 Subject: [PATCH] Added dusk Signed-off-by: snipe --- composer.json | 1 + composer.lock | 140 +++++++++++++++++++++- resources/views/layouts/default.blade.php | 4 +- tests/Browser/LoginTest.php | 71 +++++++++++ tests/Browser/Pages/HomePage.php | 36 ++++++ tests/Browser/Pages/Page.php | 20 ++++ tests/Browser/console/.gitignore | 2 + tests/Browser/screenshots/.gitignore | 2 + tests/Browser/source/.gitignore | 2 + tests/DuskTestCase.php | 49 ++++++++ 10 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 tests/Browser/LoginTest.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/Browser/source/.gitignore create mode 100644 tests/DuskTestCase.php diff --git a/composer.json b/composer.json index a72d80839a..f00f19af9b 100644 --- a/composer.json +++ b/composer.json @@ -77,6 +77,7 @@ "brianium/paratest": "^7.0", "fakerphp/faker": "^1.16", "larastan/larastan": "^2.9", + "laravel/dusk": "^8.2", "mockery/mockery": "^1.4", "nunomaduro/phpinsights": "^2.11", "php-mock/php-mock-phpunit": "^2.10", diff --git a/composer.lock b/composer.lock index 715070df0f..bd85f58589 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3819ab4ef72eb77fabe494c0e746b83b", + "content-hash": "7a5bb887aeb2368dafece0dc0da75738", "packages": [ { "name": "alek13/slack", @@ -13071,6 +13071,78 @@ ], "time": "2024-05-27T18:33:26+00:00" }, + { + "name": "laravel/dusk", + "version": "v8.2.5", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "e641800393ce4ad39f0a47133f51aae67ceb01ad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/e641800393ce4ad39f0a47133f51aae67ceb01ad", + "reference": "e641800393ce4ad39f0a47133f51aae67ceb01ad", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "guzzlehttp/guzzle": "^7.5", + "illuminate/console": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "php": "^8.1", + "php-webdriver/webdriver": "^1.9.0", + "symfony/console": "^6.2|^7.0", + "symfony/finder": "^6.2|^7.0", + "symfony/process": "^6.2|^7.0", + "vlucas/phpdotenv": "^5.2" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "orchestra/testbench": "^8.19|^9.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.1|^11.0", + "psy/psysh": "^0.11.12|^0.12" + }, + "suggest": { + "ext-pcntl": "Used to gracefully terminate Dusk when tests are running." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Dusk\\DuskServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Dusk\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Dusk provides simple end-to-end testing and browser automation.", + "keywords": [ + "laravel", + "testing", + "webdriver" + ], + "support": { + "issues": "https://github.com/laravel/dusk/issues", + "source": "https://github.com/laravel/dusk/tree/v8.2.5" + }, + "time": "2024-08-26T12:34:33+00:00" + }, { "name": "league/container", "version": "4.2.2", @@ -13839,6 +13911,72 @@ }, "time": "2024-03-27T12:14:49+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.15.1", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^7.3 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^5.0 || ^6.0 || ^7.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.20.0", + "ondram/ci-detector": "^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^5.0 || ^6.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Exception/TimeoutException.php" + ], + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.15.1" + }, + "time": "2023-10-20T12:21:20+00:00" + }, { "name": "phpmyadmin/sql-parser", "version": "5.9.0", diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 993708dacc..398fe3432d 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -99,7 +99,7 @@ dir="{{ Helper::determineLanguageDirection() }}"> {{ trans('general.skip_to_main_content') }}
-
+
@@ -819,7 +819,7 @@ dir="{{ Helper::determineLanguageDirection() }}">
-

@yield('title')

+

@yield('title')

@if (isset($helpText)) @include ('partials.more-info', diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php new file mode 100644 index 0000000000..a1130b47be --- /dev/null +++ b/tests/Browser/LoginTest.php @@ -0,0 +1,71 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Login'); + }); + } + + /** + * A basic browser test example. + */ + public function testUserCanLoginAndSeeDashboard(): void + { + $user = User::factory()->superuser()->create([ + 'username' => 'admin', + 'password' => 'password', + ]); + + $this->browse(function (Browser $browser) use ($user) { + $browser->visit('/login') + ->type('username', $user->username) + ->type('password', 'password') + ->press('Login') + ->assertPathIs('/') + ->assertSeeIn('.pagetitle', 'Dashboard') + ->assertSeeIn('.alert-success', 'Success') + ->assertNotPresent('.alert-danger'); + + $browser->logout(); + }); + + + } + + /** + * A basic browser test example. + */ + public function testRegularUserCanLoginAndSeeProfile(): void + { + $user = User::factory()->create([ + 'password' => Hash::make('password'), + ]); + + $this->browse(function (Browser $browser) use ($user) { + $browser->logout() + ->visit('/login') + ->type('username', $user->username) + ->type('password', 'password') + ->press('Login') + ->assertPathIs('/account/view-assets') + ->assertSeeIn('.pagetitle', 'Hello') + ->assertNotPresent('.alert-danger') + ->logout(); + }); + } +} diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 0000000000..45d9283f37 --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,36 @@ + + */ + public function elements(): array + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 0000000000..eb9a2ded25 --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + + */ + public static function siteElements(): array + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 0000000000..d6b7ef32c8 --- /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 0000000000..d6b7ef32c8 --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/source/.gitignore b/tests/Browser/source/.gitignore new file mode 100644 index 0000000000..d6b7ef32c8 --- /dev/null +++ b/tests/Browser/source/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 0000000000..d34b71552a --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,49 @@ +addArguments(collect([ + $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080', + '--disable-search-engine-choice-screen', + ])->unless($this->hasHeadlessDisabled(), function (Collection $items) { + return $items->merge([ + '--disable-gpu', + '--headless=new', + ]); + })->all()); + + return RemoteWebDriver::create( + $_ENV['DUSK_DRIVER_URL'] ?? env('DUSK_DRIVER_URL') ?? 'http://localhost:9515', + DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } +}