Skip to content

Commit

Permalink
Update UI tests (#23626)
Browse files Browse the repository at this point in the history
* Update UI tests for iPad

* Fix UITestFlag

* Revert the xctsetplan changes
  • Loading branch information
kean authored Oct 8, 2024
1 parent cfde199 commit 55181d6
Show file tree
Hide file tree
Showing 65 changed files with 617 additions and 604 deletions.
3 changes: 1 addition & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ steps:
context: "UI Tests (iPhone)"

- label: "🔬 :jetpack: UI Tests (iPad)"
command: echo 'noop'
# command: .buildkite/commands/run-ui-tests.sh 'iPad (10th generation) (17.5)'
command: .buildkite/commands/run-ui-tests.sh 'iPad (10th generation) (18.0)'
depends_on: "build_jetpack"
plugins: [$CI_TOOLKIT_PLUGIN]
artifact_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import ScreenObject
import XCTest

public class ActivityLogScreen: ScreenObject {
public let tabBar: TabNavComponent

private let dateRangeButtonGetter: (XCUIApplication) -> XCUIElement = {
$0.buttons["Date Range"].firstMatch
}
Expand All @@ -19,8 +17,6 @@ public class ActivityLogScreen: ScreenObject {
var duration: TimeInterval = 10.0

public init(app: XCUIApplication = XCUIApplication()) throws {
tabBar = try TabNavComponent()

try super.init(
expectedElementGetters: [ dateRangeButtonGetter, activityTypeButtonGetter ],
app: app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public class AztecEditorScreen: ScreenObject {
XCTContext.runActivity(named: "Close the More menu if needed") { (activity) in
let actionSheet = app.sheets.element(boundBy: 0)
if actionSheet.exists {
if XCUIDevice.isPad {
if XCTestCase.isPad {
app.otherElements["PopoverDismissRegion"].tap()
} else {
app.sheets.buttons["Keep Editing"].tap()
Expand All @@ -231,7 +231,7 @@ public class AztecEditorScreen: ScreenObject {
XCTContext.runActivity(named: "Discard any local changes") { (activity) in

let postHasChangesSheet = app.sheets["post-has-changes-alert"]
let discardButton = XCUIDevice.isPad ? postHasChangesSheet.buttons.lastMatch : postHasChangesSheet.buttons.element(boundBy: 1)
let discardButton = XCTestCase.isPad ? postHasChangesSheet.buttons.lastMatch : postHasChangesSheet.buttons.element(boundBy: 1)

if postHasChangesSheet.exists && (discardButton?.exists ?? false) {
Logger.log(message: "Discarding unsaved changes", event: .v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public class BlockEditorScreen: ScreenObject {
public func dismissBloggingRemindersAlertIfNeeded() {
guard setRemindersButton.waitForExistence(timeout: 5) else { return }

if XCUIDevice.isPad {
if XCTestCase.isPad {
app.swipeDown(velocity: .fast)
} else {
let dismissBloggingRemindersAlertButton = app.buttons.element(boundBy: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class LoginCheckMagicLinkScreen: ScreenObject {
return try LoginPasswordScreen()
}

@discardableResult
public func openMagicLoginLink() throws -> MySiteScreen {
openMagicLink()

return try MySiteScreen()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@ public class LoginUsernamePasswordScreen: ScreenObject {
return try MySiteScreen()
}

public func proceedWithSelfHostedSiteAddedFromSitesList(username: String, password: String) throws -> MySitesScreen {
public func proceedWithSelfHosted(username: String, password: String) throws {
fill(username: username, password: password)
return try MySitesScreen()
}

public func proceedWithSelfHosted(username: String, password: String) throws -> MySiteScreen {
fill(username: username, password: password)
return try MySiteScreen()
}

public static func isLoaded() -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ public class PasswordScreen: ScreenObject {

@discardableResult
public func proceedWithValidPassword() throws -> MySiteScreen {
try tryProceed(password: "pw")
tryProceed(password: "pw")
return try MySiteScreen()
}

public func proceedWithInvalidPassword() throws -> Self {
try tryProceed(password: "invalidPswd")

public func proceedWithInvalidPassword() -> Self {
tryProceed(password: "invalidPswd")
return self
}

public func tryProceed(password: String) throws {
public func tryProceed(password: String) {
// A hack to make tests pass for RtL languages.
//
// An unintended side effect of calling passwordTextField.tap() while testing a RtL language is that the
Expand Down
15 changes: 12 additions & 3 deletions Modules/Sources/UITestsFoundation/Screens/MySiteScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class MySiteScreen: ScreenObject {
blogTable.swipeUp(velocity: .fast)
blogDetailsRemoveSiteButton.doubleTap()

let removeButton = XCUIDevice.isPad ? removeSiteAlert : removeSiteButton
let removeButton = XCTestCase.isPad ? removeSiteAlert : removeSiteButton
removeButton.tap()
}

Expand All @@ -156,8 +156,10 @@ public class MySiteScreen: ScreenObject {

@discardableResult
public func goToMoreMenu() throws -> MySiteMoreMenuScreen {
// On iPad, the menu items are already listed on screen, so we don't need to tap More Menu button
if XCUIDevice.isPhone {
if XCTestCase.isPad {
try SidebarNavComponent()
.openSiteMenu()
} else {
moreMenuButton.tap()
}

Expand Down Expand Up @@ -280,4 +282,11 @@ public class MySiteScreen: ScreenObject {
let cardCell = collectionView.cells.containing(.any, identifier: id).firstMatch
app.scrollDownToElement(element: cardCell)
}

@discardableResult
public func goToBlockEditorScreen() throws -> BlockEditorScreen {
try goToCreateSheet()
.goToBlogPost()
return try BlockEditorScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MySitesScreen: ScreenObject {
var mySitesLabel: XCUIElement { mySitesLabelGetter(app) }
var addASiteButton: XCUIElement { plusButtonGetter(app) }

init(app: XCUIApplication = XCUIApplication()) throws {
public init(app: XCUIApplication = XCUIApplication()) throws {
try super.init(
expectedElementGetters: [
mySitesLabelGetter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ScreenObject
import XCTest
import UIKit

public protocol MainNavigationComponent {
func goToReaderScreen() throws -> ReaderScreen
func goToNotificationsScreen() throws -> NotificationsScreen
func goToMeScreen() throws -> MeTabScreen
}

public func makeMainNavigationComponent() throws -> MainNavigationComponent {
if XCTestCase.isPad {
// Assuming the app is used in the fullscreen mode.
return try SidebarNavComponent()
} else {
return try TabNavComponent()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ScreenObject
import XCTest

public class SidebarNavComponent: ScreenObject, MainNavigationComponent {
public init(app: XCUIApplication = XCUIApplication()) throws {
try super.init {
$0.otherElements["root_vc"].firstMatch
}
}

public func goToMeScreen() throws -> MeTabScreen {
try openSidebar().openMeScreen()
}

public func goToReaderScreen() throws -> ReaderScreen {
try openSidebar().openReaderScreen()
}

public func goToNotificationsScreen() throws -> NotificationsScreen {
try openSidebar().openNotificationsScreen()
}

public func openSidebar() throws -> SidebarScreen {
try openSiteMenu().openSidebar()
}

@discardableResult
public func openSiteMenu() throws -> SidebarSiteMenuScreen {
app.buttons["ToggleSidebar"].firstMatch.tap()
return try SidebarSiteMenuScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ScreenObject
import XCTest

/// Represents the main app-wide sidebar.
public class SidebarScreen: ScreenObject {
public init(app: XCUIApplication = XCUIApplication()) throws {
try super.init {
$0.collectionViews["sidebar_list"].firstMatch
}
}

public func openMeScreen() throws -> MeTabScreen {
app.buttons["sidebar_me"].firstMatch.tap()
return try MeTabScreen()
}

public func openReaderScreen() throws -> ReaderScreen {
app.staticTexts["sidebar_reader"].firstMatch.tap()
app.swipeLeft() // Close the sidebar
return try ReaderScreen()
}

public func openNotificationsScreen() throws -> NotificationsScreen {
app.staticTexts["sidebar_notifications"].firstMatch.tap()
return try NotificationsScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ScreenObject
import XCTest

/// Represents the site menu displayed in the supplementary column on iPad.
public class SidebarSiteMenuScreen: ScreenObject {
var navigationBar: XCUIElement {
app.navigationBars["site_menu_navbar"].firstMatch
}

var table: XCUIElement {
app.tables["Blog Details Table"].firstMatch
}

public init(app: XCUIApplication = XCUIApplication()) throws {
try super.init {
$0.navigationBars["site_menu_navbar"].firstMatch
}
}

func openSidebar() throws -> SidebarScreen {
navigationBar.buttons.element(boundBy: 0).tap()
return try SidebarScreen()
}

public func removeSelfHostedSite() {
table.swipeUp(velocity: .fast)
table.cells["BlogDetailsRemoveSiteCell"].tap()
app.alerts.buttons.element(boundBy: 1).tap()
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
import ScreenObject
import XCTest
import UIKit

public class TabNavComponent: ScreenObject {

private static let tabBarGetter: (XCUIApplication) -> XCUIElement = {
$0.tabBars["Main Navigation"]
}

private let mySitesTabButtonGetter: (XCUIApplication) -> XCUIElement = {
$0.tabBars["Main Navigation"].buttons["mySitesTabButton"]
public class TabNavComponent: ScreenObject, MainNavigationComponent {
var mySitesTabButton: XCUIElement {
app.buttons["tabbar_mysites"].firstMatch
}

private let readerTabButtonGetter: (XCUIApplication) -> XCUIElement = {
$0.tabBars["Main Navigation"].buttons["readerTabButton"]
var notificationsTabButton: XCUIElement {
app.buttons["tabbar_notifications"].firstMatch
}

private let notificationsTabButtonGetter: (XCUIApplication) -> XCUIElement = {
$0.tabBars["Main Navigation"].buttons["notificationsTabButton"]
var readerTabButton: XCUIElement {
app.buttons["tabbar_reader"].firstMatch
}

private let meTabButtonGetter: (XCUIApplication) -> XCUIElement = {
$0.tabBars["Main Navigation"].buttons["meTabButton"]
var meTabButton: XCUIElement {
app.buttons["tabbar_me"].firstMatch
}

var meTabButton: XCUIElement { meTabButtonGetter(app) }
var mySitesTabButton: XCUIElement { mySitesTabButtonGetter(app) }
var notificationsTabButton: XCUIElement { notificationsTabButtonGetter(app) }
var readerTabButton: XCUIElement { readerTabButtonGetter(app) }

public init(app: XCUIApplication = XCUIApplication()) throws {
try super.init(
expectedElementGetters: [
mySitesTabButtonGetter,
notificationsTabButtonGetter,
readerTabButtonGetter
],
app: app
)
try super.init {
$0.tabBars["Main Navigation"].firstMatch
}
}

public func goToMeScreen() throws -> MeTabScreen {
Expand Down Expand Up @@ -76,7 +62,6 @@ public class TabNavComponent: ScreenObject {

public func goToNotificationsScreen() throws -> NotificationsScreen {
notificationsTabButton.tap()
try dismissNotificationAlertIfNeeded()
return try NotificationsScreen()
}

Expand Down
Loading

0 comments on commit 55181d6

Please sign in to comment.