diff --git a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h index b947fcdda..1ff170864 100644 --- a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h +++ b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h @@ -32,6 +32,14 @@ NS_ASSUME_NONNULL_BEGIN /*! The UIDeviceOrientation to rotation mappings */ @property (strong, nonatomic, readonly) NSDictionary *fb_rotationMapping; +/** + The current physical device orientation as the raw UIDeviceOrientation name string, + e.g. UIDeviceOrientationPortrait, UIDeviceOrientationLandscapeLeft, + UIDeviceOrientationFaceUp. Returns UIDeviceOrientationUnknown if the orientation + cannot be determined. + */ +@property (copy, nonatomic, readonly) NSString *fb_deviceOrientation; + @end #endif diff --git a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m index 269d77f6c..d03e0aafd 100644 --- a/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m +++ b/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m @@ -64,6 +64,27 @@ - (BOOL)waitUntilInterfaceIsAtOrientation:(UIDeviceOrientation)orientation appli return application.interfaceOrientation == FBInterfaceOrientationFromDeviceOrientation(orientation); } +- (NSString *)fb_deviceOrientation +{ + switch (self.orientation) { + case UIDeviceOrientationPortrait: + return @"UIDeviceOrientationPortrait"; + case UIDeviceOrientationPortraitUpsideDown: + return @"UIDeviceOrientationPortraitUpsideDown"; + case UIDeviceOrientationLandscapeLeft: + return @"UIDeviceOrientationLandscapeLeft"; + case UIDeviceOrientationLandscapeRight: + return @"UIDeviceOrientationLandscapeRight"; + case UIDeviceOrientationFaceUp: + return @"UIDeviceOrientationFaceUp"; + case UIDeviceOrientationFaceDown: + return @"UIDeviceOrientationFaceDown"; + case UIDeviceOrientationUnknown: + default: + return @"UIDeviceOrientationUnknown"; + } +} + - (NSDictionary *)fb_rotationMapping { static NSDictionary *rotationMap; diff --git a/WebDriverAgentLib/Commands/FBOrientationCommands.m b/WebDriverAgentLib/Commands/FBOrientationCommands.m index bfadd984d..7e98b4a88 100644 --- a/WebDriverAgentLib/Commands/FBOrientationCommands.m +++ b/WebDriverAgentLib/Commands/FBOrientationCommands.m @@ -47,6 +47,8 @@ + (NSArray *)routes [[FBRoute GET:@"/rotation"].withoutSession respondWithTarget:self action:@selector(handleGetRotation:)], [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)], [[FBRoute POST:@"/rotation"].withoutSession respondWithTarget:self action:@selector(handleSetRotation:)], + [[FBRoute GET:@"/wda/deviceOrientation"] respondWithTarget:self action:@selector(handleGetDeviceOrientation:)], + [[FBRoute GET:@"/wda/deviceOrientation"].withoutSession respondWithTarget:self action:@selector(handleGetDeviceOrientation:)], ]; } @@ -113,6 +115,11 @@ + (NSArray *)routes return FBResponseWithOK(); } ++ (id)handleGetDeviceOrientation:(FBRouteRequest *)request +{ + return FBResponseWithObject(XCUIDevice.sharedDevice.fb_deviceOrientation); +} + #pragma mark - Helpers diff --git a/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m b/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m index 608798010..450cbd1bb 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m @@ -69,6 +69,27 @@ - (void)testLandscapeLeftRotation XCTAssertTrue(self.testedApplication.staticTexts[@"LandscapeRight"].exists); } +- (void)testGetDeviceOrientationInPortrait +{ + BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationPortrait]; + XCTAssertTrue(success, @"Device should support Portrait"); + XCTAssertEqualObjects([XCUIDevice sharedDevice].fb_deviceOrientation, @"UIDeviceOrientationPortrait"); +} + +- (void)testGetDeviceOrientationInLandscapeLeft +{ + BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeLeft]; + XCTAssertTrue(success, @"Device should support LandscapeLeft"); + XCTAssertEqualObjects([XCUIDevice sharedDevice].fb_deviceOrientation, @"UIDeviceOrientationLandscapeLeft"); +} + +- (void)testGetDeviceOrientationInLandscapeRight +{ + BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeRight]; + XCTAssertTrue(success, @"Device should support LandscapeRight"); + XCTAssertEqualObjects([XCUIDevice sharedDevice].fb_deviceOrientation, @"UIDeviceOrientationLandscapeRight"); +} + - (void)testRotationTiltRotation { UIDeviceOrientation currentRotation = [XCUIDevice sharedDevice].orientation;