I have the following step definition written with Cucumber based on Calabash. The name says it all: I want to touch every cell in the table view and go back to the table view again.
Then /^I touch every list item and go back again$/ do
total_sections = query("tableView", "numberOfSections")
last_section = total_sections[0] - 1
(0..last_section).each do |section|
total_rows = query("tableView", numberOfRowsInSection:section)
end_of_range = total_rows[0] - 1
(0..end_of_range).each do |row|
scroll_to_row "tableView", row
sleep(STEP_PAUSE)
macro %Q[I touch list item number #{row+1}]
macro %Q[I go back]
end
end
end
This works fine in a simple table view - but changing to a different tab containing a sectioned table view (A-Z) makes this script touch the first few cells and then it's getting weird: It scrolls correctly to the next cell but then it touches the after next cell until there is no visible cell to tap.
The only thing that is different between those two table views is that the failing one has sections and a lower row height. Why is it acting like this?
The problem lies in using the scroll_to_row
function. This is intended for simple table views which have only a single section.
The more general function scroll_to_cell
supports both sections and rows. The syntax is slightly different:
def scroll_to_cell(options={:query => "tableView",
:row => 0,
:section => 0,
:scroll_position => :top,
:animate => true})
...
end
for example
scroll_to_cell(:section => 1, :row => 2)
For your case there is also a high-level function each_cell
. For example:
each_cell(:query => "tableView") do |row, sec|
touch("tableViewCell indexPath:#{row},#{sec}")
#...
end