Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate two fast clicks on a submit button in Capybara?

I have a bug in my app which occurs if a user clicks the submit button of a form very quickly twice in a row. I can reliably reproduce this on production and in my development environment.

Is it possible for me 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 variations with execute_script do not work.

Everything I tried only caused my server-side code to be invoked once, even though console.log logging showed that click was indeed invoked twice. So I suspect there's something fundamentally missing from the capabilities of capybara and poltergeist simulate this behavior.

Is there a way to somehow invoke phantomJS at a lower level and achieve this?

I did try increasing the concurrency of my web server, it didn't help.


  • capybara 2.14.0
  • rails 5.1.0
  • poltergeist 1.15.0
  • phantomjs 2.1.1
like image 574
John Bachir Avatar asked Oct 29 '25 05:10

John Bachir


1 Answers

As you guessed - double_click is not the same as click twice. To have two clicks you can do

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

Or, depending on your bug you may need to sleep a little between those two clicks

find("#my-button").tap do |b|
  b.click
  sleep 0.1
  b.click
end
like image 148
Thomas Walpole Avatar answered Oct 30 '25 21:10

Thomas Walpole