From 5470e0e526495c754cb5ca757c901479ec6b7328 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 01:39:54 -0700 Subject: [PATCH 1/6] chore: respect defaultActiveApplication --- WebDriverAgentLib/Routing/FBSession.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index d70c53432..0d9652df5 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -166,7 +166,8 @@ - (void)kill - (XCUIApplication *)activeApplication { - if (nil != self.testedApplication) { + BOOL isAuto = [self.defaultActiveApplication isEqualToString:FBDefaultApplicationAuto]; + if (isAuto && nil != self.testedApplication) { XCUIApplicationState testedAppState = self.testedApplication.state; if (testedAppState >= XCUIApplicationStateRunningForeground) { return (XCUIApplication *)self.testedApplication; @@ -177,7 +178,7 @@ - (XCUIApplication *)activeApplication } } - NSString *defaultBundleId = [self.defaultActiveApplication isEqualToString:FBDefaultApplicationAuto] + NSString *defaultBundleId = isAuto ? nil : self.defaultActiveApplication; return [XCUIApplication fb_activeApplicationWithDefaultBundleId:defaultBundleId]; From 9837d335fb218612c54d5ac6190f7803169c15e6 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 09:46:10 -0700 Subject: [PATCH 2/6] return immediately if the given defaultActiveApplication was already foreground --- WebDriverAgentLib/Routing/FBSession.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index 0d9652df5..2e73b551b 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -181,6 +181,11 @@ - (XCUIApplication *)activeApplication NSString *defaultBundleId = isAuto ? nil : self.defaultActiveApplication; + + if (nil != defaultBundleId && [self applicationStateWithBundleId:defaultBundleId] >= XCUIApplicationStateRunningForeground) { + return [self makeApplicationWithBundleId:defaultBundleId]; + } + return [XCUIApplication fb_activeApplicationWithDefaultBundleId:defaultBundleId]; } From 54915c116c695f840bf0674c52d0f9dd0b2c32bd Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 10:05:26 -0700 Subject: [PATCH 3/6] move the foreground check prior than the self.testedApplication --- WebDriverAgentLib/Routing/FBSession.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index 2e73b551b..baa5eb705 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -167,6 +167,14 @@ - (void)kill - (XCUIApplication *)activeApplication { BOOL isAuto = [self.defaultActiveApplication isEqualToString:FBDefaultApplicationAuto]; + NSString *defaultBundleId = isAuto + ? nil + : self.defaultActiveApplication; + + if (nil != defaultBundleId && [self applicationStateWithBundleId:defaultBundleId] >= XCUIApplicationStateRunningForeground) { + return [self makeApplicationWithBundleId:defaultBundleId]; + } + if (isAuto && nil != self.testedApplication) { XCUIApplicationState testedAppState = self.testedApplication.state; if (testedAppState >= XCUIApplicationStateRunningForeground) { @@ -178,14 +186,6 @@ - (XCUIApplication *)activeApplication } } - NSString *defaultBundleId = isAuto - ? nil - : self.defaultActiveApplication; - - if (nil != defaultBundleId && [self applicationStateWithBundleId:defaultBundleId] >= XCUIApplicationStateRunningForeground) { - return [self makeApplicationWithBundleId:defaultBundleId]; - } - return [XCUIApplication fb_activeApplicationWithDefaultBundleId:defaultBundleId]; } From 6ff3b4557fadb7127b9e2d23e900d479ca80125b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 10:58:33 -0700 Subject: [PATCH 4/6] move is auto detection --- WebDriverAgentLib/Routing/FBSession.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index baa5eb705..7e4bebf52 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -167,20 +167,18 @@ - (void)kill - (XCUIApplication *)activeApplication { BOOL isAuto = [self.defaultActiveApplication isEqualToString:FBDefaultApplicationAuto]; - NSString *defaultBundleId = isAuto - ? nil - : self.defaultActiveApplication; + NSString *defaultBundleId = isAuto ? nil : self.defaultActiveApplication; if (nil != defaultBundleId && [self applicationStateWithBundleId:defaultBundleId] >= XCUIApplicationStateRunningForeground) { return [self makeApplicationWithBundleId:defaultBundleId]; } - if (isAuto && nil != self.testedApplication) { + if (nil != self.testedApplication) { XCUIApplicationState testedAppState = self.testedApplication.state; if (testedAppState >= XCUIApplicationStateRunningForeground) { return (XCUIApplication *)self.testedApplication; } - if (self.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { + if (!isAuto && self.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { NSString *description = [NSString stringWithFormat:@"The application under test with bundle id '%@' is not running, possibly crashed", self.testedApplication.bundleID]; @throw [NSException exceptionWithName:FBApplicationCrashedException reason:description userInfo:nil]; } From 69293a5230b73158069f36b80ddf19d3be2a935d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 11:01:43 -0700 Subject: [PATCH 5/6] tune --- WebDriverAgentLib/Routing/FBSession.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index 7e4bebf52..c2df77e59 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -178,7 +178,7 @@ - (XCUIApplication *)activeApplication if (testedAppState >= XCUIApplicationStateRunningForeground) { return (XCUIApplication *)self.testedApplication; } - if (!isAuto && self.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { + if (WebDriverAgentLib/Routing/FBSession.mself.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { NSString *description = [NSString stringWithFormat:@"The application under test with bundle id '%@' is not running, possibly crashed", self.testedApplication.bundleID]; @throw [NSException exceptionWithName:FBApplicationCrashedException reason:description userInfo:nil]; } From afa4d4441795042f6bbbed5a5245894f26deec2f Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 13 Mar 2024 11:02:15 -0700 Subject: [PATCH 6/6] bad change... --- WebDriverAgentLib/Routing/FBSession.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index c2df77e59..82134e0cc 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -178,7 +178,7 @@ - (XCUIApplication *)activeApplication if (testedAppState >= XCUIApplicationStateRunningForeground) { return (XCUIApplication *)self.testedApplication; } - if (WebDriverAgentLib/Routing/FBSession.mself.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { + if (self.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) { NSString *description = [NSString stringWithFormat:@"The application under test with bundle id '%@' is not running, possibly crashed", self.testedApplication.bundleID]; @throw [NSException exceptionWithName:FBApplicationCrashedException reason:description userInfo:nil]; }