Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 represented as a WebDriver orientation string,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason to limit possible values by only these constants? Lets have a new string mapping that reflects properly what XCUIDevice.sharedDevice.fb_deviceOrientation returns

e.g. PORTRAIT, LANDSCAPE, UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT or
UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN. Returns UNKNOWN if the device orientation
cannot be mapped (e.g. face up/face down/unknown).
*/
@property (copy, nonatomic, readonly) NSString *fb_deviceOrientation;

@end
#endif

Expand Down
19 changes: 19 additions & 0 deletions WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ - (BOOL)waitUntilInterfaceIsAtOrientation:(UIDeviceOrientation)orientation appli
return application.interfaceOrientation == FBInterfaceOrientationFromDeviceOrientation(orientation);
}

- (NSString *)fb_deviceOrientation
{
switch (self.orientation) {
case UIDeviceOrientationPortrait:
return @"PORTRAIT";
case UIDeviceOrientationPortraitUpsideDown:
return @"UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN";
case UIDeviceOrientationLandscapeLeft:
return @"LANDSCAPE";
case UIDeviceOrientationLandscapeRight:
return @"UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT";
case UIDeviceOrientationUnknown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
default:
return @"UNKNOWN";
}
}

- (NSDictionary *)fb_rotationMapping
{
static NSDictionary *rotationMap;
Expand Down
7 changes: 7 additions & 0 deletions WebDriverAgentLib/Commands/FBOrientationCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:)],
];
}

Expand Down Expand Up @@ -113,6 +115,11 @@ + (NSArray *)routes
return FBResponseWithOK();
}

+ (id<FBResponsePayload>)handleGetDeviceOrientation:(FBRouteRequest *)request
{
return FBResponseWithObject(XCUIDevice.sharedDevice.fb_deviceOrientation);
}


#pragma mark - Helpers

Expand Down
21 changes: 21 additions & 0 deletions WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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, @"PORTRAIT");
}

- (void)testGetDeviceOrientationInLandscapeLeft
{
BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeLeft];
XCTAssertTrue(success, @"Device should support LandscapeLeft");
XCTAssertEqualObjects([XCUIDevice sharedDevice].fb_deviceOrientation, @"LANDSCAPE");
}

- (void)testGetDeviceOrientationInLandscapeRight
{
BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeRight];
XCTAssertTrue(success, @"Device should support LandscapeRight");
XCTAssertEqualObjects([XCUIDevice sharedDevice].fb_deviceOrientation, @"UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT");
}

- (void)testRotationTiltRotation
{
UIDeviceOrientation currentRotation = [XCUIDevice sharedDevice].orientation;
Expand Down
Loading