diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 639f9cb8..e2df97a6 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 80 + 183 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSUITests/KiwixUITests.swift b/Kiwix-iOSUITests/KiwixUITests.swift deleted file mode 100644 index 87b2adfd..00000000 --- a/Kiwix-iOSUITests/KiwixUITests.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// KiwixUITests.swift -// KiwixUITests -// -// Created by Chris on 12/11/15. -// Copyright © 2015 Chris. All rights reserved. -// - -import XCTest - -class KiwixUITests: XCTestCase { - - override func setUp() { - super.setUp() - - // 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() { - // Use recording to get started writing UI tests. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - -} diff --git a/Kiwix-iOSUITests/SnapshotAutomation.swift b/Kiwix-iOSUITests/SnapshotAutomation.swift new file mode 100644 index 00000000..005fd463 --- /dev/null +++ b/Kiwix-iOSUITests/SnapshotAutomation.swift @@ -0,0 +1,57 @@ +// +// KiwixUITests.swift +// KiwixUITests +// +// Created by Chris on 12/11/15. +// Copyright © 2015 Chris. All rights reserved. +// + +import XCTest + +class SnapshotAutomation: XCTestCase { + + override func setUp() { + super.setUp() + + continueAfterFailure = false + XCUIApplication().launch() + + let app = XCUIApplication() + if app.alerts.count > 0 { + app.alerts["Welcome to Kiwix"].collectionViews.buttons["Dismiss"].tap() + } + + snapshot("01WelcomeScreen") + + if app.toolbars.buttons["Library"].exists { + // iPhone + app.toolbars.buttons["Library"].tap() + sleep(4) + if app.alerts.count > 0 { + app.alerts["Only Show Preferred Language?"].collectionViews.buttons["OK"].tap() + } + snapshot("02LibraryScreen") + } else { + // iPad + app.navigationBars["Kiwix.MainVC"].childrenMatchingType(.Button).elementBoundByIndex(4).tap() + sleep(4) + if app.alerts.count > 0 { + app.alerts["Only Show Preferred Language?"].collectionViews.buttons["OK"].tap() + } + snapshot("02LibraryScreen") + } + + + } + + 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() { + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + +} diff --git a/Kiwix-iOSUITests/SnapshotHelper.swift b/Kiwix-iOSUITests/SnapshotHelper.swift new file mode 100644 index 00000000..e534eb32 --- /dev/null +++ b/Kiwix-iOSUITests/SnapshotHelper.swift @@ -0,0 +1,129 @@ +// +// 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) +} + +public class Snapshot: NSObject { + + public 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.stringByAppendingPathComponent("language.txt") + + do { + let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet() + deviceLanguage = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(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.stringByAppendingPathComponent("locale.txt") + + do { + let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet() + locale = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(trimCharacterSet) as String + } catch { + print("Couldn't detect/set locale...") + } + if locale.isEmpty { + locale = NSLocale(localeIdentifier: deviceLanguage).localeIdentifier + } + app.launchArguments += ["-AppleLocale", "\"\(locale)\""] + } + + class func setLaunchArguments(app: XCUIApplication) { + guard let prefix = pathPrefix() else { + return + } + + let path = prefix.stringByAppendingPathComponent("snapshot-launch_arguments.txt") + app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"] + + do { + let launchArguments = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String + let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: []) + let matches = regex.matchesInString(launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count)) + let results = matches.map { result -> String in + (launchArguments as NSString).substringWithRange(result.range) + } + app.launchArguments += results + } catch { + print("Couldn't detect/set launch_arguments...") + } + } + + public class func snapshot(name: String, waitForLoadingIndicator: Bool = true) { + if waitForLoadingIndicator { + waitForLoadingIndicatorToDisappear() + } + + print("snapshot: \(name)") // more information about this, check out https://github.com/fastlane/snapshot + + sleep(1) // Waiting for the animation to be finished (kind of) + XCUIDevice.sharedDevice().orientation = .Unknown + } + + class func waitForLoadingIndicatorToDisappear() { + let query = XCUIApplication().statusBars.childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other) + + while (0.. NSString? { + if let path = NSProcessInfo().environment["SIMULATOR_HOST_HOME"] as NSString? { + return path.stringByAppendingPathComponent("Library/Caches/tools.fastlane") + } + print("Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane") + return nil + } +} + +extension XCUIElement { + var isLoadingIndicator: Bool { + 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] diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index fb2baffd..afe64fed 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -117,8 +117,7 @@ 973BCD0C1CEB3FA500F10B44 /* Kiwix_OSXUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD0B1CEB3FA500F10B44 /* Kiwix_OSXUITests.swift */; }; 973BCD191CEB402900F10B44 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 973BCD171CEB402900F10B44 /* Info.plist */; }; 973BCD1A1CEB402900F10B44 /* KiwixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD181CEB402900F10B44 /* KiwixTests.swift */; }; - 973BCD1D1CEB403700F10B44 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 973BCD1B1CEB403700F10B44 /* Info.plist */; }; - 973BCD1E1CEB403700F10B44 /* KiwixUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD1C1CEB403700F10B44 /* KiwixUITests.swift */; }; + 973BCD1E1CEB403700F10B44 /* SnapshotAutomation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD1C1CEB403700F10B44 /* SnapshotAutomation.swift */; }; 973C8D5C1C25F945007272F9 /* Preference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973C8D5B1C25F945007272F9 /* Preference.swift */; }; 974570F41C2DABB500680E43 /* ZIMMultiReaderAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */; }; 975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; }; @@ -145,6 +144,7 @@ 975334CB1CEB6A43007ED50B /* Preference.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975334CA1CEB6A43007ED50B /* Preference.storyboard */; }; 975334D01CEB6AE3007ED50B /* PreferenceGeneralController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 975334CF1CEB6AE3007ED50B /* PreferenceGeneralController.swift */; }; 975334D21CEB6B01007ED50B /* LibraryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 975334D11CEB6B01007ED50B /* LibraryController.swift */; }; + 97587A961D1061C0006EE1AA /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97587A951D1061C0006EE1AA /* SnapshotHelper.swift */; }; 975B90F91CEB75CB00D13906 /* ZimFilesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 975B90F81CEB75CB00D13906 /* ZimFilesController.swift */; }; 975B90FE1CEB909100D13906 /* iOSExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 975B90FD1CEB909100D13906 /* iOSExtensions.swift */; }; 975B90FF1CEB909900D13906 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779987A1C1E1C9600B1DD5E /* Extensions.swift */; }; @@ -440,7 +440,7 @@ 973BCD171CEB402900F10B44 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = "Kiwix-iOSTests/Info.plist"; sourceTree = SOURCE_ROOT; }; 973BCD181CEB402900F10B44 /* KiwixTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KiwixTests.swift; path = "Kiwix-iOSTests/KiwixTests.swift"; sourceTree = SOURCE_ROOT; }; 973BCD1B1CEB403700F10B44 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = "Kiwix-iOSUITests/Info.plist"; sourceTree = SOURCE_ROOT; }; - 973BCD1C1CEB403700F10B44 /* KiwixUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KiwixUITests.swift; path = "Kiwix-iOSUITests/KiwixUITests.swift"; sourceTree = SOURCE_ROOT; }; + 973BCD1C1CEB403700F10B44 /* SnapshotAutomation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnapshotAutomation.swift; path = "Kiwix-iOSUITests/SnapshotAutomation.swift"; sourceTree = SOURCE_ROOT; }; 973C8D5B1C25F945007272F9 /* Preference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preference.swift; sourceTree = ""; }; 974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZIMMultiReaderAPI.swift; sourceTree = ""; }; 97497B5A1D07487000ECD691 /* indexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = indexer.h; path = "Kiwix/libkiwix/C&C++/indexer.h"; sourceTree = ""; }; @@ -469,6 +469,7 @@ 975334CA1CEB6A43007ED50B /* Preference.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Preference.storyboard; path = "Kiwix-OSX/StoryBoards/Preference.storyboard"; sourceTree = SOURCE_ROOT; }; 975334CF1CEB6AE3007ED50B /* PreferenceGeneralController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PreferenceGeneralController.swift; path = "Kiwix-OSX/Controllers/PreferenceGeneralController.swift"; sourceTree = SOURCE_ROOT; }; 975334D11CEB6B01007ED50B /* LibraryController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LibraryController.swift; path = "Kiwix-OSX/Controllers/LibraryController.swift"; sourceTree = SOURCE_ROOT; }; + 97587A951D1061C0006EE1AA /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnapshotHelper.swift; path = "Kiwix-iOSUITests/SnapshotHelper.swift"; sourceTree = SOURCE_ROOT; }; 975B90F81CEB75CB00D13906 /* ZimFilesController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ZimFilesController.swift; path = "Kiwix-OSX/Controllers/ZimFilesController.swift"; sourceTree = SOURCE_ROOT; }; 975B90FD1CEB909100D13906 /* iOSExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = iOSExtensions.swift; path = "Kiwix-iOS/iOSExtensions.swift"; sourceTree = SOURCE_ROOT; }; 9763A6281CEB9E55008A2718 /* OSXExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OSXExtensions.swift; path = "Kiwix-OSX/OSXExtensions.swift"; sourceTree = SOURCE_ROOT; }; @@ -1225,7 +1226,8 @@ isa = PBXGroup; children = ( 973BCD1B1CEB403700F10B44 /* Info.plist */, - 973BCD1C1CEB403700F10B44 /* KiwixUITests.swift */, + 973BCD1C1CEB403700F10B44 /* SnapshotAutomation.swift */, + 97587A951D1061C0006EE1AA /* SnapshotHelper.swift */, ); name = "Kiwix-iOSUITests"; path = KiwixUITests; @@ -1557,7 +1559,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 973BCD1D1CEB403700F10B44 /* Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1934,7 +1935,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 973BCD1E1CEB403700F10B44 /* KiwixUITests.swift in Sources */, + 973BCD1E1CEB403700F10B44 /* SnapshotAutomation.swift in Sources */, + 97587A961D1061C0006EE1AA /* SnapshotHelper.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2274,7 +2276,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; - INFOPLIST_FILE = KiwixTests/Info.plist; + INFOPLIST_FILE = "Kiwix-iOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = self.KiwixTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2288,7 +2290,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; - INFOPLIST_FILE = KiwixTests/Info.plist; + INFOPLIST_FILE = "Kiwix-iOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = self.KiwixTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2300,12 +2302,13 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - INFOPLIST_FILE = KiwixUITests/Info.plist; + INFOPLIST_FILE = "Kiwix-iOSUITests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = self.KiwixUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - TEST_TARGET_NAME = Kiwix; + TEST_TARGET_NAME = "Kiwix-iOS"; USES_XCTRUNNER = YES; }; name = Debug; @@ -2314,11 +2317,12 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - INFOPLIST_FILE = KiwixUITests/Info.plist; + INFOPLIST_FILE = "Kiwix-iOSUITests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = self.KiwixUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_TARGET_NAME = Kiwix; + PROVISIONING_PROFILE = ""; + TEST_TARGET_NAME = "Kiwix-iOS"; USES_XCTRUNNER = YES; }; name = Release; @@ -2426,6 +2430,7 @@ 97E609FD1D103DED00EBCB9D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ diff --git a/Snapfile b/Snapfile new file mode 100644 index 00000000..dbe8db60 --- /dev/null +++ b/Snapfile @@ -0,0 +1,33 @@ +# Uncomment the lines below you want to change by removing the # in the beginning + +# A list of devices you want to take the screenshots from +devices([ +# "iPhone 6", +# "iPhone 6 Plus", +# "iPhone 5", +# "iPhone 4s", + "iPad Retina", + "iPad Pro" +]) + +languages([ + "en-US" +]) + +# Arguments to pass to the app on launch. See https://github.com/fastlane/snapshot#launch-arguments +# launch_arguments(["-favColor red"]) + +# The name of the scheme which contains the UI Tests +scheme "Kiwix-iOS" + +# Where should the resulting screenshots be stored? +# output_directory "./screenshots" + +# clear_previous_screenshots true # remove the '#' to clear all previously generated screenshots before creating new ones + +# Choose which project/workspace to use +# project "./Project.xcodeproj" +# workspace "./Project.xcworkspace" + +# For more information about all available options run +# snapshot --help