dhemery / victor

A Java driver for iOS applications
MIT License
11 stars 4 forks source link

Does scrolling work in the iPhone simulator with Victor #11

Open bnr opened 12 years ago

bnr commented 12 years ago

Hi Dale,

I am using victor from last 6 months and finding it really a cool stuff. Right now facing issue in scrolling down and getting the data which is not visible in the screen(need to scroll down to get or find the data).

Right now I am not able to work with the objects which are not visible in Simulator.

Can you please help out with any one of the following:

How to Scroll down the screen and work with the object or Is it possible to work with the objects with out scrolling ( which is not visible in the simulator screen)

Thanks in advance, Ravi B.N

Trilokesh commented 12 years ago

hi Dale,

Recently I too encounter a similar situation. In one of the view when scroll-bar appears Victor unable to click the button which is not visible (need to scroll down to make it visible). In the above scenario how could I make touch method work?

Looking forward to your suggestion.

Thanks, Trilokesh

dhemery commented 12 years ago

The approach I've used so far. What I've done is scroll the table or scroll view to a particular position. To do this, I'd like to send the view a setContentOffset:animated: message, but I can't do that. That method's first parameter is a point, and I last time I checked Frank wasn't able to parse points.

So I added a new method (via a catagory on UIScrollView) that takes two points.

Here is the header file:

@interface UIScrollView (MyFrankExtensions)
-(void) myfx_setContentOffsetx: (NSUInteger) x y: (NSUInteger) y;
@end

Here is implementation file:

@implementation UIScrollView (MyFrankExtensions)
- (void)myfx_setContentOffsetx:(NSUInteger)x y:(NSUInteger)y {
    CGPoint point = CGPointMake(x, y);
    [self setContentOffset:point animated:YES];
}
@end

Now I can scroll by sending this message via Victor:

myScrollView.sendMessage("myfx_setContentOffsetx:y:", x, y);

A gestures-only approach. Another approach is to use Frank's relatively new "swipe" feature:

myScrollView.sendMessage("swipeInDirection:", "down");

I haven't tried this myself, because it wasn't available when I wrote my scroll view tests. I don't know how far Frank scrolls with each swipe.

dhemery commented 12 years ago

There's a quirk of table views: When an item scrolls out of view, the table view disconnects the item from its cell view and places the cell view in a pool of reusable cell views. When a new item of the same type scrolls into view, the table view displays it using one of the cell views from the pool.

The result is this: When an item scrolls out of view, there is no longer a view for that item.

So the answer is no, you cannot interact with the cell view for an item that has scrolled out of view. What you can do (if you have some Objective-C skill) is write a helper Objective-C method that will allow you to peek at the data source behind the table. The details of how to do that depend heavily on how the app is coded, so I can't advise about that.

rohitkothari85 commented 10 years ago

Hi Dhemery

I am also facing the same problem of scrolling down. Which I am not able to do. Can you pour some light on it, to make it more clear. How to implement the scroll down functionality.

-Rohit

dhemery commented 10 years ago

HI Rohit,

I don't know how to scroll directly.

Frank itself does not seem to provide a scroll method.

UIScrollView's setContentOffset:animated: method can scroll to any point within the view, but it takes a CGPoint as a parameter, and you can't send a GCPoint through the Frankly wire protocol.

So the solution I've used is to write an Objective C category for UIScrollView. The category defines a method that takes separate X and Y coordinates, which the Frankly wire protocol can send. It creates a CGPoint from the coordinates, and calls the UIScrollView's method. It looks something like this:

@implementation UIScrollView (MY_EXTENSIONS)
- (void)MY_EXTENSION_setContentOffsetx:(NSUInteger)x y:(NSUInteger)y {
    NSLog(@"%@%d,%d", NSStringFromSelector(_cmd), x, y);
    CGPoint point = CGPointMake(x, y);
    [self setContentOffset:point animated:YES];
}
@end

You have to compile this and link it into the app you want to test. Change MY_EXTENSIONS to some name that makes more sense for your situation.

Then you can scroll to any point in the view with Victor:

view.sendMessage("MY_EXTENSION_setContentOffsetx:y:", 10, 100);

This is not quite the same thing as a scroll gesture, but it suffices for the needs that my clients and I have had so far.

dhemery commented 10 years ago

You could also try:

view.sendMessage("swipeInDirection:", "down");

I haven't used that, myself, for two reasons:

First, I don't know how far the gesture scrolls. (I suppose I could experiment to find out, but I haven't yet.)

Second, if you're trying to scroll to a particular place, that turns out to be complicated. For one thing, you have to use a loop:

while(not yet at desired position) {
    view.sendMessage("swipeInDirection:", "down");
}

That's not so bad, but there's an additional complication: What happens if you reach the bottom of the screen before you reach the desired position?

My guess is if you swipe down when you're at the bottom of the view, Frank will succeed. If you haven't reached the desired position (because it is not in the view), the while loop will loop forever.

So you have to guard against that. Some ways to do that:

These complications are why we simply set the content offset to the desired position ;-)