How do i scroll a UITable view down until i see a cell with label “Value” in Calabash

本秂侑毒 提交于 2019-12-20 03:33:09

问题


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


回答1:


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.




回答2:


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



回答3:


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



回答4:


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


来源:https://stackoverflow.com/questions/16339676/how-do-i-scroll-a-uitable-view-down-until-i-see-a-cell-with-label-value-in-cal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!