2

Calabash ios 具有 each_cell 方法来对表格的每个单元格执行操作。

each_cell(:query => "tableView", :animate => false, :post_scroll => 0.1) do |row, sec|
touch("tableViewCell indexPath:#{row},#{sec}")
tap "back_button"
end

我有一个集合视图,然后我尝试使用相同的代码

each_cell(:query => "collectionView", :animate => false, :post_scroll => 0.1) do |row, sec|
touch("collectionViewCell indexPath:#{row},#{sec}")
tap "back_button"
end

但它不起作用并出现此错误:

NoMethodError:“ * ”的未定义方法“次”:字符串

所以我认为这个功能可能仅限于满足表格视图?关于如何对集合视图上的每个单元格执行操作的任何想法?谢谢!

4

1 回答 1

-1

我所做的是...

  1. 创建一个each_item类似的函数each

    def each_item(opts={:query => 'UICollectionView', :post_scroll => 2, :animate => true}, &block)
      uiquery = opts[:query] || 'UICollectionView'
      check_element_exists(uiquery)
      secs = query(uiquery,:numberOfSections).first
      secs.times do |sec|
        items = query(uiquery,{:numberOfItemsInSection => sec}).first
        items.times do |item_pos|
          scroll_to_collection_view_item(item_pos, sec, opts)
          sleep(opts[:post_scroll]) if opts[:post_scroll] and opts[:post_scroll] > 0
         yield(item_pos, sec)
        end
      end
    end    
    
  2. 要使用这个,你可以做这样的事情

    each_item do |item_pos, section_number|
      # YOUR CODE HERE
      # to use the query with collection view item
      # query("<HERE USE YOUR CUSTOM CLASS OF THE ITEMS IN THE CELLS> indexPath:#{item_pos},#{section_number}")
    end
    
于 2015-08-17T19:50:09.527 回答