1

There are 20 different buttons to expect and needs to be clicked through to expect and verify the urls inside the code. I have tried different ways to implement my tests but they are failing.

I'm trying something like:

 page.all(:class => 'action red').each do |button|
   c = button.find(:class => 'action view red')
   c.click   
   page.driver.browser.switch_to.window(@new_window)
   expect('some element on those 20 different browsers sessions before closing them') 
   page.driver.browser.close
  end
end

I'm getting this error:

ArgumentError: invalid keys :class, should be one of :count, :minimum, :maximum, :between, :text, :visible, :exact, :match, :wait

Any can help me in the code how to perform get the elements of all the 20 buttons, store them and click them to expect the url each of them before closing it

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78

1 Answers1

0

Your "buttons" aren't buttons - since they are <a> elements they are actually links, styled to look like buttons.

Assuming that clicking each of these links actually opens a new window (since you're attempting to switch to a new window) then the code would be something like

page.all(:link, class: ['action', 'red']).each do |link|
  win = page.window_opened_by { link.click }
  page.within_window(win) do
    expect(page).to ... # whatever you need to expect
  end
  win.close()
end

Note this doesn't use any driver specific (.driver.browser...) methods - you should stay away from them whenever possible since they are generally a sign you're doing something wrong. Additionally, the :class option wasn't universally available on all of Capybaras builtin selector types until v2.10, so you will need to be using a newer version of Capybara for that.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks for your answer, but I'm getting another error: ArgumentError: invalid keys :class, should be one of :count, :minimum, :maximum, :between, :text, :visible, :exact, :match, :wait, :href –  Oct 13 '17 at 10:11
  • This is what I'm doing: page.all(:link, class: ['action', 'red']).each do |link| link.click expect(page).to have_css end –  Oct 13 '17 at 10:14
  • @Ayub check the version of Capybara you’re using – Thomas Walpole Oct 13 '17 at 14:39