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) {
                ->type('@input-login-email', $email)
                ->type('@input-login-password', $password)
    } catch (Exception $e) {

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.