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
+3


source to share


2 answers


As you might have guessed - double_click

does not match a double click. To make two clicks, you can do

find("#my-button").click.click

      



Or, depending on your mistake, you may need to sleep a bit between these two clicks

find("#my-button").tap do |b|
  b.click
  sleep 0.1
  b.click
end

      

+1


source


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)

      

0


source







All Articles