diff --git a/.env.development.example b/.env.development.example index d4daed4f74..00098446c7 100644 --- a/.env.development.example +++ b/.env.development.example @@ -8,6 +8,14 @@ APP_PORT=8000 APP_DEBUG=true SSH_MUX_ENABLED=true +# Enable Laravel Telescope for debugging +TELESCOPE_ENABLED=false + +# Selenium Driver URL for Dusk +DUSK_DRIVER_URL=http://selenium:4444 +DUSK_EMAIL=test@example.com +DUSK_PASSWORD=password + # PostgreSQL Database Configuration DB_DATABASE=coolify DB_USERNAME=coolify diff --git a/config/testing.php b/config/testing.php new file mode 100644 index 0000000000..41b8eadf01 --- /dev/null +++ b/config/testing.php @@ -0,0 +1,6 @@ + env('DUSK_TEST_EMAIL', 'test@example.com'), + 'dusk_test_password' => env('DUSK_TEST_PASSWORD', 'password'), +]; diff --git a/tests/Browser/ExampleTest.php b/tests/Browser/ExampleTest.php deleted file mode 100644 index 15dc8f5f12..0000000000 --- a/tests/Browser/ExampleTest.php +++ /dev/null @@ -1,20 +0,0 @@ -browse(function (Browser $browser) { - $browser->visit('/') - ->assertSee('Laravel'); - }); - } -} diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php new file mode 100644 index 0000000000..ffa83d09bb --- /dev/null +++ b/tests/Browser/LoginTest.php @@ -0,0 +1,30 @@ +browse(function (Browser $browser) use ($password, $email) { + $browser->visit('/login') + ->type('email', $email) + ->type('password', $password) + ->press('Login') + ->assertPathIs('/'); + }); + } +} diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index 8628871a18..d909d1c214 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -67,6 +67,9 @@ protected function hasHeadlessDisabled(): bool protected function baseUrl() { - return rtrim(config('app.url'), '/'); + $app_url = config('app.url'); + $port = config('app.port'); + + return $app_url.':'.$port; } } diff --git a/tests/How_To_Use_Dusk.md b/tests/How_To_Use_Dusk.md new file mode 100644 index 0000000000..fc10bff8c1 --- /dev/null +++ b/tests/How_To_Use_Dusk.md @@ -0,0 +1,53 @@ +# How to use Laravel Dusk in local development + +## Pre-requisites + +- Google Chrome installed on your machine (for the Chrome driver) +- everything else is already set up in the project + + +## Running Dusk in local development + +In order to use Laravel Dusk in local development, you need to run these commands: + +```bash +docker exec -it coolify php artisan dusk:chrome-driver --detect +``` + +The chrome driver will be installed under `./vendor/laravel/dusk/bin/chromedriver-linux`. + +Then you need to run the chrome-driver by hand. You can find the driver in the following path: +```bash +docker exec -it coolify ./vendor/laravel/dusk/bin/chromedriver-linux --port=9515 +``` + +### Running the tests on Apple Silicon + +If you are using an Apple Silicon machine, you need to install the Chrome driver locally on your machine with the following command: + +```bash +php artisan dusk:chrome-driver --detect +# then run it with the following command +./vendor/laravel/dusk/bin/chromedriver-mac-arm --port=9515 130 ↵ +``` + +### Running the tests + +Finally, you can run the tests with the following command: +```bash +docker exec -it coolify php artisan dusk +``` + +That's it. You should see the tests running in the terminal. +For proof, you can check the screenshot in the `tests/Browser/screenshots` folder. + +``` + + PASS Tests\Browser\LoginTest + ✓ login 3.63s + + Tests: 1 passed (1 assertions) + Duration: 3.79s + + +``` \ No newline at end of file