laravellaravel-duskbrowser-testing

Laravel Dusk fails to assert seeing a text which is visible in the screenshot (using whenAvailable for modal)


I have written a Laravel Dusk test. I am trying to assert whether some text is visible after the modal is open. So, I am using the whenAvailable method. But it fails while I can see the text in the screenshot.

$browser->press('@finish-setup-button')
        ->whenAvailable('#modal-payment-info', function ($modal) use($paymentInfo) {
            $modal->assertSee(html_entity_decode(__('account_setup.payment')))
                  ->type('name', $paymentInfo->name)
                  ->type('iban', $paymentInfo->iban)
                  ->type('bic', $paymentInfo->bic)
                  ->press('@subscribe-button');
        });

I am getting the following message:

There was 1 failure:

1) Tests\Browser\RegistrationTest::testRegistration Did not see expected text [Payment] within element [body #modal-payment-info]. Failed asserting that false is true.

Screenshot:

enter image description here

What am I doing wrong?


Solution

  • I got a workaround. I added a pause of 1 second and it works fine.

    $browser->press('@finish-setup-button')
            ->whenAvailable('#modal-payment-info', function ($modal) use($paymentInfo) {
                $modal->pause(1000)
                      ->assertSee(html_entity_decode(__('account_setup.payment')))
                      ->type('name', $paymentInfo->name)
                      ->type('iban', $paymentInfo->iban)
                      ->type('bic', $paymentInfo->bic)
                      ->press('@subscribe-button');
            });