mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 05:49:25 -04:00
Accessibility
This commit is contained in:
parent
86b8757219
commit
76b80ce082
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
screenshots
|
||||
Snapfile
|
||||
|
||||
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
@ -10,12 +10,19 @@ import UIKit
|
||||
|
||||
class Buttons: LPTBarButtonItemDelegate {
|
||||
|
||||
private(set) lazy var back: LPTBarButtonItem = LPTBarButtonItem(imageName: "LeftArrow", scale: 0.8, delegate: self)
|
||||
private(set) lazy var forward: LPTBarButtonItem = LPTBarButtonItem(imageName: "RightArrow", scale: 0.8, delegate: self)
|
||||
private(set) lazy var toc: LPTBarButtonItem = LPTBarButtonItem(imageName: "TableOfContent", scale: 0.8, delegate: self)
|
||||
private(set) lazy var bookmark: LPTBarButtonItem = LPTBarButtonItem(imageName: "Bookmark", highlightedImageName: "BookmarkHighlighted", scale: 0.9, grayed: false, delegate: self)
|
||||
private(set) lazy var library: LPTBarButtonItem = LPTBarButtonItem(imageName: "Library", delegate: self)
|
||||
private(set) lazy var setting: LPTBarButtonItem = LPTBarButtonItem(imageName: "Setting", delegate: self)
|
||||
private(set) lazy var back: LPTBarButtonItem = LPTBarButtonItem(imageName: "LeftArrow", scale: 0.8, delegate: self,
|
||||
accessibilityLabel: "Go back", accessibilityIdentifier: "GoBack")
|
||||
private(set) lazy var forward: LPTBarButtonItem = LPTBarButtonItem(imageName: "RightArrow", scale: 0.8, delegate: self,
|
||||
accessibilityLabel: "Go forward", accessibilityIdentifier: "GoForward")
|
||||
private(set) lazy var toc: LPTBarButtonItem = LPTBarButtonItem(imageName: "TableOfContent", scale: 0.8, delegate: self,
|
||||
accessibilityLabel: "Table of content", accessibilityIdentifier: "TableOfContent")
|
||||
private(set) lazy var bookmark: LPTBarButtonItem = LPTBarButtonItem(imageName: "Bookmark", highlightedImageName: "BookmarkHighlighted",
|
||||
scale: 0.9, grayed: false, delegate: self,
|
||||
accessibilityLabel: "Bookmark", accessibilityIdentifier: "Bookmark")
|
||||
private(set) lazy var library: LPTBarButtonItem = LPTBarButtonItem(imageName: "Library", delegate: self,
|
||||
accessibilityLabel: "Library", accessibilityIdentifier: "Library")
|
||||
private(set) lazy var setting: LPTBarButtonItem = LPTBarButtonItem(imageName: "Setting", delegate: self,
|
||||
accessibilityLabel: "Setting", accessibilityIdentifier: "Setting")
|
||||
|
||||
private(set) lazy var cancel: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(tapped(button:)))
|
||||
|
||||
|
@ -14,7 +14,9 @@ class LPTBarButtonItem: UIBarButtonItem {
|
||||
highlightedImageName: String? = nil,
|
||||
scale: CGFloat = 1.0,
|
||||
grayed: Bool = true,
|
||||
delegate: LPTBarButtonItemDelegate? = nil) {
|
||||
delegate: LPTBarButtonItemDelegate? = nil,
|
||||
accessibilityLabel: String? = nil,
|
||||
accessibilityIdentifier: String? = nil) {
|
||||
var image = UIImage(named: imageName)
|
||||
var highlightedImage: UIImage? = {
|
||||
guard let name = highlightedImageName else {return nil}
|
||||
@ -43,6 +45,10 @@ class LPTBarButtonItem: UIBarButtonItem {
|
||||
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(gesture:)))
|
||||
containerView.addGestureRecognizer(longPressGestureRecognizer)
|
||||
containerView.addGestureRecognizer(tapGestureRecognizer)
|
||||
|
||||
self.isAccessibilityElement = true
|
||||
self.accessibilityLabel = accessibilityLabel
|
||||
self.accessibilityIdentifier = accessibilityIdentifier
|
||||
}
|
||||
|
||||
// MARK: - Overrides
|
||||
|
@ -11,6 +11,9 @@
|
||||
9705D5941E368189005292AC /* Library.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9705D5931E368189005292AC /* Library.storyboard */; };
|
||||
9705D5961E368712005292AC /* LibraryBooksController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9705D5951E368712005292AC /* LibraryBooksController.swift */; };
|
||||
9705D5981E368933005292AC /* CoreDataCollectionBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9705D5971E368933005292AC /* CoreDataCollectionBaseController.swift */; };
|
||||
9706DAB61E6751120005FE0F /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9706DAB41E6751120005FE0F /* Info.plist */; };
|
||||
9706DAB71E6751120005FE0F /* iOS_ScreenshotAutomator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9706DAB51E6751120005FE0F /* iOS_ScreenshotAutomator.swift */; };
|
||||
9706DAB91E67527B0005FE0F /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9706DAB81E67527B0005FE0F /* SnapshotHelper.swift */; };
|
||||
970D79D41E60B8A8003F5997 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 970D79D01E60B8A8003F5997 /* Assets.xcassets */; };
|
||||
970D79D51E60B8A8003F5997 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 970D79D11E60B8A8003F5997 /* Info.plist */; };
|
||||
970D79D61E60B8A8003F5997 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 970D79D31E60B8A8003F5997 /* LaunchScreen.storyboard */; };
|
||||
@ -120,6 +123,13 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
9706DAAE1E6750EB0005FE0F /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 97A2AB801C1B80FF00052E74 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 97A2AB871C1B80FF00052E74;
|
||||
remoteInfo = iOS;
|
||||
};
|
||||
9779C31C1D4575AE0064CC8E /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 97A2AB801C1B80FF00052E74 /* Project object */;
|
||||
@ -151,6 +161,10 @@
|
||||
9705D5931E368189005292AC /* Library.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Library.storyboard; sourceTree = "<group>"; };
|
||||
9705D5951E368712005292AC /* LibraryBooksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryBooksController.swift; sourceTree = "<group>"; };
|
||||
9705D5971E368933005292AC /* CoreDataCollectionBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataCollectionBaseController.swift; sourceTree = "<group>"; };
|
||||
9706DAA91E6750EB0005FE0F /* iOS_ScreenshotAutomator.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOS_ScreenshotAutomator.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
9706DAB41E6751120005FE0F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
9706DAB51E6751120005FE0F /* iOS_ScreenshotAutomator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = iOS_ScreenshotAutomator.swift; sourceTree = "<group>"; };
|
||||
9706DAB81E67527B0005FE0F /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapshotHelper.swift; sourceTree = "<group>"; };
|
||||
970912551D7F452C00BBD5A1 /* 1.8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = 1.8.xcdatamodel; sourceTree = "<group>"; };
|
||||
970D79D01E60B8A8003F5997 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
970D79D11E60B8A8003F5997 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@ -282,6 +296,13 @@
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
9706DAA61E6750EB0005FE0F /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
9779C3101D4575AD0064CC8E /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@ -348,6 +369,24 @@
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9706DA9F1E6750360005FE0F /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9706DAB31E6751120005FE0F /* iOS_ScreenshotAutomator */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9706DAB31E6751120005FE0F /* iOS_ScreenshotAutomator */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9706DAB41E6751120005FE0F /* Info.plist */,
|
||||
9706DAB51E6751120005FE0F /* iOS_ScreenshotAutomator.swift */,
|
||||
9706DAB81E67527B0005FE0F /* SnapshotHelper.swift */,
|
||||
);
|
||||
path = iOS_ScreenshotAutomator;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
971187051CEB426E00B9909D /* libkiwix */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -655,9 +694,11 @@
|
||||
973BCCE41CEB3EDE00F10B44 /* iOS */,
|
||||
979315821E5127930093D3BA /* macOS */,
|
||||
97E609F21D103DED00EBCB9D /* iOSWidgets */,
|
||||
9706DA9F1E6750360005FE0F /* Tests */,
|
||||
931D277C156AE671D3F9EADA /* Frameworks */,
|
||||
F544A4E4357A6D33CF234C6B /* Pods */,
|
||||
979315811E5127930093D3BA /* Kiwix.app */,
|
||||
9706DAA91E6750EB0005FE0F /* iOS_ScreenshotAutomator.xctest */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@ -750,6 +791,24 @@
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
9706DAA81E6750EB0005FE0F /* iOS_ScreenshotAutomator */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 9706DAB01E6750EB0005FE0F /* Build configuration list for PBXNativeTarget "iOS_ScreenshotAutomator" */;
|
||||
buildPhases = (
|
||||
9706DAA51E6750EB0005FE0F /* Sources */,
|
||||
9706DAA61E6750EB0005FE0F /* Frameworks */,
|
||||
9706DAA71E6750EB0005FE0F /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
9706DAAF1E6750EB0005FE0F /* PBXTargetDependency */,
|
||||
);
|
||||
name = iOS_ScreenshotAutomator;
|
||||
productName = iOS_ScreenshotAutomator;
|
||||
productReference = 9706DAA91E6750EB0005FE0F /* iOS_ScreenshotAutomator.xctest */;
|
||||
productType = "com.apple.product-type.bundle.ui-testing";
|
||||
};
|
||||
9779C3121D4575AD0064CC8E /* Bookmarks */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 9779C31F1D4575AE0064CC8E /* Build configuration list for PBXNativeTarget "Bookmarks" */;
|
||||
@ -816,6 +875,12 @@
|
||||
LastUpgradeCheck = 0830;
|
||||
ORGANIZATIONNAME = "Chris Li";
|
||||
TargetAttributes = {
|
||||
9706DAA81E6750EB0005FE0F = {
|
||||
CreatedOnToolsVersion = 8.2.1;
|
||||
DevelopmentTeam = L7HWM3SP3L;
|
||||
ProvisioningStyle = Automatic;
|
||||
TestTargetID = 97A2AB871C1B80FF00052E74;
|
||||
};
|
||||
9779C3121D4575AD0064CC8E = {
|
||||
CreatedOnToolsVersion = 7.3.1;
|
||||
DevelopmentTeam = L7HWM3SP3L;
|
||||
@ -871,11 +936,20 @@
|
||||
97A2AB871C1B80FF00052E74 /* iOS */,
|
||||
979315801E5127930093D3BA /* macOS */,
|
||||
9779C3121D4575AD0064CC8E /* Bookmarks */,
|
||||
9706DAA81E6750EB0005FE0F /* iOS_ScreenshotAutomator */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
9706DAA71E6750EB0005FE0F /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9706DAB61E6751120005FE0F /* Info.plist in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
9779C3111D4575AD0064CC8E /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@ -966,6 +1040,15 @@
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
9706DAA51E6750EB0005FE0F /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9706DAB71E6751120005FE0F /* iOS_ScreenshotAutomator.swift in Sources */,
|
||||
9706DAB91E67527B0005FE0F /* SnapshotHelper.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
9779C30F1D4575AD0064CC8E /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@ -1066,6 +1149,11 @@
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
9706DAAF1E6750EB0005FE0F /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 97A2AB871C1B80FF00052E74 /* iOS */;
|
||||
targetProxy = 9706DAAE1E6750EB0005FE0F /* PBXContainerItemProxy */;
|
||||
};
|
||||
9779C31D1D4575AE0064CC8E /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 9779C3121D4575AD0064CC8E /* Bookmarks */;
|
||||
@ -1074,6 +1162,39 @@
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
9706DAB11E6750EB0005FE0F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
DEVELOPMENT_TEAM = L7HWM3SP3L;
|
||||
INFOPLIST_FILE = Tests/iOS_ScreenshotAutomator/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.kiwix.iOS-ScreenshotAutomator";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_TARGET_NAME = iOS;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
9706DAB21E6750EB0005FE0F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
DEVELOPMENT_TEAM = L7HWM3SP3L;
|
||||
INFOPLIST_FILE = Tests/iOS_ScreenshotAutomator/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.kiwix.iOS-ScreenshotAutomator";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_TARGET_NAME = iOS;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
9779C3201D4575AE0064CC8E /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
@ -1318,6 +1439,14 @@
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
9706DAB01E6750EB0005FE0F /* Build configuration list for PBXNativeTarget "iOS_ScreenshotAutomator" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
9706DAB11E6750EB0005FE0F /* Debug */,
|
||||
9706DAB21E6750EB0005FE0F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
};
|
||||
9779C31F1D4575AE0064CC8E /* Build configuration list for PBXNativeTarget "Bookmarks" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
|
@ -43,13 +43,23 @@
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "9706DA941E674F5D0005FE0F"
|
||||
BuildableName = "iOS_ScreenshotAutomator.xctest"
|
||||
BlueprintName = "iOS_ScreenshotAutomator"
|
||||
ReferencedContainer = "container:Kiwix.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "9779C3121D4575AD0064CC8E"
|
||||
BuildableName = "Bookmarks.appex"
|
||||
BlueprintName = "Bookmarks"
|
||||
BlueprintIdentifier = "97A2AB871C1B80FF00052E74"
|
||||
BuildableName = "Kiwix.app"
|
||||
BlueprintName = "iOS"
|
||||
ReferencedContainer = "container:Kiwix.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
|
@ -27,6 +27,16 @@
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>9706DA941E674F5D0005FE0F</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>9706DAA81E6750EB0005FE0F</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>9722121A1D3ECCFE00C0DCF2</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
|
22
Tests/iOS_ScreenshotAutomator/Info.plist
Normal file
22
Tests/iOS_ScreenshotAutomator/Info.plist
Normal file
@ -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>en</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>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
142
Tests/iOS_ScreenshotAutomator/SnapshotHelper.swift
Normal file
142
Tests/iOS_ScreenshotAutomator/SnapshotHelper.swift
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// SnapshotHelper.swift
|
||||
// Example
|
||||
//
|
||||
// Created by Felix Krause on 10/8/15.
|
||||
// Copyright © 2015 Felix Krause. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
var deviceLanguage = ""
|
||||
var locale = ""
|
||||
|
||||
@available(*, deprecated, message: "use setupSnapshot: instead")
|
||||
func setLanguage(_ app: XCUIApplication) {
|
||||
setupSnapshot(app)
|
||||
}
|
||||
|
||||
func setupSnapshot(_ app: XCUIApplication) {
|
||||
Snapshot.setupSnapshot(app)
|
||||
}
|
||||
|
||||
func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
||||
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
|
||||
}
|
||||
|
||||
open class Snapshot: NSObject {
|
||||
|
||||
open class func setupSnapshot(_ app: XCUIApplication) {
|
||||
setLanguage(app)
|
||||
setLocale(app)
|
||||
setLaunchArguments(app)
|
||||
}
|
||||
|
||||
class func setLanguage(_ app: XCUIApplication) {
|
||||
guard let prefix = pathPrefix() else {
|
||||
return
|
||||
}
|
||||
|
||||
let path = prefix.appendingPathComponent("language.txt")
|
||||
|
||||
do {
|
||||
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
||||
deviceLanguage = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue).trimmingCharacters(in: trimCharacterSet) as String
|
||||
app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"]
|
||||
} catch {
|
||||
print("Couldn't detect/set language...")
|
||||
}
|
||||
}
|
||||
|
||||
class func setLocale(_ app: XCUIApplication) {
|
||||
guard let prefix = pathPrefix() else {
|
||||
return
|
||||
}
|
||||
|
||||
let path = prefix.appendingPathComponent("locale.txt")
|
||||
|
||||
do {
|
||||
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
||||
locale = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue).trimmingCharacters(in: trimCharacterSet) as String
|
||||
} catch {
|
||||
print("Couldn't detect/set locale...")
|
||||
}
|
||||
if locale.isEmpty {
|
||||
locale = Locale(identifier: deviceLanguage).identifier
|
||||
}
|
||||
app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
|
||||
}
|
||||
|
||||
class func setLaunchArguments(_ app: XCUIApplication) {
|
||||
guard let prefix = pathPrefix() else {
|
||||
return
|
||||
}
|
||||
|
||||
let path = prefix.appendingPathComponent("snapshot-launch_arguments.txt")
|
||||
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]
|
||||
|
||||
do {
|
||||
let launchArguments = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue) as String
|
||||
let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
|
||||
let matches = regex.matches(in: launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
|
||||
let results = matches.map { result -> String in
|
||||
(launchArguments as NSString).substring(with: result.range)
|
||||
}
|
||||
app.launchArguments += results
|
||||
} catch {
|
||||
print("Couldn't detect/set launch_arguments...")
|
||||
}
|
||||
}
|
||||
|
||||
open class func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
||||
if waitForLoadingIndicator {
|
||||
waitForLoadingIndicatorToDisappear()
|
||||
}
|
||||
|
||||
print("snapshot: \(name)") // more information about this, check out https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
|
||||
|
||||
sleep(1) // Waiting for the animation to be finished (kind of)
|
||||
|
||||
#if os(tvOS)
|
||||
XCUIApplication().childrenMatchingType(.Browser).count
|
||||
#else
|
||||
XCUIDevice.shared().orientation = .unknown
|
||||
#endif
|
||||
}
|
||||
|
||||
class func waitForLoadingIndicatorToDisappear() {
|
||||
#if os(tvOS)
|
||||
return
|
||||
#endif
|
||||
|
||||
let query = XCUIApplication().statusBars.children(matching: .other).element(boundBy: 1).children(matching: .other)
|
||||
|
||||
while (0..<query.count).map({ query.element(boundBy: $0) }).contains(where: { $0.isLoadingIndicator }) {
|
||||
sleep(1)
|
||||
print("Waiting for loading indicator to disappear...")
|
||||
}
|
||||
}
|
||||
|
||||
class func pathPrefix() -> NSString? {
|
||||
if let path = ProcessInfo().environment["SIMULATOR_HOST_HOME"] as NSString? {
|
||||
return path.appendingPathComponent("Library/Caches/tools.fastlane") as NSString?
|
||||
}
|
||||
print("Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension XCUIElement {
|
||||
var isLoadingIndicator: Bool {
|
||||
let whiteListedLoaders = ["GeofenceLocationTrackingOn", "StandardLocationTrackingOn"]
|
||||
if whiteListedLoaders.contains(self.identifier) {
|
||||
return false
|
||||
}
|
||||
return self.frame.size == CGSize(width: 10, height: 20)
|
||||
}
|
||||
}
|
||||
|
||||
// Please don't remove the lines below
|
||||
// They are used to detect outdated configuration files
|
||||
// SnapshotHelperVersion [1.2]
|
49
Tests/iOS_ScreenshotAutomator/iOS_ScreenshotAutomator.swift
Normal file
49
Tests/iOS_ScreenshotAutomator/iOS_ScreenshotAutomator.swift
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// iOS_ScreenshotAutomator.swift
|
||||
// iOS_ScreenshotAutomator
|
||||
//
|
||||
// Created by Chris Li on 3/1/17.
|
||||
// Copyright © 2017 Chris Li. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class iOS_ScreenshotAutomator: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
let app = XCUIApplication()
|
||||
setupSnapshot(app)
|
||||
app.launch()
|
||||
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
|
||||
// In UI tests it is usually best to stop immediately when a failure occurs.
|
||||
continueAfterFailure = false
|
||||
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
|
||||
XCUIApplication().launch()
|
||||
|
||||
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
addUIInterruptionMonitor(withDescription: "System Alert") { (alert) -> Bool in
|
||||
alert.buttons["Allow"].tap()
|
||||
snapshot("01Welcome")
|
||||
return true
|
||||
}
|
||||
XCUIApplication().toolbars.otherElements["Library"].tap()
|
||||
XCUIApplication().alerts["Filter Languages?"].buttons["Hide Other Languages"].tap()
|
||||
snapshot("02Library")
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user