-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnapshotHelper.swift
66 lines (53 loc) · 1.91 KB
/
SnapshotHelper.swift
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
//
// SnapshotHelper.swift
// Example
//
// Created by Felix Krause on 10/8/15.
// Copyright © 2015 Felix Krause. All rights reserved.
//
import Foundation
import XCTest
var deviceLanguage = ""
func setLanguage(app: XCUIApplication)
{
Snapshot.setLanguage(app)
}
func snapshot(name: String, waitForLoadingIndicator: Bool = false)
{
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
}
@objc class Snapshot: NSObject
{
class func setLanguage(app: XCUIApplication)
{
let path = "/tmp/language.txt"
do {
let locale = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String
deviceLanguage = locale.substringToIndex(locale.startIndex.advancedBy(2, limit:locale.endIndex))
app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))", "-AppleLocale", "\"\(locale)\"","-ui_testing"]
} catch {
print("Couldn't detect/set language...")
}
}
class func snapshot(name: String, waitForLoadingIndicator: Bool = false)
{
if (waitForLoadingIndicator)
{
waitForLoadingIndicatorToDisappear()
}
print("snapshot: \(name)") // more information about this, check out https://github.com/krausefx/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 (query.count > 4) {
sleep(1)
print("Number of Elements in Status Bar: \(query.count)... waiting for status bar to disappear")
}
}
}
// Please don't remove the lines below
// They are used to detect outdated configuration files
// SnapshotHelperVersion [[1.0]]