Open dsebastien opened 3 weeks ago
To go to specific pages during e2e tests, we should use $browser->visitRoute('name');
To fill-in forms, we can use $browser->type('field name', 'value')
or $browser->typeSlowly('field name', 'value', 300)
(in ms)
Alternatively, we can add dusk='key'
to the form fields so that Dusk can locate those more easily. For instance if we have <input type="text" dusk="name" ...
, then we can do $browser->click('@name');
We can also register keyboard macros in AppServiceProvider.php's boot
method:
public function boot(): void {
Keyboard::macro('selectAll', function() {
$this->type([
OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
'a',
]);
});
Keyboard::macro('copy', function() {
$this->type([
OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
'c',
]);
});
Keyboard::macro('copyAll', function() {
$this->type([
OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
]);
return $this->copy();
});
Keyboard::macro('paste', function() {
$this->type([
OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
'v'
]);
});
}
With that, tests will be able to simply do: $browser->withKeyboard(fn (Keyboard $keyboard) => $keyboard->copyAll()); ...
We can also open multiple browsers in a single test: $this->browser(function (Browser $browser1, Browser $browser2) { ... }
To test pages that require authentication, use $browser->loginAs(User::find(1))->visit('/home');
Goal: be able to define and run e2e tests.
We should add Laravel Dusk and a few e2e test scenarios.
php artisan dusk
References:
Running on GH actions: