Skip to content

Commit 972bdf8

Browse files
authored
Wait for module UI test buttons to be hittable before tapping them (flutter#87607)
1 parent 6dfa53b commit 972bdf8

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

dev/integration_tests/ios_host_app/FlutterUITests/FlutterUITests.m

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@
55
@import XCTest;
66

77
@interface FlutterUITests : XCTestCase
8+
@property (strong) XCUIApplication *app;
89
@end
910

1011
@implementation FlutterUITests
1112

1213
- (void)setUp {
14+
[super setUp];
1315
self.continueAfterFailure = NO;
14-
}
1516

16-
- (void)testFullScreenColdPop {
1717
XCUIApplication *app = [[XCUIApplication alloc] init];
1818
[app launch];
19+
self.app = app;
20+
}
1921

20-
XCUIElement *coldButton = app.buttons[@"Full Screen (Cold)"];
21-
XCTAssertTrue([coldButton waitForExistenceWithTimeout:60.0]);
22-
[coldButton tap];
23-
22+
- (void)testFullScreenColdPop {
23+
XCUIApplication *app = self.app;
24+
[self waitForAndTapElement:app.buttons[@"Full Screen (Cold)"]];
2425
XCTAssertTrue([app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:60.0]);
25-
[app.otherElements[@"Increment via Flutter"] tap];
26+
27+
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
2628
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:60.0]);
2729

2830
// Back navigation.
@@ -31,15 +33,12 @@ - (void)testFullScreenColdPop {
3133
}
3234

3335
- (void)testFullScreenWarm {
34-
XCUIApplication *app = [[XCUIApplication alloc] init];
35-
[app launch];
36-
37-
XCUIElement *warmButton = app.buttons[@"Full Screen (Warm)"];
38-
XCTAssertTrue([warmButton waitForExistenceWithTimeout:60.0]);
39-
[warmButton tap];
36+
XCUIApplication *app = self.app;
4037

38+
[self waitForAndTapElement:app.buttons[@"Full Screen (Warm)"]];
4139
XCTAssertTrue([app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:60.0]);
42-
[app.otherElements[@"Increment via Flutter"] tap];
40+
41+
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
4342
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:60.0]);
4443

4544
// Back navigation.
@@ -48,15 +47,12 @@ - (void)testFullScreenWarm {
4847
}
4948

5049
- (void)testFlutterViewWarm {
51-
XCUIApplication *app = [[XCUIApplication alloc] init];
52-
[app launch];
53-
54-
XCUIElement *warmButton = app.buttons[@"Flutter View (Warm)"];
55-
XCTAssertTrue([warmButton waitForExistenceWithTimeout:60.0]);
56-
[warmButton tap];
50+
XCUIApplication *app = self.app;
5751

52+
[self waitForAndTapElement:app.buttons[@"Flutter View (Warm)"]];
5853
XCTAssertTrue([app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:60.0]);
59-
[app.otherElements[@"Increment via Flutter"] tap];
54+
55+
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
6056
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:60.0]);
6157

6258
// Back navigation.
@@ -65,17 +61,14 @@ - (void)testFlutterViewWarm {
6561
}
6662

6763
- (void)testHybridViewWarm {
68-
XCUIApplication *app = [[XCUIApplication alloc] init];
69-
[app launch];
64+
XCUIApplication *app = self.app;
7065

71-
XCUIElement *warmButton = app.buttons[@"Hybrid View (Warm)"];
72-
XCTAssertTrue([warmButton waitForExistenceWithTimeout:60.0]);
73-
[warmButton tap];
66+
[self waitForAndTapElement:app.buttons[@"Hybrid View (Warm)"]];
7467

7568
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 0 times."] waitForExistenceWithTimeout:60.0]);
7669
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
7770

78-
[app.otherElements[@"Increment via Flutter"] tap];
71+
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
7972
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 1 time."] waitForExistenceWithTimeout:60.0]);
8073
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
8174

@@ -89,10 +82,9 @@ - (void)testHybridViewWarm {
8982
}
9083

9184
- (void)testDualCold {
92-
XCUIApplication *app = [[XCUIApplication alloc] init];
93-
[app launch];
85+
XCUIApplication *app = self.app;
9486

95-
[app.buttons[@"Dual Flutter View (Cold)"] tap];
87+
[self waitForAndTapElement:app.buttons[@"Dual Flutter View (Cold)"]];
9688

9789
// There are two marquees.
9890
XCUIElementQuery *marqueeQuery = [app.staticTexts matchingIdentifier:@"This is Marquee"];
@@ -104,4 +96,11 @@ - (void)testDualCold {
10496
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:60.0]);
10597
}
10698

99+
- (void)waitForAndTapElement:(XCUIElement *)element {
100+
NSPredicate *hittable = [NSPredicate predicateWithFormat:@"exists == YES AND hittable == YES"];
101+
[self expectationForPredicate:hittable evaluatedWithObject:element handler:nil];
102+
[self waitForExpectationsWithTimeout:30.0 handler:nil];
103+
[element tap];
104+
}
105+
107106
@end

0 commit comments

Comments
 (0)