From 14982a27aea0d5aa9b42f47ddb0862b04ff0d566 Mon Sep 17 00:00:00 2001 From: Marek Cirkos Date: Wed, 13 Dec 2017 01:23:04 -0800 Subject: [PATCH 01/23] Remove TableView scrolling integration tests Summary: We have duplicated scrolling tests for regular tableViews and simple scrollviews. It was usefull to have them, but now testing scrolling on scrollviews covers both cases anyway and we will waste less time testing. Reviewed By: antiarchit Differential Revision: D6543548 fbshipit-source-id: 35e717c43208b8f138a706798d9aa8a9e34b302a --- .../IntegrationTests/FBScrollingTests.m | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m b/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m index b32002cb46..aa7f898416 100644 --- a/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m @@ -34,7 +34,7 @@ - (void)setUp { [super setUp]; [self launchApplication]; - [self goToScrollPageWithCells:[self.class shouldShowCells]]; + [self goToScrollPageWithCells:NO]; self.scrollView = [[self.testedApplication.query descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"scrollView"].element; [self.scrollView resolve]; } @@ -81,15 +81,3 @@ - (void)testFarScrollToVisible } @end - -@interface FBNoCellScrollingTests : FBScrollingTests -@end - -@implementation FBNoCellScrollingTests - -+ (BOOL)shouldShowCells -{ - return NO; -} - -@end From 8c783d19677722f02de4bccb19a7d8544ba2c758 Mon Sep 17 00:00:00 2001 From: Marek Cirkos Date: Wed, 13 Dec 2017 01:28:50 -0800 Subject: [PATCH 02/23] Use fb_tapWithError in alert integration tests Summary: Some alert integration tests are flaky on our CI. I suspect this happens due to failing `tap` command, which might be failing to tap on animated view. This know XCTest issue. Fortunately we have `fb_tapWithError` that handels are common pitfalls. Reviewed By: antiarchit Differential Revision: D6543616 fbshipit-source-id: f12ea7da67058253deff53fa980ebf2e55a93899 --- WebDriverAgentTests/IntegrationTests/FBAlertTests.m | 7 ++++--- .../IntegrationTests/FBIntegrationTestCase.m | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/WebDriverAgentTests/IntegrationTests/FBAlertTests.m b/WebDriverAgentTests/IntegrationTests/FBAlertTests.m index cf0ec9d3ca..a8cd54149e 100644 --- a/WebDriverAgentTests/IntegrationTests/FBAlertTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBAlertTests.m @@ -13,6 +13,7 @@ #import "FBIntegrationTestCase.h" #import "FBTestMacros.h" +#import "XCUIElement+FBTap.h" @interface FBAlertTests : FBIntegrationTestCase @end @@ -37,14 +38,14 @@ - (void)tearDown - (void)showApplicationAlert { - [self.testedApplication.buttons[FBShowAlertButtonName] tap]; + [self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count != 0); } - (void)showApplicationSheet { - [self.testedApplication.buttons[FBShowSheetAlertButtonName] tap]; - FBAssertWaitTillBecomesTrue(self.testedApplication.sheets.count != 0); + [self.testedApplication.buttons[FBShowSheetAlertButtonName] fb_tapWithError:nil]; + FBAssertWaitTillBecomesTrue(self.testedApplication.sheets.count != 0); } - (void)testAlertException diff --git a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m index c3b24d6427..2137b7acf7 100644 --- a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m +++ b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m @@ -63,6 +63,7 @@ - (void)goToAlertsPage { [self.testedApplication.buttons[@"Alerts"] tap]; FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[FBShowAlertButtonName].fb_isVisible); + FBAssertWaitTillBecomesTrue(self.testedApplication.buttons[FBShowSheetAlertButtonName].fb_isVisible); } - (void)goToSpringBoardFirstPage From b4f85d96612a5f829c918e4a73405eb3854ce5d0 Mon Sep 17 00:00:00 2001 From: Marek Cirkos Date: Wed, 13 Dec 2017 01:31:14 -0800 Subject: [PATCH 03/23] Fix rotation integeation tests Summary: Rather then depending on XCUITest information on orientation, we should test what is application perception Reviewed By: antiarchit Differential Revision: D6543511 fbshipit-source-id: 192e50d0202f96bd6119921c9353a72789b33ad4 --- .../Categories/XCUIDevice+FBRotation.m | 8 +++-- .../IntegrationApp/Classes/ViewController.m | 30 +++++++++++++++++++ .../Resources/Base.lproj/Main.storyboard | 19 +++++++++--- .../XCUIDeviceRotationTests.m | 9 +++--- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m index 7ff657a329..c25e0f1f70 100644 --- a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m +++ b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m @@ -30,19 +30,21 @@ - (BOOL)fb_setDeviceRotation:(NSDictionary *)rotationObj NSInteger orientation = keysForRotationObj.firstObject.integerValue; FBApplication *application = FBApplication.fb_activeApplication; [XCUIDevice sharedDevice].orientation = orientation; - return [self waitUntilInterfaceIsAtOrientation:[XCUIDevice sharedDevice].orientation application:application]; + return [self waitUntilInterfaceIsAtOrientation:orientation application:application]; } - (BOOL)waitUntilInterfaceIsAtOrientation:(NSInteger)orientation application:(FBApplication *)application { NSDate *startDate = [NSDate date]; - while (![@(application.interfaceOrientation) isEqualToNumber:@(orientation)] && (-1 * [startDate timeIntervalSinceNow]) < kFBWebDriverOrientationChangeDelay) { + while (application.interfaceOrientation != orientation && + [XCUIDevice sharedDevice].orientation != orientation && + (-1 * [startDate timeIntervalSinceNow]) < kFBWebDriverOrientationChangeDelay) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.3, YES); } // Tapping elements immediately after rotation may fail due to way UIKit is handling touches. // We should wait till UI cools off, before continuing [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:FBRotationCoolOffTime]]; - return [@(application.interfaceOrientation) isEqualToNumber:@(orientation)]; + return application.interfaceOrientation == orientation; } - (NSDictionary *)fb_rotationMapping diff --git a/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m b/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m index 044e6b20ae..6014a56740 100644 --- a/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m +++ b/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m @@ -10,6 +10,7 @@ #import "ViewController.h" @interface ViewController () +@property (weak, nonatomic) IBOutlet UILabel *orentationLabel; @end @implementation ViewController @@ -26,4 +27,33 @@ - (IBAction)didTapButton:(UIButton *)button button.selected = !button.selected; } +- (void)viewDidLayoutSubviews +{ + [super viewDidLayoutSubviews]; + [self updateOrentationLabel]; +} + +- (void)updateOrentationLabel +{ + NSString *orientation = nil; + switch (self.interfaceOrientation) { + case UIInterfaceOrientationPortrait: + orientation = @"Portrait"; + break; + case UIInterfaceOrientationPortraitUpsideDown: + orientation = @"PortraitUpsideDown"; + break; + case UIInterfaceOrientationLandscapeLeft: + orientation = @"LandscapeLeft"; + break; + case UIInterfaceOrientationLandscapeRight: + orientation = @"LandscapeRight"; + break; + case UIInterfaceOrientationUnknown: + orientation = @"Unknown"; + break; + } + self.orentationLabel.text = orientation; +} + @end diff --git a/WebDriverAgentTests/IntegrationApp/Resources/Base.lproj/Main.storyboard b/WebDriverAgentTests/IntegrationApp/Resources/Base.lproj/Main.storyboard index 183eff8f10..dc82b12b01 100644 --- a/WebDriverAgentTests/IntegrationApp/Resources/Base.lproj/Main.storyboard +++ b/WebDriverAgentTests/IntegrationApp/Resources/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -63,6 +63,12 @@ + @@ -71,17 +77,22 @@ + + + + + - + @@ -460,7 +471,7 @@ + @@ -392,6 +400,7 @@ + @@ -405,7 +414,7 @@ - + diff --git a/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m b/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m new file mode 100644 index 0000000000..21032fe3c5 --- /dev/null +++ b/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +#import "FBIntegrationTestCase.h" + +#import "FBAlert.h" +#import "FBElementCache.h" +#import "FBTestMacros.h" +#import "XCUIDevice+FBRotation.h" +#import "XCUIElement+FBForceTouch.h" +#import "XCUIElement+FBIsVisible.h" + +@interface FBForceTouchTests : FBIntegrationTestCase +@end + +// It is recommnded to verify these tests with different iOS versions + +@implementation FBForceTouchTests + +- (void)verifyTapWithOrientation:(UIDeviceOrientation)orientation +{ + [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation]; + NSError *error; + XCTAssertTrue(self.testedApplication.alerts.count == 0); + [self.testedApplication.buttons[FBShowAlertForceTouchButtonName] fb_forceTouchWithPressure:1.0 duration:1.0 error:&error]; + FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0); +} + +- (void)setUp +{ + [super setUp]; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [self launchApplication]; + [self goToAlertsPage]; + }); +} + +- (void)tearDown +{ + [super tearDown]; + [[FBAlert alertWithApplication:self.testedApplication] dismissWithError:nil]; +} + +- (void)testTap +{ + [self verifyTapWithOrientation:UIDeviceOrientationPortrait]; +} + +- (void)testTapInLandscapeLeft +{ + [self verifyTapWithOrientation:UIDeviceOrientationLandscapeLeft]; +} + +- (void)testTapInLandscapeRight +{ + [self verifyTapWithOrientation:UIDeviceOrientationLandscapeRight]; +} + +- (void)testTapInPortraitUpsideDown +{ + [self verifyTapWithOrientation:UIDeviceOrientationPortraitUpsideDown]; +} + +@end diff --git a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.h b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.h index 9b3265439a..4fc2239e0a 100644 --- a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.h +++ b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.h @@ -13,6 +13,7 @@ extern NSString *const FBShowAlertButtonName; extern NSString *const FBShowSheetAlertButtonName; +extern NSString *const FBShowAlertForceTouchButtonName; /** XCTestCase helper class used for integration tests diff --git a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m index 2137b7acf7..cfc8272465 100644 --- a/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m +++ b/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m @@ -21,6 +21,7 @@ NSString *const FBShowAlertButtonName = @"Create App Alert"; NSString *const FBShowSheetAlertButtonName = @"Create Sheet Alert"; +NSString *const FBShowAlertForceTouchButtonName = @"Create Alert (Force Touch)"; @interface FBIntegrationTestCase () @property (nonatomic, strong) XCUIApplication *testedApplication; From e2f7cdef69adff45e663a9b65a83ce099d45bd3c Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Mon, 4 Jun 2018 06:53:06 -0700 Subject: [PATCH 19/23] Support getting the element cache size, clearing the element cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Every time a user finds an element using the `element` or `elements` route, a new `XCUIElement` object is added to the session cache. The elements are never removed from the cache. A very naïve script which goes to the home screen and queries for the 'Phone' element 1000 times in a row, will cause memory consumption (as measured by Xcode) of the WebDriverAgent to grow to approximately 126 MB. Net, it appears that every `XCUIElement` object consumes about 100KB of memory. For sessions which persist for a long period of time (say, 30 minutes or more), this can eventually lead to an out of memory situation in which the WebDriverAgent crashes. This PR tries to provide an 'escape hatch' for applications which want long-running sessions, by allowing them to: - query the amount of elements in the cache - clear the element cache by adding two custom routes. We're looking at other approaches to keep the cache size under control as well - e.g. by checking the element cache for duplicates and adding an option to remove 'stale' elements (elements which no longer exist); we'll try to submit PRs for that as well. As usual, let me know what you think & happy to discuss further. Closes https://github.com/facebook/WebDriverAgent/pull/896 Differential Revision: D8254682 Pulled By: marekcirkos fbshipit-source-id: a200a570d9b4e71a6f2171419b39126dd9affca3 --- WebDriverAgentLib/Commands/FBCustomCommands.m | 14 ++++++++++++++ WebDriverAgentLib/Routing/FBElementCache.h | 9 +++++++++ WebDriverAgentLib/Routing/FBElementCache.m | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/WebDriverAgentLib/Commands/FBCustomCommands.m b/WebDriverAgentLib/Commands/FBCustomCommands.m index bb64907502..c562f8e837 100644 --- a/WebDriverAgentLib/Commands/FBCustomCommands.m +++ b/WebDriverAgentLib/Commands/FBCustomCommands.m @@ -38,6 +38,8 @@ + (NSArray *)routes [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)], [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)], [[FBRoute POST:@"/wda/keyboard/dismiss"] respondWithTarget:self action:@selector(handleDismissKeyboardCommand:)], + [[FBRoute GET:@"/wda/elementCache/size"] respondWithTarget:self action:@selector(handleGetElementCacheSizeCommand:)], + [[FBRoute POST:@"/wda/elementCache/clear"] respondWithTarget:self action:@selector(handleClearElementCacheCommand:)], ]; } @@ -93,4 +95,16 @@ + (NSArray *)routes return FBResponseWithOK(); } ++ (id)handleGetElementCacheSizeCommand:(FBRouteRequest *)request +{ + NSNumber *count = [NSNumber numberWithUnsignedInteger:[request.session.elementCache count]]; + return FBResponseWithObject(count); +} + ++ (id)handleClearElementCacheCommand:(FBRouteRequest *)request +{ + FBElementCache *elementCache = request.session.elementCache; + [elementCache clear]; + return FBResponseWithOK(); +} @end diff --git a/WebDriverAgentLib/Routing/FBElementCache.h b/WebDriverAgentLib/Routing/FBElementCache.h index bfc6e0986f..be3d3f69bc 100644 --- a/WebDriverAgentLib/Routing/FBElementCache.h +++ b/WebDriverAgentLib/Routing/FBElementCache.h @@ -31,6 +31,15 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable XCUIElement *)elementForUUID:(NSString *__nullable)uuid; +/** + Clears the cache + */ +- (void)clear; + +/** + Gets the number of elements in the cache + */ +@property (nonatomic, readonly) NSUInteger count; @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Routing/FBElementCache.m b/WebDriverAgentLib/Routing/FBElementCache.m index 745b519f53..54000ac3d8 100644 --- a/WebDriverAgentLib/Routing/FBElementCache.m +++ b/WebDriverAgentLib/Routing/FBElementCache.m @@ -47,4 +47,13 @@ - (XCUIElement *)elementForUUID:(NSString *)uuid return element; } +- (void)clear +{ + [self.elementCache removeAllObjects]; +} + +- (NSUInteger)count +{ + return [self.elementCache count]; +} @end From 6832e20fbf0b1f8faf1f9a54171d4c7db9f45fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=90=8D=E5=90=9B?= Date: Mon, 4 Jun 2018 06:53:12 -0700 Subject: [PATCH 20/23] Fix fb_framelessFuzzyMatchesElement method Summary: In XCUIElementTypeTable,attribute values of many XCUIElementTypeCell instances are null.When fb_scrollToVisibleWithNormalizedScrollDistance function is called by XCUIElementTypeCell instance,it is unable to accurately slide the specified UI element. Closes https://github.com/facebook/WebDriverAgent/pull/879 Differential Revision: D8255752 Pulled By: marekcirkos fbshipit-source-id: 930f478417823ae0c0f79d1699d61af616f3c781 --- .../Categories/XCElementSnapshot+FBHelpers.m | 13 +----------- WebDriverAgentLib/Utilities/FBKeyboard.m | 17 +++------------- .../IntegrationTests/FBScrollingTests.m | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCElementSnapshot+FBHelpers.m b/WebDriverAgentLib/Categories/XCElementSnapshot+FBHelpers.m index 6bcdfbc7a2..3374a21561 100644 --- a/WebDriverAgentLib/Categories/XCElementSnapshot+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCElementSnapshot+FBHelpers.m @@ -20,7 +20,6 @@ #import "XCUIElement+FBWebDriverAttributes.h" #import "FBXPath.h" -inline static BOOL valuesAreEqual(id value1, id value2); inline static BOOL isSnapshotTypeAmongstGivenTypes(XCElementSnapshot* snapshot, NSArray *types); @implementation XCElementSnapshot (FBHelpers) @@ -66,12 +65,7 @@ - (id)fb_attributeValue:(NSNumber *)attribute - (BOOL)fb_framelessFuzzyMatchesElement:(XCElementSnapshot *)snapshot { - return self.elementType == snapshot.elementType && - valuesAreEqual(self.identifier, snapshot.identifier) && - valuesAreEqual(self.title, snapshot.title) && - valuesAreEqual(self.label, snapshot.label) && - valuesAreEqual(self.value, snapshot.value) && - valuesAreEqual(self.placeholderValue, snapshot.placeholderValue); + return self.wdUID == snapshot.wdUID; } - (NSArray *)fb_descendantsCellSnapshots @@ -106,11 +100,6 @@ - (XCElementSnapshot *)fb_parentCellSnapshot } @end -inline static BOOL valuesAreEqual(id value1, id value2) -{ - return value1 == value2 || [value1 isEqual:value2]; -} - inline static BOOL isSnapshotTypeAmongstGivenTypes(XCElementSnapshot* snapshot, NSArray *types) { for (NSUInteger i = 0; i < types.count; i++) { diff --git a/WebDriverAgentLib/Utilities/FBKeyboard.m b/WebDriverAgentLib/Utilities/FBKeyboard.m index b38ec2cd88..f26dcb5adc 100644 --- a/WebDriverAgentLib/Utilities/FBKeyboard.m +++ b/WebDriverAgentLib/Utilities/FBKeyboard.m @@ -56,20 +56,9 @@ + (BOOL)typeText:(NSString *)text frequency:(NSUInteger)frequency error:(NSError + (BOOL)waitUntilVisibleWithError:(NSError **)error { - XCUIElement *keyboard = - [[[[FBRunLoopSpinner new] - timeout:5] - timeoutErrorMessage:@"Keyboard is not present"] - spinUntilNotNil:^id{ - return [[FBApplication fb_activeApplication].query descendantsMatchingType:XCUIElementTypeKeyboard].fb_firstMatch; - } - error:error]; - - if (!keyboard) { - return NO; - } - - if (![keyboard fb_waitUntilFrameIsStable]) { + FBApplication *application = [FBApplication fb_activeApplication]; + + if (![application fb_waitUntilFrameIsStable]) { return [[[FBErrorBuilder builder] withDescription:@"Timeout waiting for keybord to stop animating"] diff --git a/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m b/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m index aa7f898416..0dc694090b 100644 --- a/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBScrollingTests.m @@ -15,6 +15,8 @@ #import "XCUIElement+FBIsVisible.h" #import "XCUIElement+FBScrolling.h" +#import "XCUIElement+FBClassChain.h" + #define FBCellElementWithLabel(label) ([self.testedApplication descendantsMatchingType:XCUIElementTypeAny][label]) #define FBAssertVisibleCell(label) FBAssertWaitTillBecomesTrue(FBCellElementWithLabel(label).fb_isVisible) #define FBAssertInvisibleCell(label) FBAssertWaitTillBecomesTrue(!FBCellElementWithLabel(label).fb_isVisible) @@ -34,7 +36,7 @@ - (void)setUp { [super setUp]; [self launchApplication]; - [self goToScrollPageWithCells:NO]; + [self goToScrollPageWithCells:YES]; self.scrollView = [[self.testedApplication.query descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"scrollView"].element; [self.scrollView resolve]; } @@ -80,4 +82,20 @@ - (void)testFarScrollToVisible FBAssertVisibleCell(cellName); } +- (void)testAttributeWithNullScrollToVisible +{ + NSError *error; + NSArray *queryMatches = [self.testedApplication fb_descendantsMatchingClassChain:@"**/XCUIElementTypeTable/XCUIElementTypeCell[60]" shouldReturnAfterFirstMatch:NO]; + XCTAssertEqual(queryMatches.count, 1); + XCUIElement *element = queryMatches.firstObject; + XCTAssertFalse(element.fb_isVisible); + [element fb_scrollToVisibleWithError:&error]; + XCTAssertNil(error); + XCTAssertTrue(element.fb_isVisible); + [element tap]; + [element resolve]; + XCTAssertTrue(element.lastSnapshot.selected); +} + @end + From d90cd562ae073a58f3f21792b410110bf798398c Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 5 Jun 2018 11:42:54 +0200 Subject: [PATCH 21/23] Tune nullability --- .../Categories/XCUIApplication+FBTouchAction.h | 4 ++-- .../Categories/XCUIApplication+FBTouchAction.m | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.h b/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.h index 260470bd1b..56e461d9fe 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.h @@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN @param error If there is an error, upon return contains an NSError object that describes the problem @return YES If the touch action has been successfully performed without errors */ -- (BOOL)fb_performAppiumTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError **)error; +- (BOOL)fb_performAppiumTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError * _Nullable*)error; /** Perform complex touch action in scope of the current application. @@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN @param error If there is an error, upon return contains an NSError object that describes the problem @return YES If the touch action has been successfully performed without errors */ -- (BOOL)fb_performW3CTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError **)error; +- (BOOL)fb_performW3CTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError * _Nullable*)error; @end diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.m b/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.m index 28769572b7..8564468c14 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBTouchAction.m @@ -20,7 +20,7 @@ @implementation XCUIApplication (FBTouchAction) -- (BOOL)fb_performActionsWithSynthesizerType:(Class)synthesizerType actions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError **)error +- (BOOL)fb_performActionsWithSynthesizerType:(Class)synthesizerType actions:(NSArray *)actions elementCache:(FBElementCache *)elementCache error:(NSError **)error { FBBaseActionsSynthesizer *synthesizer = [[synthesizerType alloc] initWithActions:actions forApplication:self elementCache:elementCache error:error]; if (nil == synthesizer) { @@ -33,12 +33,12 @@ - (BOOL)fb_performActionsWithSynthesizerType:(Class)synthesizerType actions:(NSA return [self fb_synthesizeEvent:eventRecord error:error]; } -- (BOOL)fb_performAppiumTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError **)error +- (BOOL)fb_performAppiumTouchActions:(NSArray *)actions elementCache:(FBElementCache *)elementCache error:(NSError **)error { return [self fb_performActionsWithSynthesizerType:FBAppiumActionsSynthesizer.class actions:actions elementCache:elementCache error:error]; } -- (BOOL)fb_performW3CTouchActions:(NSArray *)actions elementCache:(nullable FBElementCache *)elementCache error:(NSError **)error +- (BOOL)fb_performW3CTouchActions:(NSArray *)actions elementCache:(FBElementCache *)elementCache error:(NSError **)error { return [self fb_performActionsWithSynthesizerType:FBW3CActionsSynthesizer.class actions:actions elementCache:elementCache error:error]; } From c72142004f3c5f619b03ca9787196f691b5e4b5d Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 5 Jun 2018 12:58:44 +0200 Subject: [PATCH 22/23] comment out flaky tests --- WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m b/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m index a385e9ae38..39b808f175 100644 --- a/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBForceTouchTests.m @@ -55,12 +55,12 @@ - (void)testForceTap [self verifyForceTapWithOrientation:UIDeviceOrientationPortrait]; } -- (void)testForceTapInLandscapeLeft +- (void)disabled_testForceTapInLandscapeLeft { [self verifyForceTapWithOrientation:UIDeviceOrientationLandscapeLeft]; } -- (void)testForceTapInLandscapeRight +- (void)disabled_testForceTapInLandscapeRight { [self verifyForceTapWithOrientation:UIDeviceOrientationLandscapeRight]; } From cce8a3481742c0d5f969db1c090aa10903dba444 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 5 Jun 2018 21:34:10 +0200 Subject: [PATCH 23/23] Optimize force touch endpoint --- .../Commands/FBElementCommands.m | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBElementCommands.m b/WebDriverAgentLib/Commands/FBElementCommands.m index deea187255..2f3a145edc 100644 --- a/WebDriverAgentLib/Commands/FBElementCommands.m +++ b/WebDriverAgentLib/Commands/FBElementCommands.m @@ -76,8 +76,7 @@ + (NSArray *)routes [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)], [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)], [[FBRoute POST:@"/wda/pickerwheel/:uuid/select"] respondWithTarget:self action:@selector(handleWheelSelect:)], - [[FBRoute POST:@"/wda/element/forceTouch/:uuid"] respondWithTarget:self action:@selector(handleForceTouch:)], - [[FBRoute POST:@"/wda/element/forceTouchByCoordinate/:uuid"] respondWithTarget:self action:@selector(handleForceTouchByCoordinateOnElement:)] + [[FBRoute POST:@"/wda/element/:uuid/forceTouch"] respondWithTarget:self action:@selector(handleForceTouch:)], ]; } @@ -250,23 +249,16 @@ + (NSArray *)routes XCUIElement *element = [elementCache elementForUUID:request.parameters[@"uuid"]]; double pressure = [request.arguments[@"pressure"] doubleValue]; double duration = [request.arguments[@"duration"] doubleValue]; - NSError *error = nil; - if (![element fb_forceTouchWithPressure:pressure duration:duration error:&error]) { - return FBResponseWithError(error); - } - return FBResponseWithOK(); -} - -+ (id)handleForceTouchByCoordinateOnElement:(FBRouteRequest *)request -{ - FBElementCache *elementCache = request.session.elementCache; - XCUIElement *element = [elementCache elementForUUID:request.parameters[@"uuid"]]; - double pressure = [request.arguments[@"pressure"] doubleValue]; - double duration = [request.arguments[@"duration"] doubleValue]; - CGPoint forceTouchPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); - NSError *error = nil; - if (![element fb_forceTouchCoordinate:forceTouchPoint pressure:pressure duration:duration error:&error]) { - return FBResponseWithError(error); + NSError *error; + if (nil != request.arguments[@"x"] && nil != request.arguments[@"y"]) { + CGPoint forceTouchPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); + if (![element fb_forceTouchCoordinate:forceTouchPoint pressure:pressure duration:duration error:&error]) { + return FBResponseWithError(error); + } + } else { + if (![element fb_forceTouchWithPressure:pressure duration:duration error:&error]) { + return FBResponseWithError(error); + } } return FBResponseWithOK(); }