ruby-on-railscapybaraintegration-testing

Is there a built-in Capybara method to click on an element multiple times?


I have a form with a '+' icon to increase the number value inside of another tag.

So with Capybara I can just click on it like this:

all('.qty-input')[0].find('.more').click

But I want to be able to set the amount of clicks through a variable. I tried doing this but it raises an error because click does not accept any parameters.

all('.qty-input')[0].find('.more').click(number_of_clicks)

I think I can create a simple method to this, like this, but is it necessary? Doesn't Capybara have anything built-in for several clicks?

def multiple_clicks element, number_of_clicks
   number_of_clicks.times{|n| element.click}
end

Edit:

The original code I put there was

def multiple_clicks element, number_of_clicks
   number_of_clicks.map{|n| element.click}
end

Which doesn't make sense, so I edited it using times instead of map method.


Solution

  • No, Capybara doesn't have anything like that built-in