How can I simulate two quick clicks on the submit button in Capybara?
I have an error in my application that occurs if the user clicks a form submit button very quickly twice in a row. I can reliably reproduce this in production and in my development environment.
Is it possible to reproduce this with Capybara / poltergeist / phantomjs?
find("#my-button").double_click
, find("#my-button").click.click
, execute_script("$('#register-button').click().click();")
, And other options execute_script
do not work.
Everything I tried only caused my server side code to shutdown once, although the log console.log
showed that it was click
indeed being called twice. Therefore, I suspect that something is fundamentally missing in the capybara and poltergeist capabilities that mimic this behavior.
Is there a way to somehow call phantomJS at a lower level and achieve this?
I tried to increase the concurrency of my webserver, it didn't help.
- capybara 2.14.0
- rails 5.1.0
- poltergeist 1.15.0
- phantomjs 2.1.1
source to share
Taking a slightly different approach here: what is the fix for this error? Would it be easier to verify the fix rather than verify that these actions cannot be performed?
For example, if the fix is ββto use Rails UJS disable-with
on <input type=submit>
, then your test might look something like this:
# replace `your_path` as required
visit your_path
# important: this stops the submission so the page doesn't change;
# but crucially doesn't stop UJS from doing its thing
execute_script("$('form').submit(function() { event.preventDefault() })")
# replace 'Submit form' and 'Processing...' text as appropriate
click_button('Submit form')
expect(page).to have_button('Processing...', disabled: true)
source to share