Stabilize iOS UI test foundation and fix flaky suites
This commit is contained in:
@@ -13,45 +13,47 @@ struct CustomizeScreen {
|
||||
// MARK: - Theme Mode Buttons
|
||||
|
||||
func themeButton(named name: String) -> XCUIElement {
|
||||
app.buttons["customize_theme_\(name.lowercased())"]
|
||||
app.buttons[UITestID.Customize.themeButton(name)]
|
||||
}
|
||||
|
||||
// MARK: - Voting Layout Buttons
|
||||
|
||||
func votingLayoutButton(named name: String) -> XCUIElement {
|
||||
app.buttons["customize_voting_\(name.lowercased())"]
|
||||
app.buttons[UITestID.Customize.votingLayoutButton(name)]
|
||||
}
|
||||
|
||||
// MARK: - Day View Style Buttons
|
||||
|
||||
func dayViewStyleButton(named name: String) -> XCUIElement {
|
||||
app.buttons["customize_daystyle_\(name.lowercased())"]
|
||||
app.buttons[UITestID.Customize.dayStyleButton(name)]
|
||||
}
|
||||
|
||||
func iconPackButton(named name: String) -> XCUIElement {
|
||||
app.buttons[UITestID.Customize.iconPackButton(name)]
|
||||
}
|
||||
|
||||
func appThemeCard(named name: String) -> XCUIElement {
|
||||
app.element(UITestID.Customize.appThemeCard(name))
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
func selectTheme(_ name: String) {
|
||||
let button = themeButton(named: name)
|
||||
_ = button.waitForExistence(timeout: 5)
|
||||
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
tapHorizontallyScrollableButton(themeButton(named: name))
|
||||
}
|
||||
|
||||
func selectVotingLayout(_ name: String) {
|
||||
let button = votingLayoutButton(named: name)
|
||||
if button.exists && !button.isHittable {
|
||||
app.swipeLeft()
|
||||
}
|
||||
_ = button.waitForExistence(timeout: 5)
|
||||
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
tapHorizontallyScrollableButton(votingLayoutButton(named: name))
|
||||
}
|
||||
|
||||
func selectDayViewStyle(_ name: String) {
|
||||
let button = dayViewStyleButton(named: name)
|
||||
if button.exists && !button.isHittable {
|
||||
app.swipeLeft()
|
||||
}
|
||||
_ = button.waitForExistence(timeout: 5)
|
||||
button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
tapHorizontallyScrollableButton(dayViewStyleButton(named: name))
|
||||
}
|
||||
|
||||
func selectIconPack(_ name: String) {
|
||||
let button = iconPackButton(named: name)
|
||||
_ = app.swipeUntilExists(button, direction: .up, maxSwipes: 6)
|
||||
button.tapWhenReady(timeout: 5)
|
||||
}
|
||||
|
||||
// MARK: - Assertions
|
||||
@@ -63,4 +65,42 @@ struct CustomizeScreen {
|
||||
file: file, line: line
|
||||
)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func openThemePicker(file: StaticString = #file, line: UInt = #line) -> Bool {
|
||||
let browseButton = app.element(UITestID.Settings.browseThemesButton)
|
||||
guard browseButton.waitForExistence(timeout: 5) else {
|
||||
XCTFail("Browse Themes button should exist", file: file, line: line)
|
||||
return false
|
||||
}
|
||||
browseButton.tapWhenReady(timeout: 5, file: file, line: line)
|
||||
|
||||
let firstCard = appThemeCard(named: "Zen Garden")
|
||||
return firstCard.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func tapHorizontallyScrollableButton(_ button: XCUIElement) {
|
||||
if button.waitForExistence(timeout: 1) {
|
||||
button.tapWhenReady(timeout: 3)
|
||||
return
|
||||
}
|
||||
|
||||
for _ in 0..<6 {
|
||||
app.swipeLeft()
|
||||
if button.waitForExistence(timeout: 1) {
|
||||
button.tapWhenReady(timeout: 3)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _ in 0..<6 {
|
||||
app.swipeRight()
|
||||
if button.waitForExistence(timeout: 1) {
|
||||
button.tapWhenReady(timeout: 3)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user