Merge pull request #3342 from ALsJourney/tests/LoginPageTest
Added a basic login test and also added 2 small variables to dev .env…
This commit is contained in:
@@ -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
|
||||
|
6
config/testing.php
Normal file
6
config/testing.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'dusk_test_email' => env('DUSK_TEST_EMAIL', 'test@example.com'),
|
||||
'dusk_test_password' => env('DUSK_TEST_PASSWORD', 'password'),
|
||||
];
|
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class ExampleTest extends DuskTestCase
|
||||
{
|
||||
/**
|
||||
* A basic browser test example.
|
||||
*/
|
||||
public function testBasicExample(): void
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/')
|
||||
->assertSee('Laravel');
|
||||
});
|
||||
}
|
||||
}
|
30
tests/Browser/LoginTest.php
Normal file
30
tests/Browser/LoginTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
use Throwable;
|
||||
|
||||
class LoginTest extends DuskTestCase
|
||||
{
|
||||
/**
|
||||
* A basic test for the login page.
|
||||
* Login with the test user and assert that the user is redirected to the dashboard.
|
||||
*
|
||||
* @return void
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function testLogin()
|
||||
{
|
||||
$email = config('testing.dusk_test_email');
|
||||
$password = config('testing.dusk_test_password');
|
||||
$this->browse(function (Browser $browser) use ($password, $email) {
|
||||
$browser->visit('/login')
|
||||
->type('email', $email)
|
||||
->type('password', $password)
|
||||
->press('Login')
|
||||
->assertPathIs('/');
|
||||
});
|
||||
}
|
||||
}
|
@@ -67,6 +67,9 @@ abstract class DuskTestCase extends BaseTestCase
|
||||
|
||||
protected function baseUrl()
|
||||
{
|
||||
return rtrim(config('app.url'), '/');
|
||||
$app_url = config('app.url');
|
||||
$port = config('app.port');
|
||||
|
||||
return $app_url.':'.$port;
|
||||
}
|
||||
}
|
||||
|
53
tests/How_To_Use_Dusk.md
Normal file
53
tests/How_To_Use_Dusk.md
Normal file
@@ -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
|
||||
|
||||
|
||||
```
|
Reference in New Issue
Block a user