繁体   English   中英

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

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

使用Rspec运行GUI测试。 我是否可以传递值的数组并将其用作元素的索引位置?

就像是:

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

因此,在测试中,我将调用pin_specific_idxs(0,2,3)

那可行吗,还是我每次都必须显式调用单个索引值?

您需要做两件事:

  • 遍历传入的索引,而不是将整个Array作为参数传递给:index
  • 使用:index找到特定的div而不是divs (即元素集合不支持:index定位器)

看起来像:

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