P
P
PQR2019-12-13 20:52:15
Software testing
PQR, 2019-12-13 20:52:15

Laravel Dusk: how to check button lock after form submit?

Question about Laravel Dusk. I read the documentation, googled, searched on StackOverflow until I could find a solution, maybe you have come across.
There is a form, there is a Submit button. I wrote a little JavaScript that, when clicked, blocks the Submit button so that the user doesn't accidentally click twice. The form is sent by a regular post request, the page is reloaded, the user gets some result.
I want to write a test that when the button is clicked, it is really blocked. Work for Laravel Dusk?
I am writing a test:

$this->browse(function (Browser $browser) {
    $browser->visit('/')
        ->click('@my-button')
        ->assertButtonDisabled('@my-button');
}

(@my-button - this is such a tricky syntax of selectors in Dusk - everything is right here, the error is definitely not in this https://laravel.com/docs/6.0/dusk#dusk-selectors )
The test fails with the error “Expected button [@ my-button] to be disabled, but it wasn't.“.
In the screenshot, I see the page where the browser gets after submitting the form, i.e. Dusk doesn't have time to check that the button was disabled on the original page.
For the purity of the experiment, I wrote inside the form tag so that the browser does not go anywhere, I run the test - it passes! Because the browser didn't navigate and Dusk successfully checked that the button was disabled on the original page. Question:<form onsubmit="return false">
how to rewrite the test in order to have time to catch the button's blocked state before the browser moves to another page?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question