From cddd4b59f90dbeee57039e15cbdd1aa0fea57be0 Mon Sep 17 00:00:00 2001
From: ALsJourney <63744576+ALsJourney@users.noreply.github.com>
Date: Fri, 6 Sep 2024 14:16:40 +0200
Subject: [PATCH 01/39] Added a basic login test and also added 2 small
variables to dev .env file
Small test just to see if you wish to continue this way of me writing tests in this shape and form. you can run them locally with php artisan dusk:chrome-driver --detect, run it with ./vendor/laravel/dusk/bin/chromedriver-mac-arm --port=9515 then run tests with php artisan dusk
---
.env.development.example | 2 ++
config/testing.php | 6 ++++++
tests/Browser/ExampleTest.php | 20 --------------------
tests/Browser/LoginTest.php | 30 ++++++++++++++++++++++++++++++
tests/DuskTestCase.php | 5 ++++-
5 files changed, 42 insertions(+), 21 deletions(-)
create mode 100644 config/testing.php
delete mode 100644 tests/Browser/ExampleTest.php
create mode 100644 tests/Browser/LoginTest.php
diff --git a/.env.development.example b/.env.development.example
index f9bcd361a..0f9e4c72e 100644
--- a/.env.development.example
+++ b/.env.development.example
@@ -13,6 +13,8 @@ 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
diff --git a/config/testing.php b/config/testing.php
new file mode 100644
index 000000000..41b8eadf0
--- /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 15dc8f5f1..000000000
--- 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 000000000..ffa83d09b
--- /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 8628871a1..d909d1c21 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;
}
}
From 38d4e4a035a050e9038a12ea04b016a399568f6d Mon Sep 17 00:00:00 2001
From: ALsJourney <63744576+ALsJourney@users.noreply.github.com>
Date: Sun, 8 Sep 2024 21:41:56 +0200
Subject: [PATCH 02/39] Added a HowTo Markdown on how to run tests
---
tests/How_To_Use_Dusk.md | 53 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 tests/How_To_Use_Dusk.md
diff --git a/tests/How_To_Use_Dusk.md b/tests/How_To_Use_Dusk.md
new file mode 100644
index 000000000..fc10bff8c
--- /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
From 67b17e871fe75e04a872da0f06c79ecb6df0aa39 Mon Sep 17 00:00:00 2001
From: Eric Dahl
Warning: Enable these
- options only if you fully understand their implications and
- consequences!
Improper use will result in data loss and could cause
- functional issues.