forked from euwars/browser-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarketingUITests.swift
118 lines (91 loc) · 3.98 KB
/
MarketingUITests.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import XCTest
class MarketingSnapshotTests: XCTestCase {
let LoadingTimeout: NSTimeInterval = 60
let exists = NSPredicate(format: "exists = true")
let loaded = NSPredicate(format: "value BEGINSWITH '100'")
var sleep = false
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
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func loadWebPage(url: String, testForAutocompleteDialog: Bool = false) {
let app = XCUIApplication()
let addressTextField = app.textFields.elementBoundByIndex(0)
addressTextField.tap()
addressTextField.typeText(url)
if testForAutocompleteDialog {
// for var idx:UInt = 0; idx < app.buttons.count; idx++ {
// let button = app.buttons.elementBoundByIndex(idx)
// print("\(button.identifier): \(button.value)")
// }
app.buttons.elementBoundByIndex(8).tap()
}
let progressIndicator = app.progressIndicators.elementBoundByIndex(0)
expectationForPredicate(exists, evaluatedWithObject: progressIndicator, handler: nil)
expectationForPredicate(loaded, evaluatedWithObject: progressIndicator, handler: nil)
app.typeText("\n")
waitForExpectationsWithTimeout(LoadingTimeout, handler: nil)
}
func testTakeMarketingScreenshots() {
let app = XCUIApplication()
// dismiss the intro tour
app.buttons.elementBoundByIndex(1).tap()
snapshot("00TopSites")
// go to synced tabs home screen
app.buttons.elementBoundByIndex(4).tap()
snapshot("03SyncedTabs")
// return to top sites
app.buttons.elementBoundByIndex(1).tap()
// create new tab
app.staticTexts.firstWithName("1").tap()
let addTabButton = app.buttons.elementBoundByIndex(3)
addTabButton.tap()
// load some web pages in some new tabs
loadWebPage("http://twitter.com", testForAutocompleteDialog: true)
app.staticTexts.firstWithName("2").tap()
addTabButton.tap()
loadWebPage("https://mozilla.org/firefox/desktop")
app.staticTexts.firstWithName("3").tap()
addTabButton.tap()
loadWebPage("https://mozilla.org")
app.staticTexts.firstWithName("4").tap()
addTabButton.tap()
loadWebPage("firefox")
loadWebPage("https://mozilla.org/firefox/new")
app.staticTexts.firstWithName("5").tap()
snapshot("02TabTray")
// return to first tab
app.collectionViews.firstMatchingType(.Cell).tap()
let addressTextField = app.textFields.elementBoundByIndex(0)
addressTextField.tap()
// perform a search but don't complete (we're testing autocomplete here)
addressTextField.typeText("firef")
snapshot("01SearchResults")
// cancel search
app.buttons.elementBoundByIndex(1).tap()
}
}
extension XCUIElementQuery {
func firstWithName(name: String) -> XCUIElement {
let values = self.containingPredicate(NSPredicate(format: "label = '\(name)'"))
if values.count > 0 {
return values.elementBoundByIndex(0)
}
return self.elementBoundByIndex(0)
}
func firstMatchingType( type: XCUIElementType) -> XCUIElement {
return self.childrenMatchingType(type).elementBoundByIndex(0)
}
}