-
Notifications
You must be signed in to change notification settings - Fork 27
/
FindInPageTest.swift
122 lines (94 loc) · 4.32 KB
/
FindInPageTest.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
119
120
121
122
/* 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 FindInPageTests: BaseTestCase {
var navigator: Navigator!
var app: XCUIApplication!
override func setUp() {
super.setUp()
app = XCUIApplication()
navigator = createScreenGraph(app).navigator(self)
}
override func tearDown() {
super.tearDown()
}
private func openFindInPageFromMenu() {
navigator.goto(FindInPage)
waitforExistence(app.buttons["Next in-page result"])
waitforExistence(app.buttons["Previous in-page result"])
XCTAssertTrue(app.textFields[""].exists)
}
func testFindFromMenu() {
openFindInPageFromMenu()
// Enter some text to start finding
app.textFields[""].typeText("Book")
// Once there are matches, test previous/next buttons
waitforExistence(app.staticTexts["1/5"])
XCTAssertTrue(app.staticTexts["1/5"].exists)
let nextInPageResultButton = app.buttons["Next in-page result"]
nextInPageResultButton.tap()
waitforExistence(app.staticTexts["2/5"])
XCTAssertTrue(app.staticTexts["2/5"].exists)
nextInPageResultButton.tap()
waitforExistence(app.staticTexts["3/5"])
XCTAssertTrue(app.staticTexts["3/5"].exists)
let previousInPageResultButton = app.buttons["Previous in-page result"]
previousInPageResultButton.tap()
waitforExistence(app.staticTexts["2/5"])
XCTAssertTrue(app.staticTexts["2/5"].exists)
previousInPageResultButton.tap()
waitforExistence(app.staticTexts["1/5"])
XCTAssertTrue(app.staticTexts["1/5"].exists)
// Tapping on close dismisses the search bar
//app.buttons["Done"].tap()
navigator.goto(BrowserTab)
waitforNoExistence(app.textFields["Book"])
}
func testQueryWithNoMatches() {
openFindInPageFromMenu()
// Try to find text which does not match and check that there are not results
app.textFields["FindInPage.searchField"].typeText("foo")
waitforExistence(app.staticTexts["0/0"])
XCTAssertTrue(app.staticTexts["0/0"].exists, "There should not be any matches")
}
func testBarDissapearsWhenReloading() {
openFindInPageFromMenu()
// Before reloading, it is necessary to hide the keyboard
app.textFields["url"].tap()
app.textFields["address"].typeText("\n")
// Once the page is reloaded the search bar should not appear
waitforNoExistence(app.textFields[""])
XCTAssertFalse(app.textFields[""].exists)
}
func testBarDissapearsWhenOpeningTabsTray() {
openFindInPageFromMenu()
// Dismiss keyboard
app.otherElements["contentView"].tap()
navigator.nowAt(BrowserTab)
// Going to tab tray and back to the website hides the search field.
navigator.goto(TabTray)
waitforExistence(app.collectionViews.cells["The Book of Mozilla"])
app.collectionViews.cells["The Book of Mozilla"].tap()
XCTAssertFalse(app.textFields[""].exists)
XCTAssertFalse(app.buttons["Next in-page result"].exists)
XCTAssertFalse(app.buttons["Previous in-page result"].exists)
}
func testFindFromSelection() {
navigator.goto(BrowserTab)
let textToFind = "from"
// Long press on the word to be found
waitforExistence(app.webViews.staticTexts[textToFind])
let stringToFind = app.webViews.staticTexts.matching(identifier: textToFind)
let firstStringToFind = stringToFind.element(boundBy: 0)
firstStringToFind.press(forDuration: 3)
// Find in page is correctly launched, bar with text pre-filled and
// the buttons to find next and previous
waitforExistence(app.menuItems["Find in Page"])
app.menuItems["Find in Page"].tap()
waitforExistence(app.textFields[textToFind])
XCTAssertTrue(app.textFields[textToFind].exists, "The bar does not appear with the text selected to be found")
XCTAssertTrue(app.buttons["Previous in-page result"].exists, "Find previus button exists")
XCTAssertTrue(app.buttons["Next in-page result"].exists, "Find next button exists")
}
}