-
Notifications
You must be signed in to change notification settings - Fork 27
/
BookmarkingTests.swift
112 lines (94 loc) · 3.52 KB
/
BookmarkingTests.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
/* 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
let url_1 = "www.google.com"
let url_2 = ["url": "www.mozilla.org", "bookmarkLabel": "Internet for people, not profit — Mozilla"]
class BookmarkingTests: 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 bookmark() {
navigator.goto(PageOptionsMenu)
waitforExistence(app.tables.cells["Bookmark This Page"])
app.tables.cells["Bookmark This Page"].tap()
navigator.nowAt(BrowserTab)
}
private func unbookmark() {
navigator.goto(PageOptionsMenu)
waitforExistence(app.tables.cells["Remove Bookmark"])
app.cells["Remove Bookmark"].tap()
navigator.nowAt(BrowserTab)
}
private func checkBookmarked() {
navigator.goto(PageOptionsMenu)
waitforExistence(app.tables.cells["Remove Bookmark"])
if iPad() {
app.otherElements["PopoverDismissRegion"].tap()
navigator.nowAt(BrowserTab)
} else {
navigator.goto(BrowserTab)
}
}
private func checkUnbookmarked() {
navigator.goto(PageOptionsMenu)
waitforExistence(app.tables.cells["Bookmark This Page"])
if iPad() {
app.otherElements["PopoverDismissRegion"].tap()
navigator.nowAt(BrowserTab)
} else {
navigator.goto(BrowserTab)
}
}
func testBookmarkingUI() {
// Go to a webpage, and add to bookmarks, check it's added
navigator.createNewTab()
loadWebPage(url_1)
navigator.nowAt(BrowserTab)
bookmark()
checkBookmarked()
// Load a different page on a new tab, check it's not bookmarked
navigator.createNewTab()
loadWebPage(url_2["url"]!)
navigator.nowAt(BrowserTab)
checkUnbookmarked()
// Go back, check it's still bookmarked, check it's on bookmarks home panel
navigator.goto(TabTray)
app.collectionViews.cells["Google"].tap()
navigator.nowAt(BrowserTab)
checkBookmarked()
// Open it, then unbookmark it, and check it's no longer on bookmarks home panel
unbookmark()
checkUnbookmarked()
}
private func checkEmptyBookmarkList() {
let list = app.tables["Bookmarks List"].cells.count
XCTAssertEqual(list, 0, "There should not be any entry in the bookmarks list")
}
private func checkItemInBookmarkList() {
let list = app.tables["Bookmarks List"].cells.count
XCTAssertEqual(list, 1, "There should be an entry in the bookmarks list")
XCTAssertTrue(app.tables["Bookmarks List"].staticTexts[url_2["bookmarkLabel"]!].exists)
}
func testAccessBookmarksFromContextMenu() {
//First time there is not any bookmark
navigator.browserPerformAction(.openBookMarksOption)
checkEmptyBookmarkList()
navigator.nowAt(BrowserTab)
//Add a bookmark
navigator.createNewTab()
loadWebPage(url_2["url"]!)
navigator.nowAt(BrowserTab)
bookmark()
//There should be a bookmark
navigator.browserPerformAction(.openBookMarksOption)
checkItemInBookmarkList()
}
}