Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import XCTest
6
7
class MarketingSnapshotTests: XCTestCase {
8
9
let LoadingTimeout: NSTimeInterval = 60
10
let exists = NSPredicate(format: "exists = true")
11
let loaded = NSPredicate(format: "value BEGINSWITH '100'")
12
13
var sleep = false
14
15
override func setUp() {
16
super.setUp()
17
18
// Put setup code here. This method is called before the invocation of each test method in the class.
19
20
// In UI tests it is usually best to stop immediately when a failure occurs.
21
continueAfterFailure = false
22
23
let app = XCUIApplication()
24
setupSnapshot(app)
25
app.launch()
26
}
27
28
override func tearDown() {
29
// Put teardown code here. This method is called after the invocation of each test method in the class.
30
super.tearDown()
31
}
32
33
func loadWebPage(url: String, testForAutocompleteDialog: Bool = false) {
34
let app = XCUIApplication()
35
let addressTextField = app.textFields.elementBoundByIndex(0)
36
addressTextField.tap()
37
addressTextField.typeText(url)
38
if testForAutocompleteDialog {
39
// for var idx:UInt = 0; idx < app.buttons.count; idx++ {
40
// let button = app.buttons.elementBoundByIndex(idx)
41
// print("\(button.identifier): \(button.value)")
42
// }
43
app.buttons.elementBoundByIndex(8).tap()
44
}
45
let progressIndicator = app.progressIndicators.elementBoundByIndex(0)
46
expectationForPredicate(exists, evaluatedWithObject: progressIndicator, handler: nil)
47
expectationForPredicate(loaded, evaluatedWithObject: progressIndicator, handler: nil)
48
app.typeText("\n")
49
waitForExpectations(timeout: LoadingTimeout, handler: nil)
50
}
51
52
func testTakeMarketingScreenshots() {
53
54
let app = XCUIApplication()
55
56
// dismiss the intro tour
57
app.buttons.elementBoundByIndex(1).tap()
58
snapshot("00TopSites")
59
60
// go to synced tabs home screen
61
app.buttons.elementBoundByIndex(4).tap()
62
snapshot("03SyncedTabs")
63
64
// return to top sites
65
app.buttons.elementBoundByIndex(1).tap()
66
67
// create new tab
68
app.staticTexts.firstWithName("1").tap()
69
let addTabButton = app.buttons.elementBoundByIndex(3)
70
addTabButton.tap()
71
72
// load some web pages in some new tabs
73
loadWebPage("http://twitter.com", testForAutocompleteDialog: true)
74
75
app.staticTexts.firstWithName("2").tap()
76
addTabButton.tap()
78
79
app.staticTexts.firstWithName("3").tap()
80
addTabButton.tap()
81
loadWebPage("https://mozilla.org")
82
app.staticTexts.firstWithName("4").tap()
83
addTabButton.tap()
84
85
loadWebPage("firefox")
87
app.staticTexts.firstWithName("5").tap()
88
snapshot("02TabTray")
89
90
// return to first tab
91
app.collectionViews.firstMatchingType(.Cell).tap()
92
let addressTextField = app.textFields.elementBoundByIndex(0)
93
addressTextField.tap()
94
95
// perform a search but don't complete (we're testing autocomplete here)
96
addressTextField.typeText("firef")
97
snapshot("01SearchResults")
98
99
// cancel search
100
app.buttons.elementBoundByIndex(1).tap()
101
}
102
103
}
104
105
extension XCUIElementQuery {
106
func firstWithName(name: String) -> XCUIElement {
107
let values = self.containingPredicate(NSPredicate(format: "label = '\(name)'"))
108
if values.count > 0 {
109
return values.elementBoundByIndex(0)
110
}
111
112
return self.elementBoundByIndex(0)
113
}
114
115
func firstMatchingType( type: XCUIElementType) -> XCUIElement {
116
return self.childrenMatchingType(type).elementBoundByIndex(0)
117
}
118
}