Animations can cause Dusk tests to fail randomly.
For example, interacting with an element that is inside a modal might not work if the modal is still playing a slide-in animation.
A nice solution for flaky tests caused by animations is to disable animations while running Dusk tests.
Put this in the <head>
or your Blade template:
@if(is_running_dusk_tests())
<style>
* {
animation: none !important;
}
</style>
@endif
The is_running_dusk_tests()
is a helper function that checks the application environment:
function is_running_dusk_tests(): bool
{
return app()->environment('testing-dusk');
}
Make sure you have the correct environment set in your .env.dusk
:
Level up your Laravel deployments
If you aren't happy with your current deployment strategy for your Laravel apps, check out my premium deployment script.
Deploy with GitHub Actions
Deploy with GitLab CI/CD