From 5ebc71c6ca2b364d44a44716e794885f8d3b6d9c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 31 Mar 2024 23:56:33 -0700 Subject: [PATCH] feat: add system screen size/width in the system info endpoint (#881) * feat: add system screen size/width * simplify * add nil statusBar case * tune --- WebDriverAgentLib/Commands/FBCustomCommands.m | 18 ++++++++++++++++-- WebDriverAgentLib/Utilities/FBScreen.h | 5 ----- WebDriverAgentLib/Utilities/FBScreen.m | 13 ------------- .../IntegrationTests/FBScreenTests.m | 7 ------- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBCustomCommands.m b/WebDriverAgentLib/Commands/FBCustomCommands.m index f31c96739..2ab039e6b 100644 --- a/WebDriverAgentLib/Commands/FBCustomCommands.m +++ b/WebDriverAgentLib/Commands/FBCustomCommands.m @@ -15,6 +15,7 @@ #import "FBConfiguration.h" #import "FBKeyboard.h" #import "FBNotificationsHelper.h" +#import "FBMathUtils.h" #import "FBPasteboard.h" #import "FBResponsePayload.h" #import "FBRoute.h" @@ -48,6 +49,7 @@ + (NSArray *)routes [[FBRoute GET:@"/wda/locked"].withoutSession respondWithTarget:self action:@selector(handleIsLocked:)], [[FBRoute GET:@"/wda/locked"] respondWithTarget:self action:@selector(handleIsLocked:)], [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)], + [[FBRoute GET:@"/wda/screen"].withoutSession respondWithTarget:self action:@selector(handleGetScreen:)], [[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)], [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession respondWithTarget:self action:@selector(handleActiveAppInfo:)], #if !TARGET_OS_TV // tvOS does not provide relevant APIs @@ -134,10 +136,22 @@ + (NSArray *)routes + (id)handleGetScreen:(FBRouteRequest *)request { - FBSession *session = request.session; - CGSize statusBarSize = [FBScreen statusBarSizeForApplication:session.activeApplication]; + XCUIApplication *app = XCUIApplication.fb_systemApplication; + + XCUIElement *mainStatusBar = app.statusBars.allElementsBoundByIndex.firstObject; + CGSize statusBarSize = (nil == mainStatusBar) ? CGSizeZero : mainStatusBar.frame.size; + +#if TARGET_OS_TV + CGSize screenSize = app.frame.size; +#else + CGSize screenSize = FBAdjustDimensionsForApplication(app.wdFrame.size, app.interfaceOrientation); +#endif + return FBResponseWithObject( @{ + @"screenSize":@{@"width": @(screenSize.width), + @"height": @(screenSize.height) + }, @"statusBarSize": @{@"width": @(statusBarSize.width), @"height": @(statusBarSize.height), }, diff --git a/WebDriverAgentLib/Utilities/FBScreen.h b/WebDriverAgentLib/Utilities/FBScreen.h index 61dc4aeb4..9c4cca87e 100644 --- a/WebDriverAgentLib/Utilities/FBScreen.h +++ b/WebDriverAgentLib/Utilities/FBScreen.h @@ -18,11 +18,6 @@ NS_ASSUME_NONNULL_BEGIN */ + (double)scale; -/** - The absolute size of application's status bar or CGSizeZero if it's hidden or does not exist - */ -+ (CGSize)statusBarSizeForApplication:(XCUIApplication *)application; - @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBScreen.m b/WebDriverAgentLib/Utilities/FBScreen.m index 8ebe080d5..17b7d8b19 100644 --- a/WebDriverAgentLib/Utilities/FBScreen.m +++ b/WebDriverAgentLib/Utilities/FBScreen.m @@ -19,17 +19,4 @@ + (double)scale return [XCUIScreen.mainScreen scale]; } -+ (CGSize)statusBarSizeForApplication:(XCUIApplication *)application -{ - XCUIApplication *app = XCUIApplication.fb_systemApplication; - // Since iOS 13 the status bar is no longer part of the application, it’s part of the SpringBoard - XCUIElement *mainStatusBar = app.statusBars.allElementsBoundByIndex.firstObject; - if (nil == mainStatusBar) { - return CGSizeZero; - } - CGSize result = mainStatusBar.frame.size; - // Workaround for https://github.com/appium/appium/issues/15961 - return CGSizeMake(MAX(result.width, result.height), MIN(result.width, result.height)); -} - @end diff --git a/WebDriverAgentTests/IntegrationTests/FBScreenTests.m b/WebDriverAgentTests/IntegrationTests/FBScreenTests.m index 4eff7fcd9..0f5bb5bbc 100644 --- a/WebDriverAgentTests/IntegrationTests/FBScreenTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBScreenTests.m @@ -28,12 +28,5 @@ - (void)testScreenScale XCTAssertTrue([FBScreen scale] >= 2); } -- (void)testStatusBarSize -{ - CGSize statusBarSize = [FBScreen statusBarSizeForApplication:self.testedApplication]; - BOOL statusBarSizeIsZero = CGSizeEqualToSize(CGSizeZero, statusBarSize); - XCTAssertFalse(statusBarSizeIsZero); -} - @end