-
-
Notifications
You must be signed in to change notification settings - Fork 67
Allow Appium to Scroll To a particular element on screen #109
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -891,6 +891,55 @@ -(PFUIElement*) windowForHandle:(NSString*)windowHandle | |
| return [windows objectAtIndex:windowIndex]; | ||
| } | ||
|
|
||
| -(BOOL) scrollPage:(id)element | ||
| { | ||
| float increment_by = 0.25; | ||
| bool scroll_found = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use YES/NO constants with BOOL type |
||
| PFUIElement* scroll; | ||
| float axValue = 0,adder = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please define variables closer to the block where they used, also each variable should be defined in its own row |
||
|
|
||
| id parent = [(PFUIElement*)element AXParent]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the parent's type be more specific? |
||
| NSArray* siblings = [parent AXChildren]; | ||
|
|
||
| while(scroll == nil && parent != nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add space after while, if and other similar keywords to match with the common project style |
||
| { | ||
| for(id child in siblings) | ||
| { | ||
| if([[(PFUIElement*)child AXRole] isEqualToString:@"AXScrollBar"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reason to define the child element type as |
||
| { | ||
| scroll = child; | ||
| scroll_found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| parent = [(PFUIElement*)parent AXParent]; | ||
| siblings = [parent AXChildren]; | ||
| } | ||
|
|
||
| NSPoint middlePoint = [[element AXPosition] pointValue]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what |
||
| if(middlePoint.y < 0) | ||
| { | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this block be empty? |
||
| } | ||
|
|
||
| if(scroll_found) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could immediately return NO here if the var is false |
||
| { | ||
| while(adder<=1) | ||
| { | ||
| axValue = [scroll.AXValue floatValue]; | ||
| adder = axValue + increment_by; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be possible to have more descriptive name for the |
||
| scroll.AXValue = [NSNumber numberWithFloat: adder]; | ||
|
|
||
| if([self isElementDisplayed:element]) | ||
| { | ||
| return YES; | ||
| } | ||
| } | ||
| } | ||
| return NO; | ||
| } | ||
|
|
||
| -(GDataXMLDocument*)xmlPageSource | ||
| { | ||
| return [self xmlPageSourceFromRootUIElement:nil pathMap:nil xPath:nil]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -963,6 +963,28 @@ - (AppiumMacHTTPJSONResponse *)post_doubleclick:(NSString*)path data:(NSData *)p | |
| }]; | ||
| } | ||
|
|
||
|
|
||
| // POST /session/:sessionId/element/:id/scrollTo | ||
| // Scroll to the particular element passed to Appium. Scrolls till the bottom of the screen till the element becomes visible | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it always the case we need to scroll to the bottom? what if the destination element is located in the other direction, for example upper or at the right side? |
||
| // If the element is still not visible returns element not found | ||
| - (AppiumMacHTTPJSONResponse *)post_element_scrollTo:(NSString *)path data:(NSData *)postData | ||
| { | ||
| return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode) | ||
| { | ||
| id element = [commandParams objectForKey:@"elementObject"]; | ||
|
|
||
| if ([session isElementDisplayed:element]) { | ||
| return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId]; | ||
| } | ||
|
|
||
| BOOL result = [session scrollPage:element]; | ||
|
|
||
| return result ? [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId] : | ||
| [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchElement session:session.sessionId]; | ||
| }]; | ||
| } | ||
|
|
||
|
|
||
| // POST /session/:sessionId/touch/click | ||
| // Single tap on the touch enabled device. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please use camelCase naming to match with the current project coding style?