簡體   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