2

Calabash ios has the each_cell method to perform an action on each cell of a table.

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

I got a collection view, then I tried to use the same code

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

But it wasn't working and got this error:

NoMethodError: undefined method `times' for "*":String

So I reckon this function could be limited to only cater table views? Any idea on how to perform action on each cell on collection view? Thanks!

user3363340
  • 55
  • 1
  • 9

1 Answers1

-1

what i did was...

  1. Create a function called each_item similar to 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. To Use this, you can do something like this

    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
    
nlips
  • 1,258
  • 9
  • 25