3
votes

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?

2

2 Answers

4
votes

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');
        });
1
votes

I just came across the same issue, I assume it's simply not there when the assertion is tested, but then appears by the time the screenshot is taken.

Rather than add a 1-second delay you can also use ->waitForText() which will remove most unnessacary waiting time.