Flutter Engine
The Flutter Engine
Instance Methods | Properties | List of all members
AppExtensionTests Class Reference
Inheritance diagram for AppExtensionTests:

Instance Methods

(void) - setUp [implementation]
 
(void) - testAppExtensionLaunching [implementation]
 

Properties

XCUIApplication * hostApplication
 

Detailed Description

Definition at line 8 of file AppExtensionTests.m.

Method Documentation

◆ setUp

- (void) setUp
implementation

Definition at line 9 of file AppExtensionTests.m.

14 {
15 [super setUp];
16 self.continueAfterFailure = NO;
17 self.hostApplication =
18 [[XCUIApplication alloc] initWithBundleIdentifier:@"dev.flutter.FlutterAppExtensionTestHost"];
19}

◆ testAppExtensionLaunching

- (void) testAppExtensionLaunching
implementation

Definition at line 9 of file AppExtensionTests.m.

21 {
22 // Launch the Scenarios app first to ensure it's installed then close it.
23 XCUIApplication* app = [[XCUIApplication alloc] init];
24 [app launch];
25 [app terminate];
26
27 [self.hostApplication launch];
28 XCUIElement* button = self.hostApplication.buttons[@"Open Share"];
29 if (![button waitForExistenceWithTimeout:10]) {
30 NSLog(@"%@", self.hostApplication.debugDescription);
31 XCTFail(@"Failed due to not able to find any button with %@ seconds", @(10));
32 }
33 [button tap];
34 BOOL launchedExtensionInFlutter = NO;
35
36 // Custom share extension button (like the one in this test) does not have a
37 // unique identity on older versions of iOS. They are all identified as
38 // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are
39 // identified by name. Loop through all the buttons labeled
40 // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the
41 // Flutter one.
42 NSPredicate* cellPredicate = [NSPredicate
43 predicateWithFormat:
44 @"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"];
45
46 // Wait for the first cell matching the cellPredicate on the share sheet to appear.
47 XCUIElement* firstCell =
48 [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate].firstMatch;
49 if (![firstCell waitForExistenceWithTimeout:10]) {
50 NSLog(@"%@", self.hostApplication.debugDescription);
51 XCTFail(@"Failed due to not able to find Scenarios cell within %@ seconds", @(10));
52 }
53
54 NSArray<XCUIElement*>* shareSheetCells =
55 [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate]
56 .allElementsBoundByIndex;
57 for (XCUIElement* shareSheetCell in shareSheetCells) {
58 [shareSheetCell tap];
59
60 XCUIElement* flutterView = self.hostApplication.otherElements[@"flutter_view"];
61 if ([flutterView waitForExistenceWithTimeout:10]) {
62 launchedExtensionInFlutter = YES;
63 break;
64 }
65
66 // All the built-in share extensions have a Cancel button.
67 // Tap the Cancel button to close the built-in extension.
68 XCUIElement* cancel = self.hostApplication.buttons[@"Cancel"];
69 if ([cancel waitForExistenceWithTimeout:10]) {
70 [cancel tap];
71 }
72 }
73 // App extension successfully launched flutter view.
74 XCTAssertTrue(launchedExtensionInFlutter);
75}
XCUIApplication * hostApplication
int BOOL
Definition: windows_types.h:37

Property Documentation

◆ hostApplication

- (XCUIApplication*) hostApplication
readwritenonatomicstrong

Definition at line 9 of file AppExtensionTests.m.


The documentation for this class was generated from the following file: