Skip to content

Commit 1444c07

Browse files
authored
Refactor MTE-4923 Refactor DataManagementTests with TAE (#29859)
1 parent 3857ebd commit 1444c07

File tree

8 files changed

+312
-1
lines changed

8 files changed

+312
-1
lines changed

firefox-ios/firefox-ios-tests/Tests/FullFunctionalTestPlan.xctestplan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"CreditCardsTests\/testEditSavedCardsUI()",
122122
"CronTabsPerformanceTest",
123123
"DataManagementTests\/testWebSiteDataEnterFirstTime()",
124+
"DataManagementTests\/testWebSiteDataEnterFirstTime_TAE()",
124125
"DatabaseFixtureTest\/testPerBookmarks1000openMenu()",
125126
"DatabaseFixtureTest\/testPerBookmarks1000startUp()",
126127
"DatabaseFixtureTest\/testPerfHistory4000openMenu()",

firefox-ios/firefox-ios-tests/Tests/Smoketest.xctestplan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
"CreditCardsTests\/testVerifyThatTheEditedCreditCardIsSaved()",
191191
"CronTabsPerformanceTest",
192192
"DataManagementTests\/testFilterWebsiteData()",
193+
"DataManagementTests\/testWebSiteDataEnterFirstTime_TAE()",
193194
"DataManagementTests\/testWebSiteDataOptions()",
194195
"DatabaseFixtureTest",
195196
"DesktopModeTestsIphone\/testClearPrivateData()",

firefox-ios/firefox-ios-tests/Tests/TAESmokeTestPlan.xctestplan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
"CreditCardsTests\/testUpdatePrompt()",
118118
"CreditCardsTests\/testVerifyThatMultipleCardsCanBeAdded()",
119119
"CreditCardsTests\/testVerifyThatTheEditedCreditCardIsSaved()",
120-
"DataManagementTests",
121120
"DataManagementTests\/testFilterWebsiteData()",
122121
"DataManagementTests\/testWebSiteDataEnterFirstTime()",
123122
"DataManagementTests\/testWebSiteDataOptions()",

firefox-ios/firefox-ios-tests/Tests/XCUITests/DataManagementTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import XCTest
66

77
class DataManagementTests: BaseTestCase {
8+
private var webSitesDataScreen: WebsiteDataScreen!
9+
810
func cleanAllData() {
911
navigator.goto(WebsiteDataSettings)
1012
mozWaitForElementToExist(app.tables.otherElements["Website Data"])
@@ -88,6 +90,22 @@ class DataManagementTests: BaseTestCase {
8890
}
8991
}
9092

93+
// https://mozilla.testrail.io/index.php?/cases/view/2307017
94+
// Smoketest TAE
95+
func testWebSiteDataEnterFirstTime_TAE() {
96+
webSitesDataScreen = WebsiteDataScreen(app: app)
97+
navigator.goto(WebsiteDataSettings)
98+
webSitesDataScreen.clearAllWebsiteData()
99+
navigator.nowAt(NewTabScreen)
100+
navigator.openURL("example.com")
101+
waitUntilPageLoad()
102+
navigator.goto(WebsiteDataSettings)
103+
webSitesDataScreen.waitUntilListIsReady()
104+
webSitesDataScreen.expandShowMoreIfNeeded()
105+
webSitesDataScreen.waitForExampleDomain()
106+
webSitesDataScreen.assertWebsiteDataVisible()
107+
}
108+
91109
// https://mozilla.testrail.io/index.php?/cases/view/2802088
92110
func testFilterWebsiteData() {
93111
cleanAllData()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
final class WebsiteDataScreen {
8+
private let app: XCUIApplication
9+
private let sel: WebsiteDataSelectorsSet
10+
11+
init(app: XCUIApplication, selectors: WebsiteDataSelectorsSet = WebsiteDataSelectors()) {
12+
self.app = app
13+
self.sel = selectors
14+
}
15+
16+
func clearAllWebsiteData() {
17+
BaseTestCase().mozWaitForElementToExist(sel.TABLE_WEBSITE_DATA.element(in: app))
18+
BaseTestCase().mozWaitForElementToNotExist(app.activityIndicators.firstMatch)
19+
20+
let clearAll = sel.clearAllLabel(in: app)
21+
BaseTestCase().mozWaitForElementToExist(clearAll)
22+
clearAll.waitAndTap()
23+
24+
let okButton = sel.ALERT_OK_BUTTON.element(in: app)
25+
okButton.waitAndTap()
26+
BaseTestCase().mozWaitForElementToNotExist(okButton)
27+
sel.BUTTON_DATA_MANAGEMENT.element(in: app).waitAndTap()
28+
sel.BUTTON_SETTINGS.element(in: app).waitAndTap()
29+
sel.BUTTON_DONE.element(in: app).waitAndTap()
30+
}
31+
32+
func assertAllWebsiteDataCleared() {
33+
XCTAssertEqual(app.cells.buttons.images.count, 0, "The Website data has not cleared correctly")
34+
}
35+
36+
func navigateBackToBrowser() {
37+
Selector.buttonByLabel("Data Management", description: "Back").element(in: app).waitAndTap()
38+
Selector.buttonByLabel("Settings", description: "Back").element(in: app).waitAndTap()
39+
Selector.buttonByLabel("Done", description: "Done").element(in: app).waitAndTap()
40+
}
41+
42+
func waitUntilListIsReady(timeout: TimeInterval = TIMEOUT) {
43+
BaseTestCase().mozWaitForElementToExist(sel.TABLE_WEBSITE_DATA.element(in: app), timeout: timeout)
44+
45+
if #available(iOS 17, *) {
46+
let circleInCells = sel.circleImageInsideCells(app)
47+
BaseTestCase().mozWaitForElementToExist(circleInCells, timeout: timeout)
48+
} else {
49+
let anyBtn = sel.anyTableButton(app)
50+
BaseTestCase().mozWaitForElementToExist(anyBtn, timeout: timeout)
51+
}
52+
}
53+
54+
func expandShowMoreIfNeeded() {
55+
let showMore = sel.CELL_SHOW_MORE.element(in: app)
56+
if showMore.exists {
57+
showMore.waitAndTap()
58+
}
59+
}
60+
61+
func waitForExampleDomain(timeout: TimeInterval = TIMEOUT) {
62+
BaseTestCase().mozWaitForElementToExist(sel.EXAMPLE_EQUAL.element(in: app), timeout: timeout)
63+
}
64+
65+
func assertWebsiteDataVisible(timeout: TimeInterval = TIMEOUT) {
66+
if #available(iOS 17, *) {
67+
let circle = sel.circleImageInsideCells(app)
68+
BaseTestCase().mozWaitForElementToExist(circle, timeout: timeout)
69+
XCTAssertTrue(circle.exists, "Expected circle image inside cells")
70+
} else {
71+
let exampleText = sel.STATIC_TEXT_EXAMPLE_IN_CELL.element(in: app)
72+
BaseTestCase().mozWaitForElementToExist(exampleText, timeout: timeout)
73+
XCTAssertTrue(exampleText.exists, "Expected a staticText 'example.com' inside a cell")
74+
}
75+
}
76+
}

firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorHelper.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ enum SelectorStrategy {
1414
case collectionViewById(String)
1515
case tableById(String)
1616
case textFieldById(String)
17+
case imageById(String)
18+
case otherInTablesById(String)
1719
}
1820

1921
// Selector model (with metadata)
@@ -60,6 +62,10 @@ extension Selector {
6062
return app.tables[value]
6163
case .textFieldById:
6264
return app.textFields[value]
65+
case .imageById:
66+
return app.images[value]
67+
case .otherInTablesById(let id):
68+
return app.tables.otherElements[id]
6369
}
6470
}
6571

@@ -86,6 +92,10 @@ extension Selector {
8692
return app.tables.matching(identifier: value)
8793
case .textFieldById:
8894
return app.textFields.matching(identifier: value)
95+
case .imageById:
96+
return app.images.matching(identifier: value)
97+
case .otherInTablesById(let id):
98+
return app.tables.otherElements.matching(identifier: id)
8999
}
90100
}
91101

firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorShortcuts.swift

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,85 @@ extension Selector {
7777
let p = NSPredicate(format: "elementType == %d", XCUIElement.ElementType.table.rawValue)
7878
return Selector(strategy: .predicate(p), value: "firstTable", description: description, groups: groups)
7979
}
80+
81+
static func imageId(_ id: String, description: String, groups: [String] = []) -> Selector {
82+
Selector(strategy: .imageById(id), value: id, description: description, groups: groups)
83+
}
84+
/*
85+
static func buttonByLabel(_ label: String, description: String, groups: [String] = []) -> Selector {
86+
let predicate = NSPredicate(
87+
format: "elementType == %d AND label == %@",
88+
XCUIElement.ElementType.button.rawValue,
89+
label
90+
)
91+
return Selector(strategy: .predicate(predicate), value: label, description: description, groups: groups)
92+
}
93+
*/
94+
static func tableOtherById(_ id: String, description: String, groups: [String] = []) -> Selector {
95+
Selector(strategy: .otherInTablesById(id), value: id, description: description, groups: groups)
96+
}
97+
98+
static func cellById(_ id: String, description: String, groups: [String] = []) -> Selector {
99+
let p = NSPredicate(format: "elementType == %d AND identifier == %@",
100+
XCUIElement.ElementType.cell.rawValue,
101+
id)
102+
return Selector(strategy: .predicate(p), value: id, description: description, groups: groups)
103+
}
104+
105+
static func imageById(_ id: String, description: String, groups: [String] = []) -> Selector {
106+
Selector(
107+
strategy: .predicate(
108+
NSPredicate(
109+
format: "elementType == %d AND identifier == %@",
110+
XCUIElement.ElementType.image.rawValue,
111+
id
112+
)
113+
),
114+
value: id,
115+
description: description,
116+
groups: groups
117+
)
118+
}
119+
120+
static func staticTextByExactLabel(_ label: String, description: String, groups: [String] = []) -> Selector {
121+
Selector(
122+
strategy: .predicate(
123+
NSPredicate(
124+
format: "elementType == %d AND label == %@",
125+
XCUIElement.ElementType.staticText.rawValue,
126+
label
127+
)
128+
),
129+
value: label,
130+
description: description,
131+
groups: groups
132+
)
133+
}
134+
135+
static func staticTextLabelContains(_ text: String, description: String, groups: [String] = []) -> Selector {
136+
Selector(
137+
strategy: .predicate(
138+
NSPredicate(
139+
format: "elementType == %d AND label CONTAINS %@",
140+
XCUIElement.ElementType.staticText.rawValue,
141+
text
142+
)
143+
),
144+
value: text,
145+
description: description,
146+
groups: groups
147+
)
148+
}
149+
150+
static func cellStaticTextLabelContains(_ text: String, description: String, groups: [String] = []) -> Selector {
151+
let predicate = NSPredicate(
152+
format: "elementType == %d AND label CONTAINS[c] %@",
153+
XCUIElement.ElementType.staticText.rawValue,
154+
text
155+
)
156+
return Selector(strategy: .predicate(predicate),
157+
value: text,
158+
description: description,
159+
groups: groups)
160+
}
80161
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
protocol WebsiteDataSelectorsSet {
8+
var TABLE_WEBSITE_DATA: Selector { get }
9+
var CELL_CLEAR_ALL: Selector { get }
10+
var ALERT_OK_BUTTON: Selector { get }
11+
var BUTTON_DATA_MANAGEMENT: Selector { get }
12+
var BUTTON_SETTINGS: Selector { get }
13+
var BUTTON_DONE: Selector { get }
14+
var CELL_SHOW_MORE: Selector { get }
15+
var EXAMPLE_EQUAL: Selector { get }
16+
var EXAMPLE_CONTAINS: Selector { get }
17+
var CIRCLE_IMAGE_ANYWHERE: Selector { get }
18+
var STATIC_TEXT_EXAMPLE_IN_CELL: Selector { get }
19+
func clearAllLabel(in app: XCUIApplication) -> XCUIElement
20+
func circleImageInsideCells(_ app: XCUIApplication) -> XCUIElement
21+
func anyTableButton(_ app: XCUIApplication) -> XCUIElement
22+
var all: [Selector] { get }
23+
}
24+
25+
struct WebsiteDataSelectors: WebsiteDataSelectorsSet {
26+
private enum IDs {
27+
static let websiteDataOther = "Website Data"
28+
static let clearAllCell = "ClearAllWebsiteData"
29+
static let clearAllLabel = "Clear All Website Data"
30+
static let showMoreCell = "ShowMoreWebsiteData"
31+
static let exampleLabel = "example.com"
32+
static let circleImageId = "circle"
33+
static let dataManagement = "Data Management"
34+
static let settings = "Settings"
35+
static let doneButton = "Done"
36+
static let exampleUrl = "example.com"
37+
}
38+
39+
let TABLE_WEBSITE_DATA = Selector.tableOtherById(
40+
IDs.websiteDataOther,
41+
description: "Main Website Data table",
42+
groups: ["settings"]
43+
)
44+
45+
let CELL_CLEAR_ALL = Selector.cellById(
46+
IDs.clearAllCell,
47+
description: "Cell 'ClearAllWebsiteData'",
48+
groups: ["settings"]
49+
)
50+
51+
let ALERT_OK_BUTTON = Selector.buttonByLabel(
52+
"OK",
53+
description: "Confirmation button in clear data alert",
54+
groups: ["settings"]
55+
)
56+
57+
let BUTTON_DATA_MANAGEMENT = Selector.buttonByLabel(
58+
IDs.dataManagement,
59+
description: "Back button from Website Data to Data Management screen",
60+
groups: ["settings"]
61+
)
62+
63+
let BUTTON_SETTINGS = Selector.buttonByLabel(
64+
IDs.settings,
65+
description: "Back button to Settings screen",
66+
groups: ["settings"]
67+
)
68+
69+
let BUTTON_DONE = Selector.buttonByLabel(
70+
IDs.doneButton,
71+
description: "Done button to exit Settings",
72+
groups: ["settings"]
73+
)
74+
75+
let CELL_SHOW_MORE = Selector.cellById(
76+
IDs.showMoreCell,
77+
description: "Show more website data cell",
78+
groups: ["settings", "websitedata"]
79+
)
80+
81+
let EXAMPLE_EQUAL = Selector.staticTextByExactLabel(
82+
IDs.exampleLabel,
83+
description: "example.com exact label",
84+
groups: ["settings", "websitedata"]
85+
)
86+
87+
let EXAMPLE_CONTAINS = Selector.staticTextLabelContains(
88+
IDs.exampleLabel,
89+
description: "any staticText containing 'example.com'",
90+
groups: ["settings", "websitedata"]
91+
)
92+
93+
let CIRCLE_IMAGE_ANYWHERE = Selector.imageById(
94+
IDs.circleImageId,
95+
description: "circle image id anywhere",
96+
groups: ["settings", "websitedata"]
97+
)
98+
99+
let STATIC_TEXT_EXAMPLE_IN_CELL = Selector.cellStaticTextLabelContains(
100+
IDs.exampleUrl,
101+
description: "StaticText 'example.com' inside Website Data cell",
102+
groups: ["settings", "websitedata"]
103+
)
104+
105+
func clearAllLabel(in app: XCUIApplication) -> XCUIElement {
106+
app.tables.cells[IDs.clearAllCell].staticTexts[IDs.clearAllLabel]
107+
}
108+
109+
func circleImageInsideCells(_ app: XCUIApplication) -> XCUIElement {
110+
return app.cells.images.matching(identifier: IDs.circleImageId).firstMatch
111+
}
112+
113+
func anyTableButton(_ app: XCUIApplication) -> XCUIElement {
114+
return app.tables.buttons.firstMatch
115+
}
116+
117+
var all: [Selector] {
118+
[
119+
TABLE_WEBSITE_DATA, CELL_CLEAR_ALL, ALERT_OK_BUTTON,
120+
BUTTON_DATA_MANAGEMENT, BUTTON_SETTINGS, BUTTON_DONE,
121+
CELL_SHOW_MORE, EXAMPLE_EQUAL, EXAMPLE_CONTAINS,
122+
CIRCLE_IMAGE_ANYWHERE, STATIC_TEXT_EXAMPLE_IN_CELL
123+
]
124+
}
125+
}

0 commit comments

Comments
 (0)