简体   繁体   English

Rspec和Watir; 使用数组参数作为元素索引

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

Running GUI tests using Rspec. 使用Rspec运行GUI测试。 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) 因此,在测试中,我将调用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 遍历传入的索引,而不是将整个Array作为参数传递给:index
  • Locate the specific div rather than divs using the :index (ie element collections do not support the :index locator) 使用:index找到特定的div而不是divs (即元素集合不支持:index定位器)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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