forked from agentic-review-benchmarks/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowsingPDFTests.swift
More file actions
260 lines (221 loc) · 10 KB
/
BrowsingPDFTests.swift
File metadata and controls
260 lines (221 loc) · 10 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// 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
import Common
let PDF_website = [
"url": "https://storage.googleapis.com/mobile_test_assets/public/pdf-test.pdf",
"urlValue": "education.gov.yk.ca",
"pdfValue": "storage.googleapis.com",
"bookmarkLabel": "https://storage.googleapis.com/mobile_test_assets/public/pdf-test.pdf",
"longUrlValue": "http://www.education.gov.yk.ca/"
]
class BrowsingPDFTests: BaseTestCase {
let url = XCUIApplication().textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField]
private var topSites: TopSitesScreen!
private var browser: BrowserScreen!
private var pdf: PDFScreen!
private var contextMenu: ContextMenuScreen!
private var library: LibraryScreen!
override func setUp() async throws {
// Test name looks like: "[Class testFunc]", parse out the function name
try await super.setUp()
topSites = TopSitesScreen(app: app)
contextMenu = ContextMenuScreen(app: app)
pdf = PDFScreen(app: app)
browser = BrowserScreen(app: app)
library = LibraryScreen(app: app)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307116
func testOpenPDFViewer() {
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
mozWaitForValueContains(url, value: PDF_website["pdfValue"]!)
// Swipe Up and Down
app.swipeUp()
mozWaitForElementToExist(app.staticTexts["1 of 1"])
app.swipeDown()
mozWaitForElementToExist(app.staticTexts["1 of 1"])
}
// https://mozilla.testrail.io/index.php?/cases/view/2307117
func testOpenLinkFromPDF() {
// Sometimes the test fails before opening the URL
// Let's make sure the homepage is ready
mozWaitForElementToExist(app.collectionViews[AccessibilityIdentifiers.FirefoxHomepage.collectionView])
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Click on a link on the pdf and check that the website is shown
app.webViews.links.element(boundBy: 0).tapOnApp()
waitUntilPageLoad()
let checkboxValidation = app.webViews["Web content"].staticTexts["Verify you are human"]
if checkboxValidation.exists {
checkboxValidation.waitAndTap()
}
mozWaitForValueContains(url, value: PDF_website["urlValue"]!)
// Let's comment the next line until that fails intermittently due to the page re-direction
// mozWaitForElementToExist(app.staticTexts["Education and schools"])
// Go back to pdf view
app.buttons[AccessibilityIdentifiers.Toolbar.backButton].waitAndTap()
mozWaitForValueContains(url, value: PDF_website["pdfValue"]!)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307117
func testOpenLinkFromPDF_TAE() {
// Sometimes the test fails before opening the URL. Let's make sure the homepage is ready
topSites.assertVisible()
// Open the PDF URL and wait for the page to load
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Tap on a link within the PDF and check that the website is shown
pdf.tapOnLinkInPdf(atIndex: 0)
waitUntilPageLoad()
// Handle potential human verification step
browser.handleHumanVerification()
// Assert that the browser is at the correct URL
browser.assertAddressBarContains(value: PDF_website["urlValue"]!)
// Go back to the PDF view
browser.tapBackButton()
// Assert that the browser is back at the PDF URL
browser.assertAddressBarContains(value: PDF_website["pdfValue"]!)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307118
func testLongPressOnPDFLink() {
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Long press on a link on the pdf and check the options shown
longPressOnPdfLink()
waitForElementsToExist(
[
app.staticTexts[PDF_website["longUrlValue"]!],
app.buttons["Open"],
app.buttons["Add to Reading List"]
]
)
if #available(iOS 16, *) {
mozWaitForElementToExist(app.buttons["Copy Link"])
} else {
mozWaitForElementToExist(app.buttons["Copy"])
}
mozWaitForElementToExist(app.buttons["Share…"])
}
// https://mozilla.testrail.io/index.php?/cases/view/2307119
func testLongPressOnPDFLinkToAddToReadingList() {
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Long press on a link on the pdf and check the options shown
longPressOnPdfLink()
mozWaitForElementToExist(app.staticTexts[PDF_website["longUrlValue"]!])
app.buttons["Add to Reading List"].waitAndTap()
navigator.nowAt(BrowserTab)
// Go to reading list and check that the item is there
navigator.goto(LibraryPanel_ReadingList)
let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts[PDF_website["longUrlValue"]!]
mozWaitForElementToExist(savedToReadingList)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307120
// Smoketest
func testPinPDFtoTopSites() {
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
navigator.goto(BrowserTabMenuMore)
navigator.performAction(Action.PinToTopSitesPAM)
navigator.performAction(Action.OpenNewTabFromTabTray)
let pinnedItem = app
.links[AccessibilityIdentifiers.FirefoxHomepage.TopSites.itemCell]
.staticTexts[PDF_website["bookmarkLabel"]!]
mozWaitForElementToExist(pinnedItem)
// Open pdf from pinned site
let pdfTopSite = app
.collectionViews[AccessibilityIdentifiers.FirefoxHomepage.collectionView]
.links["Pinned: \(PDF_website["bookmarkLabel"]!)"]
.children(matching: .other)
.element
.children(matching: .other)
.element(boundBy: 0)
if iPad() {
app.buttons["Cancel"].waitAndTap()
}
pdfTopSite.waitAndTap()
waitUntilPageLoad()
mozWaitForValueContains(url, value: PDF_website["pdfValue"]!)
// Remove pdf pinned site
navigator.performAction(Action.OpenNewTabFromTabTray)
if iPad() {
app.buttons["Cancel"].waitAndTap()
}
mozWaitForElementToExist(pinnedItem)
pdfTopSite.press(forDuration: 1)
app.tables.cells.buttons[StandardImageIdentifiers.Large.pinSlash].waitAndTap()
mozWaitForElementToNotExist(pinnedItem)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307120
// Smoketest TAE
func testPinPDFtoTopSites_TAE() {
// 1. Open a PDF and pin it to Top Sites.
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Assumes BrowserTabMenuMore and PinToTopSitesPAM are custom navigator actions
navigator.goto(BrowserTabMenuMore)
navigator.performAction(Action.PinToTopSitesPAM)
// 2. Go to the homepage and verify the PDF is pinned.
navigator.performAction(Action.OpenNewTabFromTabTray)
// Wait for the pinned item to exist on the Top Sites screen.
let bookmarkLabel = PDF_website["bookmarkLabel"]!
topSites.assertTopSiteExists(named: bookmarkLabel)
// 3. Open the PDF from the pinned site and verify the URL.
// Tap on the pinned PDF item.
topSites.tapOnPinnedSite(named: bookmarkLabel)
waitUntilPageLoad()
// Assert the browser is showing the correct PDF URL.
browser.assertAddressBarContains(value: PDF_website["pdfValue"]!)
// 4. Go back to the homepage and unpin the item.
navigator.performAction(Action.OpenNewTabFromTabTray)
topSites.assertTopSiteExists(named: bookmarkLabel)
// Long-press the pinned site to open the context menu.
topSites.longPressOnPinnedSite(named: bookmarkLabel)
// Remove the pinned site via the context menu.
contextMenu.unpinFromTopSites()
// 5. Verify the item has been unpinned.
topSites.assertTopSiteDoesNotExist(named: bookmarkLabel)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307121
// Smoketest
func testBookmarkPDF() {
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
navigator.goto(BrowserTabMenu)
navigator.performAction(Action.Bookmark)
navigator.goto(BrowserTabMenu)
navigator.goto(LibraryPanel_Bookmarks)
waitForElementsToExist(
[
app.tables["Bookmarks List"],
app.tables["Bookmarks List"].staticTexts[PDF_website["bookmarkLabel"]!]
]
)
}
// https://mozilla.testrail.io/index.php?/cases/view/2307121
// Smoketest TAE
func testBookmarkPDF_TAE() {
library = LibraryScreen(app: app)
// Open the PDF URL and wait for the page to load
navigator.openURL(PDF_website["url"]!)
waitUntilPageLoad()
// Navigate to the browser menu and perform the bookmark action
navigator.goto(BrowserTabMenu)
navigator.performAction(Action.Bookmark)
// Navigate to the bookmarks section
navigator.goto(BrowserTabMenu)
navigator.goto(LibraryPanel_Bookmarks)
// Assert that the bookmarked item exists
library.assertBookmarkExists(named: PDF_website["bookmarkLabel"]!)
}
private func longPressOnPdfLink() {
let link = app.webViews.links.element(boundBy: 0)
mozWaitForElementToExist(link)
let startCoordinate = link.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0))
let endCoordinate = link.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
startCoordinate.press(forDuration: 3, thenDragTo: endCoordinate)
}
}