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

[webview_flutter] Add iOS integration tests #3995

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Add iOS UI integration test target.

## 2.0.8

* Migrate maven repository from jcenter to mavenCentral.
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ flutter_ios_podfile_setup
target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

target 'RunnerUITests' do
target 'RunnerTests' do
inherit! :search_paths

# Matches test_spec dependency.
Expand Down
177 changes: 133 additions & 44 deletions packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "68BDCAE823C3F7CB00D9C032"
BuildableName = "RunnerTests.xctest"
BlueprintName = "RunnerTests"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F7151F73266057800028CB91"
BuildableName = "RunnerUITests.xctest"
BlueprintName = "RunnerUITests"
ReferencedContainer = "container:Runner.xcodeproj">
Expand Down

This file was deleted.

22 changes: 22 additions & 0 deletions packages/webview_flutter/example/ios/RunnerTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
101 changes: 101 additions & 0 deletions packages/webview_flutter/example/ios/RunnerUITests/FLTWebViewUITests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2013 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;
@import os.log;

@interface FLTWebViewUITests : XCTestCase
@property(nonatomic, strong) XCUIApplication* app;
@end

@implementation FLTWebViewUITests

- (void)setUp {
self.continueAfterFailure = NO;

self.app = [[XCUIApplication alloc] init];
[self.app launch];
}

- (void)testUserAgent {
XCUIApplication* app = self.app;
XCUIElement* menu = app.buttons[@"Show menu"];
if (![menu waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find menu");
}
[menu tap];

XCUIElement* userAgent = app.buttons[@"Show user agent"];
if (![userAgent waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find Show user agent");
}
NSPredicate* userAgentPredicate =
[NSPredicate predicateWithFormat:@"label BEGINSWITH 'User Agent: Mozilla/5.0 (iPhone; '"];
XCUIElement* userAgentPopUp = [app.otherElements elementMatchingPredicate:userAgentPredicate];
XCTAssertFalse(userAgentPopUp.exists);
[userAgent tap];
if (![userAgentPopUp waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find user agent pop up");
}
}

- (void)testCache {
XCUIApplication* app = self.app;
XCUIElement* menu = app.buttons[@"Show menu"];
if (![menu waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find menu");
}
[menu tap];

XCUIElement* clearCache = app.buttons[@"Clear cache"];
if (![clearCache waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find Clear cache");
}
[clearCache tap];

[menu tap];

XCUIElement* listCache = app.buttons[@"List cache"];
if (![listCache waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find List cache");
}
[listCache tap];

XCUIElement* emptyCachePopup = app.otherElements[@"{\"cacheKeys\":[],\"localStorage\":{}}"];
if (![emptyCachePopup waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find empty cache pop up");
}

[menu tap];
XCUIElement* addCache = app.buttons[@"Add to cache"];
if (![addCache waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find Add to cache");
}
[addCache tap];
[menu tap];

if (![listCache waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find List cache");
}
[listCache tap];

XCUIElement* cachePopup =
app.otherElements[@"{\"cacheKeys\":[\"test_caches_entry\"],\"localStorage\":{\"test_"
@"localStorage\":\"dummy_entry\"}}"];
if (![cachePopup waitForExistenceWithTimeout:30.0]) {
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
XCTFail(@"Failed due to not able to find cache pop up");
}
}

@end