Question

How do i scroll a UITableView down until i see a cell with label "Value" in Calabash/Cucumber. I've been trying to do it using:

      Then I swipe down until I see "Value"

and using:

      Then I scroll down until I see "Value"

but none of them seem to work. Thanks!

The message I get when I try with the above is obviously:

You can implement step definitions for undefined steps with these snippets:

Then(/^I swipe down until I see "(.*?)"$/) do |arg1| pending # express the regexp above with the code you wish you had end

Was it helpful?

Solution

add step definitions

Then /^I scroll to cell with "([^\"]*)" label$/ do |name|
    wait_poll(:until_exists => "label text:'#{name}'", :timeout => 20) do
    scroll("tableView", :down)
    end
end

to the ProjectName/features/step_definitions/my_first_steps.rb ruby file and In your calabash script add

Then I scroll to cell with "AAA" label

its working fine for me.

OTHER TIPS

Every cucumber framework has a set of predefined steps. Of course, these steps don't cover all the possibilites. If you need additional functionality, you have to define your own steps:

When /^I scroll (up|down) until I see "([^\"]*)"$/ do |direction, something_to_see|
   #implement the step here
end

I can't help you with the exact implementation (what is "Value"?) but you can find the core functions here

Probably you'll need function

scroll(uiquery, direction)

(where uiquery will be tableView)

If you take this function and element_is_not_hidden you can create a while cycle which will scroll down until you see the "Value".

Maybe something similar to the following (I don't know Calabash but I know Frank a little)

When /^I scroll (up|down) until I see "([^\"]*)"$/ do |direction, something_to_see|
   max_scroll_tries = 10

   [0..max_scroll_tries].each do
      break if element_is_not_hidden("view marked:'#{something_to_see}'")
      scroll("tableView", direction)
   end

   check_element_exists_and_is_visible("view marked:'#{something_to_see}'")
end

table have rows and sections, based how your code is organized use rows or sections in below code

def scroll_side_panel(text)

section=0
scroll_to_cell(:row => 0, :section => 0) # scroll to top of view
sleep 1 # wait for a second

#Scroll to each element and compare text, if there is a match break
each_cell(:animate => false, :post_scroll => 0.2) do |row, sec|
  puts "#{query("tableViewCell indexPath:#{row},#{sec} label", :text)}  #{text}"
  if query("tableViewCell indexPath:#{row},#{sec} label", :text).first==text
    break
  end
  section=section+1
end
puts "table view text found at element number:#{section}"
end

following should also work

Then(/^I scrolldown until "(.*?)" is visible$/) do |arg1|
  until query("lable text:'#{arg1}'").length > 0
    scroll("tableView", :down)
  end
end

Call this by following

Then I scrolldown until "XY" is visible
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top