1

I'm working on testing an iOS app with Calabash, and ran into the problem where the command scroll 'UIScrollView', :down scrolls down the wrong view, since the first view it finds is a UIPageViewController, not the scrollview inside it.

Is there any way I can distinguish between the two views? The basic UIScrollView doesn't have a custom class, and I don't want to create one just for the sake of testing. Any other options? I can't find anything useful in the calabash docs.

Cheers!

Samuel Neugber
  • 1,041
  • 1
  • 11
  • 17

2 Answers2

4

Calabash queries support looking up by index. This approach is fragile, as the query depends on other views than the one you are looking for to correctly determine which view to match. A change in the rest of your UI could cause these queries to break.

However, if you have no unique identifier, using index is absolutely correct and not a bad solution, you should just be cautious.

query("UIScrollView index:1") will select the second UIScrollView. The query syntax is identical for all the gestures.

Tobias
  • 678
  • 4
  • 9
0

If there are no custom details that let you distinguish but you know that there is always just the two. You could do something like

sView = query "UIScrollView"
scroll sView[1], :down

I have not tested this particular sample code. But query for matches and then using a specific one is a valid approach.

Link to github syntax info https://github.com/calabash/calabash-ios/wiki/05-Query-syntax

Lasse
  • 1,153
  • 1
  • 10
  • 21
  • That doesn't work unfortunately, as the scroll command takes a query as the first parameter. I can't go calabash -> ruby -> calabash in this case, and afaik there is no way to select individual results from within a calabash query. – Samuel Neugber Mar 20 '15 at 09:24
  • irb(main):001:0> query("tabBarButton").count => 4 irb(main):002:0> query("tabBarButton")[0] => {"class"=>"UITabBarButton", "frame"=>{"y"=>1, "width"=>76, "x"=>2, "height"=>48}, "UIType"=>"UIControl", "description"=>">" } – Lasse Mar 20 '15 at 09:28