-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Convert UI tests screens to be ScreenObject subclasses – Part 3 of many
#17359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6f78d27
300b141
013c4bc
96e01ee
5348008
c462636
09d3e75
4f8161d
c354057
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,27 @@ extension ScreenObject { | |
| public func pop() { | ||
| navBackButton.tap() | ||
| } | ||
|
|
||
| public func openMagicLink() { | ||
| XCTContext.runActivity(named: "Open magic link in Safari") { activity in | ||
| let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari") | ||
| safari.launch() | ||
|
|
||
| // Select the URL bar when Safari opens | ||
| let urlBar = safari.textFields["URL"] | ||
| if !urlBar.waitForExistence(timeout: 5) { | ||
| safari.buttons["URL"].tap() | ||
| } | ||
|
|
||
| // Follow the magic link | ||
| var magicLinkComponents = URLComponents(url: WireMock.URL(), resolvingAgainstBaseURL: false)! | ||
| magicLinkComponents.path = "/magic-link" | ||
| magicLinkComponents.queryItems = [URLQueryItem(name: "scheme", value: "wpdebug")] | ||
|
|
||
| urlBar.typeText("\(magicLinkComponents.url!.absoluteString)\n") | ||
|
|
||
| // Accept the prompt to open the deep link | ||
| safari.scrollViews.element(boundBy: 0).buttons.element(boundBy: 1).tap() | ||
| } | ||
| } | ||
|
Comment on lines
+17
to
+38
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated from the |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,21 +1,23 @@ | ||||||||||||||||||||||
| import ScreenObject | ||||||||||||||||||||||
| import XCTest | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // TODO: remove when unifiedAuth is permanent. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private struct ElementStringIDs { | ||||||||||||||||||||||
| static let loginButton = "Prologue Log In Button" | ||||||||||||||||||||||
| static let signupButton = "Prologue Signup Button" | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| public class WelcomeScreen: ScreenObject { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private let logInButtonGetter: (XCUIApplication) -> XCUIElement = { | ||||||||||||||||||||||
| $0.buttons["Prologue Log In Button"] | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public class WelcomeScreen: BaseScreen { | ||||||||||||||||||||||
| let logInButton: XCUIElement | ||||||||||||||||||||||
| let signupButton: XCUIElement | ||||||||||||||||||||||
| private let signupButtonGetter: (XCUIApplication) -> XCUIElement = { | ||||||||||||||||||||||
| $0.buttons["Prologue Signup Button"] | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public init() { | ||||||||||||||||||||||
| logInButton = XCUIApplication().buttons[ElementStringIDs.loginButton] | ||||||||||||||||||||||
| signupButton = XCUIApplication().buttons[ElementStringIDs.signupButton] | ||||||||||||||||||||||
| var signupButton: XCUIElement { signupButtonGetter(app) } | ||||||||||||||||||||||
| var logInButton: XCUIElement { logInButtonGetter(app) } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| super.init(element: logInButton) | ||||||||||||||||||||||
| public init(app: XCUIApplication = XCUIApplication()) throws { | ||||||||||||||||||||||
| try super.init(expectedElementGetters: [logInButtonGetter, signupButtonGetter], app: app) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public func selectSignup() throws -> WelcomeScreenSignupComponent { | ||||||||||||||||||||||
|
|
@@ -31,6 +33,6 @@ public class WelcomeScreen: BaseScreen { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static func isLoaded() -> Bool { | ||||||||||||||||||||||
| return XCUIApplication().buttons[ElementStringIDs.loginButton].exists | ||||||||||||||||||||||
| (try? WelcomeScreen().isLoaded) ?? false | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
35
to
37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is the same in previous PRs, but for some reason it caught my eye only now. To be honest, I spent some time not understanding the reason for having an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. To be fair, the For example, the following doesn't make much sense anymore: WordPress-iOS/WordPress/UITestsFoundation/Screens/Editor/BlockEditorScreen.swift Lines 141 to 147 in b6d9650
We could replace it with something like: guard let alert = FancyAlertComponent() else {
publishNowButton.tap()
return
}
alert.acceptAlert()On the other hand, this does. Since we don't access any of those screen directly, it's handy to call a method on the type:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaining it, Gio! |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,30 @@ | ||
| import ScreenObject | ||
| import XCTest | ||
|
|
||
| // TODO: remove when unifiedAuth is permanent. | ||
|
|
||
| private struct ElementStringIDs { | ||
| static let emailTextField = "Signup Email Address" | ||
| static let nextButton = "Signup Email Next Button" | ||
| } | ||
| public class SignupEmailScreen: ScreenObject { | ||
|
|
||
| private let emailTextFieldGetter: (XCUIApplication) -> XCUIElement = { | ||
| $0.textFields["Signup Email Address"] | ||
| } | ||
|
|
||
| public class SignupEmailScreen: BaseScreen { | ||
| let emailTextField: XCUIElement | ||
| let nextButton: XCUIElement | ||
| private let nextButtonGetter: (XCUIApplication) -> XCUIElement = { | ||
| $0.buttons["Signup Email Next Button"] | ||
| } | ||
|
|
||
| init() { | ||
| let app = XCUIApplication() | ||
| emailTextField = app.textFields[ElementStringIDs.emailTextField] | ||
| nextButton = app.buttons[ElementStringIDs.nextButton] | ||
| var emailTextField: XCUIElement { emailTextFieldGetter(app) } | ||
| var nextButton: XCUIElement { nextButtonGetter(app) } | ||
|
|
||
| super.init(element: emailTextField) | ||
| init(app: XCUIApplication = XCUIApplication()) throws { | ||
| try super.init(expectedElementGetters: [emailTextFieldGetter, nextButtonGetter], app: app) | ||
| } | ||
|
|
||
| public func proceedWith(email: String) -> SignupCheckMagicLinkScreen { | ||
| public func proceedWith(email: String) throws -> SignupCheckMagicLinkScreen { | ||
| emailTextField.tap() | ||
| emailTextField.typeText(email) | ||
| nextButton.tap() | ||
|
|
||
| return SignupCheckMagicLinkScreen() | ||
| return try SignupCheckMagicLinkScreen() | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There'll be a bunch more of this changes because of the
gototogoTorename. Sorry for the noise.