简体   繁体   中英

Rspec and Watir; use array param as for an element index

Running GUI tests using Rspec. Is it possible for me to pass an array of values and have them used as the index position for an element?

Something like:

def pin_specific_idxs(*idx)
    pins = foo.divs(:class => 'some-element', :index => idx).div(:class, 'another-element').button(:class, 'thingy-i-want-to-click')
    pins.each do |pin|
        pin.click
    end
end

So in testing, I would call pin_specific_idxs(0,2,3)

Is that doable or do I have to explicitly call individual index values every time?

You need to do 2 things:

  • Iterate over the passed in indices rather than passing the whole Array as a parameter to :index
  • Locate the specific div rather than divs using the :index (ie element collections do not support the :index locator)

This would look like:

def pin_specific_idxs(*idxs)
  idxs.each do |idx|
    foo.div(:class => 'some-element', :index => idx)
       .div(:class, 'another-element')
       .button(:class, 'thingy-i-want-to-click')
       .click
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM