Convert UI tests screens to be ScreenObject subclasses – Part 3 of many#17359
Convert UI tests screens to be ScreenObject subclasses – Part 3 of many#17359
ScreenObject subclasses – Part 3 of many#17359Conversation
|
You can trigger an installable build for these changes by visiting CircleCI here. |
|
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
| 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() | ||
| } | ||
| } |
There was a problem hiding this comment.
This is duplicated from the BaseScreen version. Once we'll have no more BaseScreen in the UI tests, it will become the only one in the codebase. It's also something we might want to move to the authentication framework.
| mySiteScreen = TabNavComponent() | ||
| .gotoMySiteScreen() | ||
| mySiteScreen = try TabNavComponent() | ||
| .goToMySiteScreen() |
There was a problem hiding this comment.
Just an indentation fix
|
|
||
| // Get Stats screenshot | ||
| let statsScreen = mySite.gotoStatsScreen() | ||
| let statsScreen = try mySite.goToStatsScreen() |
There was a problem hiding this comment.
There'll be a bunch more of this changes because of the goto to goTo rename. Sorry for the noise.
ScreenObject subclasses – Part 3 of manyScreenObject subclasses – Part 3 of many
pachlava
left a comment
There was a problem hiding this comment.
I executed the UI tests and screenshot generation locally, and both passed. Thanks for doing the code clean-up besides the 'main' task 👍
| static func isLoaded() -> Bool { | ||
| return XCUIApplication().buttons[ElementStringIDs.loginButton].exists | ||
| (try? WelcomeScreen().isLoaded) ?? false | ||
| } |
There was a problem hiding this comment.
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 isLoaded() method for some of the screens, when there's an isLoaded variable in the ScreenObject. After a bit of processing, I realized that this is a shorter way to calculate that property in the runtime, without the need to handle potential error every time.
There was a problem hiding this comment.
Correct.
To be fair, the static approach made sense only in the BaseScreen context, where a calling init on a screen not displayed would fail the test. With ScreenObject, it's less useful. I'd like to remove as many of these as possible.
For example, the following doesn't make much sense anymore:
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:
There was a problem hiding this comment.
Thanks for explaining it, Gio!
See #17221 and #17348.
Regression Notes
Potential unintended areas of impact
N.A.
What I did to test those areas of impact (or what existing automated tests I relied on)
N.A.
What automated tests I added (or what prevented me from doing so)
N.A.
RELEASE-NOTES.txtif necessary. N.A.