Skip to content

Commit

Permalink
Convert remaining UI tests screens to ScreenObject subclasses (#17641)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio authored Dec 9, 2021
2 parents 0a231b6 + b5ccadd commit bd211eb
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 190 deletions.
88 changes: 0 additions & 88 deletions WordPress/UITestsFoundation/BaseScreen.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class LoginCheckMagicLinkScreen: ScreenObject {
return try LoginPasswordScreen()
}

public func openMagicLoginLink() -> LoginEpilogueScreen {
public func openMagicLoginLink() throws -> LoginEpilogueScreen {
openMagicLink()

return LoginEpilogueScreen()
return try LoginEpilogueScreen()
}

public static func isLoaded() -> Bool {
Expand Down
38 changes: 15 additions & 23 deletions WordPress/UITestsFoundation/Screens/Login/LoginEpilogueScreen.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import ScreenObject
import XCTest

private struct ElementStringIDs {
static let usernameField = "login-epilogue-username-label"
static let siteUrlField = "siteUrl"
static let loginEpilogueTable = "login-epilogue-table"
}
public class LoginEpilogueScreen: ScreenObject {

public class LoginEpilogueScreen: BaseScreen {
let usernameField: XCUIElement
let siteUrlField: XCUIElement
let loginEpilogueTable: XCUIElement
private let loginEpilogueTableGetter: (XCUIApplication) -> XCUIElement = {
$0.tables["login-epilogue-table"]
}

init() {
let app = XCUIApplication()
usernameField = app.staticTexts[ElementStringIDs.usernameField]
siteUrlField = app.staticTexts[ElementStringIDs.siteUrlField]
loginEpilogueTable = app.tables[ElementStringIDs.loginEpilogueTable]
var loginEpilogueTable: XCUIElement { loginEpilogueTableGetter(app) }

super.init(element: loginEpilogueTable)
init(app: XCUIApplication = XCUIApplication()) throws {
try super.init(expectedElementGetters: [loginEpilogueTableGetter], app: app)
}

public func continueWithSelectedSite() throws -> MySiteScreen {
Expand All @@ -41,12 +34,12 @@ public class LoginEpilogueScreen: BaseScreen {
public func verifyEpilogueDisplays(username: String? = nil, siteUrl: String) -> LoginEpilogueScreen {
if var expectedUsername = username {
expectedUsername = "@\(expectedUsername)"
let actualUsername = usernameField.label
let actualUsername = app.staticTexts["login-epilogue-username-label"].label
XCTAssertEqual(expectedUsername, actualUsername, "Username displayed is \(actualUsername) but should be \(expectedUsername)")
}

let expectedSiteUrl = getDisplayUrl(for: siteUrl)
let actualSiteUrl = siteUrlField.firstMatch.label
let actualSiteUrl = app.staticTexts["siteUrl"].firstMatch.label
XCTAssertEqual(expectedSiteUrl, actualSiteUrl, "Site URL displayed is \(actualSiteUrl) but should be \(expectedSiteUrl)")

return self
Expand All @@ -62,12 +55,11 @@ public class LoginEpilogueScreen: BaseScreen {
}

private func dismissQuickStartPromptIfNeeded() throws {
try XCTContext.runActivity(named: "Dismiss quick start prompt if needed.") { (activity) in
if QuickStartPromptScreen.isLoaded() {
Logger.log(message: "Dismising quick start prompt...", event: .i)
_ = try QuickStartPromptScreen().selectNoThanks()
return
}
try XCTContext.runActivity(named: "Dismiss quick start prompt if needed.") { _ in
guard QuickStartPromptScreen.isLoaded() else { return }

Logger.log(message: "Dismising quick start prompt...", event: .i)
_ = try QuickStartPromptScreen().selectNoThanks()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class LoginPasswordScreen: ScreenObject {
try super.init(expectedElementGetters: [passwordTextFieldGetter], app: app)
}

func proceedWith(password: String) -> LoginEpilogueScreen {
func proceedWith(password: String) throws -> LoginEpilogueScreen {
_ = tryProceed(password: password)

return LoginEpilogueScreen()
return try LoginEpilogueScreen()
}

func tryProceed(password: String) -> LoginPasswordScreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public class LoginUsernamePasswordScreen: ScreenObject {
)
}

public func proceedWith(username: String, password: String) -> LoginEpilogueScreen {
public func proceedWith(username: String, password: String) throws -> LoginEpilogueScreen {
fill(username: username, password: password)

return LoginEpilogueScreen()
return try LoginEpilogueScreen()
}

public func proceedWithSelfHostedSiteAddedFromSitesList(username: String, password: String) throws -> MySitesScreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class PasswordScreen: ScreenObject {
)
}

public func proceedWith(password: String) -> LoginEpilogueScreen {
public func proceedWith(password: String) throws -> LoginEpilogueScreen {
_ = tryProceed(password: password)

return LoginEpilogueScreen()
return try LoginEpilogueScreen()
}

public func tryProceed(password: String) -> PasswordScreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class SignupCheckMagicLinkScreen: ScreenObject {
)
}

public func openMagicSignupLink() -> SignupEpilogueScreen {
public func openMagicSignupLink() throws -> SignupEpilogueScreen {
openMagicLink()

return SignupEpilogueScreen()
return try SignupEpilogueScreen()
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import ScreenObject
import XCTest

private struct ElementStringIDs {
static let newAccountHeader = "New Account Header"
static let displayNameField = "Display Name Field"
static let usernameField = "Username Field"
static let passwordField = "Password Field"
// This is the Done button on the Login Epilogue
static let doneButton = "Done"
// This is the Done button on the Signup Epilogue
static let continueButton = "Done Button"
}
public class SignupEpilogueScreen: ScreenObject {

public class SignupEpilogueScreen: BaseScreen {
let newAccountHeader: XCUIElement
let displayNameField: XCUIElement
let usernameField: XCUIElement
let passwordField: XCUIElement
let doneButton: XCUIElement
let continueButton: XCUIElement

init() {
let app = XCUIApplication()
newAccountHeader = app.staticTexts[ElementStringIDs.newAccountHeader]
displayNameField = app.textFields[ElementStringIDs.displayNameField]
usernameField = app.textFields[ElementStringIDs.usernameField]
passwordField = app.secureTextFields[ElementStringIDs.passwordField]
doneButton = app.buttons[ElementStringIDs.doneButton]
continueButton = app.buttons[ElementStringIDs.continueButton]

super.init(element: newAccountHeader)
init(app: XCUIApplication = XCUIApplication()) throws {
try super.init(
expectedElementGetters: [ { $0.staticTexts["New Account Header"] } ],
app: app
)
}

public func verifyEpilogueContains(username: String, displayName: String) -> SignupEpilogueScreen {
let actualUsername = usernameField.value as! String
let actualDisplayName = displayNameField.value as! String
let actualUsername = app.textFields["Username Field"].value as! String
let actualDisplayName = app.textFields["Display Name Field"].value as! String

XCTAssertEqual(username, actualUsername, "Username is set to \(actualUsername) but should be \(username)")
XCTAssertEqual(displayName, actualDisplayName, "Display name is set to \(actualDisplayName) but should be \(displayName)")
Expand All @@ -42,15 +21,16 @@ public class SignupEpilogueScreen: BaseScreen {
}

public func setPassword(_ password: String) -> SignupEpilogueScreen {
let passwordField = app.secureTextFields["Password Field"]
passwordField.tap()
passwordField.typeText(password)
doneButton.tap()
app.buttons["Done"].tap()

return self
}

public func continueWithSignup() throws -> MySiteScreen {
continueButton.tap()
app.buttons["Done Button"].tap()

return try MySiteScreen()
}
Expand Down
4 changes: 0 additions & 4 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@
3FA6405B2670CCD40064401E /* UITestsFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FA640592670CCD40064401E /* UITestsFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
3FA640612670CE210064401E /* UITestsFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA640572670CCD40064401E /* UITestsFoundation.framework */; };
3FA640622670CE260064401E /* UITestsFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA640572670CCD40064401E /* UITestsFoundation.framework */; };
3FA640642670CED80064401E /* BaseScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA640632670CED80064401E /* BaseScreen.swift */; };
3FA640662670CEFF0064401E /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA640652670CEFE0064401E /* XCTest.framework */; };
3FA640672670D1290064401E /* UITestsFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA640572670CCD40064401E /* UITestsFoundation.framework */; };
3FAA18CC25797B85002B1911 /* UnconfiguredView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FAA18CB25797B85002B1911 /* UnconfiguredView.swift */; };
Expand Down Expand Up @@ -5201,7 +5200,6 @@
3FA640572670CCD40064401E /* UITestsFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UITestsFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3FA640592670CCD40064401E /* UITestsFoundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UITestsFoundation.h; sourceTree = "<group>"; };
3FA6405A2670CCD40064401E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3FA640632670CED80064401E /* BaseScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseScreen.swift; sourceTree = "<group>"; };
3FA640652670CEFE0064401E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
3FAA18CB25797B85002B1911 /* UnconfiguredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnconfiguredView.swift; sourceTree = "<group>"; };
3FAF9CC126D01CFE00268EA2 /* DomainsDashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainsDashboardView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9381,7 +9379,6 @@
3FA640582670CCD40064401E /* UITestsFoundation */ = {
isa = PBXGroup;
children = (
3FA640632670CED80064401E /* BaseScreen.swift */,
3F762E9626784BED0088CD45 /* FancyAlertComponent.swift */,
3F762E9C26784DB40088CD45 /* Globals.swift */,
3FA6405A2670CCD40064401E /* Info.plist */,
Expand Down Expand Up @@ -18484,7 +18481,6 @@
3F2F855826FAF227000FCDA5 /* SignupEpilogueScreen.swift in Sources */,
3F2F855726FAF227000FCDA5 /* WelcomeScreenSignupComponent.swift in Sources */,
3F2F855326FAF227000FCDA5 /* EditorPostSettings.swift in Sources */,
3FA640642670CED80064401E /* BaseScreen.swift in Sources */,
3F2F856026FAF235000FCDA5 /* NotificationsScreen.swift in Sources */,
3F2F854026FAE9DC000FCDA5 /* BlockEditorScreen.swift in Sources */,
3FB5C2B327059AC8007D0ECE /* XCUIElement+Scroll.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ class WordPressScreenshotGeneration: XCTestCase {
}
}

extension BaseScreen {
@discardableResult
func thenTakeScreenshot(_ index: Int, named title: String) -> Self {
let mode = XCUIDevice.inDarkMode ? "dark" : "light"
let filename = "\(index)-\(mode)-\(title)"

snapshot(filename)

return self
}
}

extension ScreenObject {

@discardableResult
Expand Down
21 changes: 0 additions & 21 deletions WordPress/WordPressUITests/Screens/BaseScreen.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
import UITestsFoundation
import XCTest

extension BaseScreen {

class func waitForLoadingIndicatorToDisappear(within timeout: TimeInterval) {
let networkLoadingIndicator = XCUIApplication().otherElements.deviceStatusBars.networkLoadingIndicators.element
let networkLoadingIndicatorDisappeared = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: networkLoadingIndicator)
_ = XCTWaiter.wait(for: [networkLoadingIndicatorDisappeared], timeout: timeout)
}

func tapStatusBarToScrollToTop() {
// A hack to work around there being no status bar – just tap the appropriate spot on the navigation bar
XCUIApplication().navigationBars.allElementsBoundByIndex.forEach {
$0.coordinate(withNormalizedOffset: CGVector(dx: 20, dy: -20)).tap()
}
}

// Pops the navigation stack, returning to the item above the current one
func pop() {
navBackButton.tap()
}
}

private extension XCUIElementAttributes {
var isNetworkLoadingIndicator: Bool {
if hasAllowListedIdentifier { return false }
Expand Down

0 comments on commit bd211eb

Please sign in to comment.