Laravel Dusk "if" statement
Published
on Jun 6, 2022
In some cases, we need an if statement in our Dusk test. There is no bulletproof solution for this situation, we have to figure it out by ourselves:
public function testTryLogin()
{
try {
$this->browse(function (Browser $browser) {
$browser->visit('/login')
->waitFor('@input-login-email')
->type('@input-login-email', $email)
->waitFor('@input-login-password')
->type('@input-login-password', $password)
->press('@input-login-submit')
->waitFor('.welcome');
});
} catch (Exception $e) {
dump($e->getMessage());
}
}
So yes, it looks simple because it is. You only need to use the try-catch pair and paste your code to the try section. You can leave empty the catch block if you want.