Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 47b7cee

Browse files
committed
[webview_flutter] Add iOS integration tests
1 parent bb539fb commit 47b7cee

File tree

7 files changed

+271
-97
lines changed

7 files changed

+271
-97
lines changed

packages/webview_flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Add iOS UI integration test target.
4+
15
## 2.0.8
26

37
* Migrate maven repository from jcenter to mavenCentral.

packages/webview_flutter/example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ flutter_ios_podfile_setup
3030
target 'Runner' do
3131
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
3232

33-
target 'RunnerUITests' do
33+
target 'RunnerTests' do
3434
inherit! :search_paths
3535

3636
# Matches test_spec dependency.

packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 133 additions & 44 deletions
Large diffs are not rendered by default.

packages/webview_flutter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
<BuildableReference
4343
BuildableIdentifier = "primary"
4444
BlueprintIdentifier = "68BDCAE823C3F7CB00D9C032"
45+
BuildableName = "RunnerTests.xctest"
46+
BlueprintName = "RunnerTests"
47+
ReferencedContainer = "container:Runner.xcodeproj">
48+
</BuildableReference>
49+
</TestableReference>
50+
<TestableReference
51+
skipped = "NO">
52+
<BuildableReference
53+
BuildableIdentifier = "primary"
54+
BlueprintIdentifier = "F7151F73266057800028CB91"
4555
BuildableName = "RunnerUITests.xctest"
4656
BlueprintName = "RunnerUITests"
4757
ReferencedContainer = "container:Runner.xcodeproj">

packages/webview_flutter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/RunnerUITests.xcscheme

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
@import XCTest;
6+
@import os.log;
7+
8+
@interface FLTWebViewUITests : XCTestCase
9+
@property(nonatomic, strong) XCUIApplication* app;
10+
@end
11+
12+
@implementation FLTWebViewUITests
13+
14+
- (void)setUp {
15+
self.continueAfterFailure = NO;
16+
17+
self.app = [[XCUIApplication alloc] init];
18+
[self.app launch];
19+
}
20+
21+
- (void)testUserAgent {
22+
XCUIApplication* app = self.app;
23+
XCUIElement* menu = app.buttons[@"Show menu"];
24+
if (![menu waitForExistenceWithTimeout:30.0]) {
25+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
26+
XCTFail(@"Failed due to not able to find menu");
27+
}
28+
[menu tap];
29+
30+
XCUIElement* userAgent = app.buttons[@"Show user agent"];
31+
if (![userAgent waitForExistenceWithTimeout:30.0]) {
32+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
33+
XCTFail(@"Failed due to not able to find Show user agent");
34+
}
35+
NSPredicate* userAgentPredicate =
36+
[NSPredicate predicateWithFormat:@"label BEGINSWITH 'User Agent: Mozilla/5.0 (iPhone; '"];
37+
XCUIElement* userAgentPopUp = [app.otherElements elementMatchingPredicate:userAgentPredicate];
38+
XCTAssertFalse(userAgentPopUp.exists);
39+
[userAgent tap];
40+
if (![userAgentPopUp waitForExistenceWithTimeout:30.0]) {
41+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
42+
XCTFail(@"Failed due to not able to find user agent pop up");
43+
}
44+
}
45+
46+
- (void)testCache {
47+
XCUIApplication* app = self.app;
48+
XCUIElement* menu = app.buttons[@"Show menu"];
49+
if (![menu waitForExistenceWithTimeout:30.0]) {
50+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
51+
XCTFail(@"Failed due to not able to find menu");
52+
}
53+
[menu tap];
54+
55+
XCUIElement* clearCache = app.buttons[@"Clear cache"];
56+
if (![clearCache waitForExistenceWithTimeout:30.0]) {
57+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
58+
XCTFail(@"Failed due to not able to find Clear cache");
59+
}
60+
[clearCache tap];
61+
62+
[menu tap];
63+
64+
XCUIElement* listCache = app.buttons[@"List cache"];
65+
if (![listCache waitForExistenceWithTimeout:30.0]) {
66+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
67+
XCTFail(@"Failed due to not able to find List cache");
68+
}
69+
[listCache tap];
70+
71+
XCUIElement* emptyCachePopup = app.otherElements[@"{\"cacheKeys\":[],\"localStorage\":{}}"];
72+
if (![emptyCachePopup waitForExistenceWithTimeout:30.0]) {
73+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
74+
XCTFail(@"Failed due to not able to find empty cache pop up");
75+
}
76+
77+
[menu tap];
78+
XCUIElement* addCache = app.buttons[@"Add to cache"];
79+
if (![addCache waitForExistenceWithTimeout:30.0]) {
80+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
81+
XCTFail(@"Failed due to not able to find Add to cache");
82+
}
83+
[addCache tap];
84+
[menu tap];
85+
86+
if (![listCache waitForExistenceWithTimeout:30.0]) {
87+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
88+
XCTFail(@"Failed due to not able to find List cache");
89+
}
90+
[listCache tap];
91+
92+
XCUIElement* cachePopup =
93+
app.otherElements[@"{\"cacheKeys\":[\"test_caches_entry\"],\"localStorage\":{\"test_"
94+
@"localStorage\":\"dummy_entry\"}}"];
95+
if (![cachePopup waitForExistenceWithTimeout:30.0]) {
96+
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
97+
XCTFail(@"Failed due to not able to find cache pop up");
98+
}
99+
}
100+
101+
@end

0 commit comments

Comments
 (0)