From ecad29a17778e6648a60bab2e966d8befa5a2f2c Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:39:18 -0500 Subject: [PATCH] Change element to wait for in AppExtensionTests testAppExtensionLaunching (flutter/engine#53358) Instead of waiting for the first cell in the share sheet to appear, wait for the first cell matching the predicate to appear. It seems that on macOS 14 it [occasionally doesn't find any matches](https://github.com/flutter/flutter/issues/150117#issuecomment-2163493564), presumably a race condition - so this will wait up to 10 seconds for the desired elements to appear. Attempting to fix https://github.com/flutter/flutter/issues/150117. I wasn't able to recreate locally and it only happens flakily in CI so hard to guarantee it will fix. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ScenariosUITests/AppExtensionTests.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m index 32555de44e..140368cc0f 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/AppExtensionTests.m @@ -33,13 +33,6 @@ [button tap]; BOOL launchedExtensionInFlutter = NO; - // Wait for first cell of share sheet to appear. - XCUIElement* firstCell = self.hostApplication.collectionViews.cells.firstMatch; - if (![firstCell waitForExistenceWithTimeout:10]) { - NSLog(@"%@", self.hostApplication.debugDescription); - XCTFail(@"Failed due to not able to find any cells with %@ seconds", @(10)); - } - // Custom share extension button (like the one in this test) does not have a // unique identity on older versions of iOS. They are all identified as // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are @@ -49,6 +42,15 @@ NSPredicate* cellPredicate = [NSPredicate predicateWithFormat: @"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"]; + + // Wait for the first cell matching the cellPredicate on the share sheet to appear. + XCUIElement* firstCell = + [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate].firstMatch; + if (![firstCell waitForExistenceWithTimeout:10]) { + NSLog(@"%@", self.hostApplication.debugDescription); + XCTFail(@"Failed due to not able to find Scenarios cell within %@ seconds", @(10)); + } + NSArray* shareSheetCells = [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate] .allElementsBoundByIndex;