Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 // Wait for first cell of share sheet to appear.
37 XCUIElement* firstCell = self.hostApplication.collectionViews.cells.firstMatch;
38 if (![firstCell waitForExistenceWithTimeout:10]) {
39 NSLog(@"%@", self.hostApplication.debugDescription);
40 XCTFail(@"Failed due to not able to find any cells with %@ seconds", @(10));
41 }
42
43 // Custom share extension button (like the one in this test) does not have a
44 // unique identity on older versions of iOS. They are all identified as
45 // `XCElementSnapshotPrivilegedValuePlaceholder`. On iOS 17, they are
46 // identified by name. Loop through all the buttons labeled
47 // `XCElementSnapshotPrivilegedValuePlaceholder` or `Scenarios` to find the
48 // Flutter one.
49 NSPredicate* cellPredicate = [NSPredicate
50 predicateWithFormat:
51 @"label == 'XCElementSnapshotPrivilegedValuePlaceholder' OR label = 'Scenarios'"];
52 NSArray<XCUIElement*>* shareSheetCells =
53 [self.hostApplication.collectionViews.cells matchingPredicate:cellPredicate]
54 .allElementsBoundByIndex;
55 for (XCUIElement* shareSheetCell in shareSheetCells) {
56 [shareSheetCell tap];
57
58 XCUIElement* flutterView = self.hostApplication.otherElements[@"flutter_view"];
59 if ([flutterView waitForExistenceWithTimeout:10]) {
60 launchedExtensionInFlutter = YES;
61 break;
62 }
63
64 // All the built-in share extensions have a Cancel button.
65 // Tap the Cancel button to close the built-in extension.
66 XCUIElement* cancel = self.hostApplication.buttons[@"Cancel"];
67 if ([cancel waitForExistenceWithTimeout:10]) {
68 [cancel tap];
69 }
70 }
71 // App extension successfully launched flutter view.
72 XCTAssertTrue(launchedExtensionInFlutter);
73}
XCUIApplication * hostApplication
int BOOL

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: