-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support different gestures in landscape mode #411
Support different gestures in landscape mode #411
Conversation
@@ -58,6 +59,8 @@ + (NSArray *)routes | |||
[[FBRoute POST:@"/uiaElement/:uuid/twoFingerTap"] respondWithTarget:self action:@selector(handleTwoFingerTap:)], | |||
[[FBRoute POST:@"/uiaElement/:uuid/touchAndHold"] respondWithTarget:self action:@selector(handleTouchAndHold:)], | |||
[[FBRoute POST:@"/uiaElement/:uuid/scroll"] respondWithTarget:self action:@selector(handleScroll:)], | |||
[[FBRoute POST:@"/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)], |
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.
Can you not use different endpoint something like /wda/dragfromtoforduration
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.
I have just created it based on existing API methods examples, like "/touchAndHold" and "/doubleTap". Shouldn't we follow the same template there?
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.
Those are legacy stuff, that should die.
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.
ok then I will use wda/ prefix as you suggested
@@ -58,6 +59,8 @@ + (NSArray *)routes | |||
[[FBRoute POST:@"/uiaElement/:uuid/twoFingerTap"] respondWithTarget:self action:@selector(handleTwoFingerTap:)], | |||
[[FBRoute POST:@"/uiaElement/:uuid/touchAndHold"] respondWithTarget:self action:@selector(handleTouchAndHold:)], | |||
[[FBRoute POST:@"/uiaElement/:uuid/scroll"] respondWithTarget:self action:@selector(handleScroll:)], | |||
[[FBRoute POST:@"/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)], | |||
// TODO: remove obsolete endpoint | |||
[[FBRoute POST:@"/uiaTarget/:uuid/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)], |
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.
We should split those handler. I don't like that we try to handle both cases in one handle and being smart about element presence.
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.
no pb - I will implement both methods
CGSize FBAdjustDimensionsForApplication(CGSize actualSize, UIInterfaceOrientation orientation) | ||
{ | ||
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { | ||
if (actualSize.height > actualSize.width) { |
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.
?
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.
XCTest bug is, that it returns exchanged dimensions for landscape mode. This verification is just to make sure the bug is still there (since height is never greater than width in landscape) and to make it still working properly after XCTest itself starts to respect landscape.
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.
Can you and comment on that?
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.
sure
XCUICoordinate *gestureCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:point]; | ||
return gestureCoordinate; | ||
// TODO: handle this properly after XCTest starts to respect landscape interface orientation | ||
CGPoint point = FBInvertPointForApplication(coordinate, application.frame.size, application.interfaceOrientation); |
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.
- You should check for iOS version here as well.
- Instead of forcing those checks everywhere, you might want to consider adding
FBUICoordinate
class and patch coordinates on the go?
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.
You should check for iOS version here as well.
This might be a bad idea, because you never know whether given coordinates were calculated based on some element position or just based on the actual screen size. I would prefer to keep it like this, because this is generic method and only have such verification for methods, where we explicitly calculate offset based on element location (like tap)
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.
- Instead of forcing those checks everywhere, you might want to consider adding FBUICoordinate class and patch coordinates on the go?
I think this might be too complicated. There are many places where you can read these coordinates (wdRect, wdFrame). Plus these a widely used for internal calculations and we need to cover the case, that iOS9.3 properly calculates them
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.
Yes, but all versions checks etc, would happen in that class. So final product would be "transparent" for all clients. All of them should expect correct values anyway. Only problem would be argument you made in first point.
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.
Let's make it simple. Most of users don't even use 20% of features we have here. I could think about improving this if there are enough complains in Appium forum. But for now it might take a lot of time to just create a workaround for the stuff, which is not widely used. And time is money 💯
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.
I've also noticed one more thing, that is not going to be resolved if we just transform element coordinates. All the methods of XCUIElement, like doubleTap, pinch, etc will still fail in landscape. We anyway need to replace them with something, that does the same action by coordinates (actually, this is what you've already done for click) :-(
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.
Nice work, however I think we can do much better.
I am sorry @mykola-mokhnach, I will not be able to merge this before Christmas. There are few things I would like do differently, but I wouldn't have time to sit to properly. |
@marekcirkos Any progress on this pr? |
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.
Ok, Let's get done with it :).
@param relativeCoordinate hit point coordinate relative to the current element position | ||
@return YES if the operation succeeds, otherwise NO. | ||
*/ | ||
- (BOOL)fb_tapCoordinateWithError:(NSError **)error relativeCoordinate:(CGPoint)relativeCoordinate; |
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.
Error parameter should be last.
- (BOOL)fb_tapAtRelativeCoordinate:(CGPoint)relativeCoordinate error:(NSError **)error;
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.
fixed
CGPoint hitPoint = hitpointValue ? hitpointValue.CGPointValue : [self coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)].screenPoint; | ||
hitPoint = FBInvertPointForApplication(hitPoint, self.application.frame.size, self.application.interfaceOrientation); | ||
CGPoint hitPoint = CGPointMake(self.frame.origin.x + relativeCoordinate.x, self.frame.origin.y + relativeCoordinate.y); | ||
// TODO: Change that after XCTest starts to respect landscape orientation |
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.
Instead of todo I would add comment why this is needed.
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.
added detailed comment
@@ -206,7 +208,8 @@ + (NSArray *)routes | |||
|
|||
+ (id<FBResponsePayload>)handleDoubleTapCoordinate:(FBRouteRequest *)request | |||
{ | |||
XCUICoordinate *doubleTapCoordinate = [self.class getGestureCoordinate:request]; | |||
CGPoint doubleTapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); | |||
XCUICoordinate *doubleTapCoordinate = [self.class gestureCoordinateWithCoordinate:doubleTapPoint application:request.session.application shouldApplyOrientationWorkaround:YES]; |
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.
Why you always apply changes here without iOS check? Would it be better to make iOS check inside that method?
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.
Sorry, please ignore my recent comment. This is done, because in iOS 9.3 drag coordinates are also inverted. So the current implementation works properly if one provides absolute coordinates based on the actual screen width/height, but will not work if relative coordinates based on some element position are provided. I think the first case is more relevant for such method call. If one wanted to have a thing that performs drag on element by its relative coordinates, then he would create some other method (something like tap for clicking). But the method above only accepts absolute coordinates
@imurchie what is your opinion on it?
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.
Just to summarise what we know:
- On iOS 9.x coordinates are not inverted
- On iOS 10.x coordinates are inverted
- We can assume that coordinates passed by user are correct (meaning they are in reference to current orientation). This is mainly because we give them the coordinates or they manually calculate them.
Is that right?
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.
- On iOS 9.x coordinates are not inverted
Yes, but only coordinates we get when we want to know XCUIElement frame. All the other XCUIElement methods have the same bug as in 10.0+
On iOS 10.x coordinates are inverted
Yes, but this might be fixed in any of upcoming iOS releases.
- We can assume that coordinates passed by user are correct (meaning they are in reference to current orientation). This is mainly because we give them the coordinates or they manually calculate them.
I want to discuss this point with @imurchie, because most of WDA calls where we do operations with absolute screen coordinates cannot be invoked directly from Appium, but rather via TouchAction interface. And we need to be in sync about our expectations here.
@mykola-mokhnach is it ready for review or we are waiting for @imurchie? |
Yes, this is ready from my side. I just want @imurchie to take a final look at this PR, because he was working on TouchAction interface in Appium, which, actually, is the main consumer of fixed WDA API methods. |
Looks good to me! This will be awesome to get in! |
Hi @marekcirkos |
XCUICoordinate *appCoordinate = [[XCUICoordinate alloc] initWithElement:session.application normalizedOffset:CGVectorMake(0, 0)]; | ||
XCUICoordinate *endCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:endPoint]; | ||
XCUICoordinate *startCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:startPoint]; | ||
BOOL shouldApplyOrientationWorkaround = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0"); |
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.
Why we care about iOS version if we are handling coordinates there that are always buggy?
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.
here we calculate coordinates based on element's position, which is calculated properly for iOS 9.3 and is broken for iOS10.0+
In other cases coordinates are passed as absolute values.
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.
Ok, let's do this then!
@marekcirkos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
…ng values (#411) * Fix for appium/appium#7055 (comment) * Fix test data
Summary: Fixes facebookarchive/WebDriverAgent#362 Closes facebookarchive/WebDriverAgent#411 Differential Revision: D4461734 Pulled By: marekcirkos fbshipit-source-id: b388682e70d11a498e6a5fa8eb33172514371dab
Fixes #362