1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@import XCTest;
static const CGFloat kStandardTimeOut = 60.0;
@interface FlutterUITests : XCTestCase
@property (strong) XCUIApplication *app;
@end
@implementation FlutterUITests
- (void)setUp {
[super setUp];
self.continueAfterFailure = NO;
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
self.app = app;
}
- (void)testFullScreenColdPop {
XCUIApplication *app = self.app;
[self waitForAndTapElement:app.buttons[@"Full Screen (Cold)"]];
XCTAssertTrue([app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut]);
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
// Back navigation.
[app.buttons[@"POP"] tap];
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
}
- (void)testFullScreenWarm {
XCUIApplication *app = self.app;
[self waitForAndTapElement:app.buttons[@"Full Screen (Warm)"]];
BOOL newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
if (!newPageAppeared) {
// Sometimes, the element doesn't respond to the tap, it seems an XCUITest race condition where the tap happened
// too soon. Trying to tap the element again.
[self waitForAndTapElement:app.buttons[@"Full Screen (Warm))"]];
newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
}
XCTAssertTrue(newPageAppeared);
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
// Back navigation.
[app.buttons[@"POP"] tap];
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
}
- (void)testFlutterViewWarm {
XCUIApplication *app = self.app;
[self waitForAndTapElement:app.buttons[@"Flutter View (Warm)"]];
BOOL newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
if (!newPageAppeared) {
// Sometimes, the element doesn't respond to the tap, it seems an XCUITest race condition where the tap happened
// too soon. Trying to tap the element again.
[self waitForAndTapElement:app.buttons[@"Flutter View (Warm)"]];
newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
}
XCTAssertTrue(newPageAppeared);
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
// Back navigation.
[app.buttons[@"POP"] tap];
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
}
- (void)testHybridViewWarm {
XCUIApplication *app = self.app;
[self waitForAndTapElement:app.buttons[@"Hybrid View (Warm)"]];
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut]);
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
[app.buttons[@"Increment via iOS"] tap];
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
XCTAssertTrue(app.staticTexts[@"Platform button tapped 1 time."].exists);
// Back navigation.
[app.navigationBars[@"Hybrid Flutter/Native"].buttons[@"Flutter iOS Demos Home"] tap];
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
}
- (void)testDualCold {
XCUIApplication *app = self.app;
[self waitForAndTapElement:app.buttons[@"Dual Flutter View (Cold)"]];
// There are two marquees.
XCUIElementQuery *marqueeQuery = [app.staticTexts matchingIdentifier:@"This is Marquee"];
[self expectationForPredicate:[NSPredicate predicateWithFormat:@"count = 2"] evaluatedWithObject:marqueeQuery handler:nil];
[self waitForExpectationsWithTimeout:30.0 handler:nil];
// Back navigation.
[app.navigationBars[@"Dual Flutter Views"].buttons[@"Flutter iOS Demos Home"] tap];
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
}
- (void)waitForAndTapElement:(XCUIElement *)element {
NSPredicate *hittable = [NSPredicate predicateWithFormat:@"exists == YES AND hittable == YES"];
[self expectationForPredicate:hittable evaluatedWithObject:element handler:nil];
[self waitForExpectationsWithTimeout:30.0 handler:nil];
[element tap];
}
@end