-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Convert UI tests screens to be ScreenObject subclasses – Part 4 of many
#17360
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ea2677
Convert `LoginEmailScreen` to be a `ScreenObject` subclass
mokagio 2f06481
Convert `LoginUsernamePasswordScreen` to be a `ScreenObject` subclass
mokagio 66a49ff
Convert `ReaderScreen` to be a `ScreenObject` subclass
mokagio a6acf80
Handle notifications alert in Reader screen scenario during UI tests
mokagio cdd1e92
Extract logic to scroll an element in dedicated extension
mokagio 9684ef1
Convert `PostsScreen` to be a `ScreenObject` subclass
mokagio db2a044
Convert `MediaPickerAlbumListScreen` to be a `ScreenObject` subclass
mokagio b7a7f32
Convert `MediaPickerAlbumScreen` to be a `ScreenObject` subclass
mokagio a3a3c03
Convert `NotificationsScreen` to be a `ScreenObject` subclass
mokagio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 14 additions & 10 deletions
24
WordPress/UITestsFoundation/Screens/Media/MediaPickerAlbumListScreen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,28 @@ | ||
| import ScreenObject | ||
| import XCTest | ||
|
|
||
| public class MediaPickerAlbumListScreen: BaseScreen { | ||
| let albumList: XCUIElement | ||
| public class MediaPickerAlbumListScreen: ScreenObject { | ||
|
|
||
| public init() { | ||
| let app = XCUIApplication() | ||
| albumList = app.tables["AlbumTable"] | ||
| private let albumListGetter: (XCUIApplication) -> XCUIElement = { | ||
| $0.tables["AlbumTable"] | ||
| } | ||
|
|
||
| super.init(element: albumList) | ||
| public init(app: XCUIApplication = XCUIApplication()) throws { | ||
| try super.init( | ||
| expectedElementGetter: albumListGetter, | ||
| app: app | ||
| ) | ||
| } | ||
|
|
||
| public func selectAlbum(atIndex index: Int) -> MediaPickerAlbumScreen { | ||
| let selectedAlbum = albumList.cells.element(boundBy: index) | ||
| public func selectAlbum(atIndex index: Int) throws -> MediaPickerAlbumScreen { | ||
| let selectedAlbum = albumListGetter(app).cells.element(boundBy: index) | ||
| XCTAssertTrue(selectedAlbum.waitForExistence(timeout: 5), "Selected album did not load") | ||
| selectedAlbum.tap() | ||
|
|
||
| return MediaPickerAlbumScreen() | ||
| return try MediaPickerAlbumScreen() | ||
| } | ||
|
|
||
| public static func isLoaded() -> Bool { | ||
| return XCUIApplication().tables["AlbumTable"].exists | ||
| (try? MediaPickerAlbumListScreen().isLoaded) ?? false | ||
| } | ||
| } |
26 changes: 12 additions & 14 deletions
26
WordPress/UITestsFoundation/Screens/Media/MediaPickerAlbumScreen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,32 @@ | ||
| import ScreenObject | ||
| import XCTest | ||
|
|
||
| public class MediaPickerAlbumScreen: BaseScreen { | ||
| let mediaCollection: XCUIElement | ||
| let insertButton: XCUIElement | ||
|
|
||
| public init() { | ||
| let app = XCUIApplication() | ||
| mediaCollection = app.collectionViews["MediaCollection"] | ||
| insertButton = app.buttons["SelectedActionButton"] | ||
| public class MediaPickerAlbumScreen: ScreenObject { | ||
| let mediaCollectionGetter: (XCUIApplication) -> XCUIElement = { | ||
| $0.collectionViews["MediaCollection"] | ||
| } | ||
|
|
||
| super.init(element: mediaCollection) | ||
| public init(app: XCUIApplication = XCUIApplication()) throws { | ||
| try super.init(expectedElementGetters: [mediaCollectionGetter], app: app) | ||
| } | ||
|
|
||
| public func selectImage(atIndex index: Int) { | ||
| let selectedImage = mediaCollection.cells.element(boundBy: index) | ||
| let selectedImage = mediaCollectionGetter(app).cells.element(boundBy: index) | ||
| XCTAssertTrue(selectedImage.waitForExistence(timeout: 5), "Selected image did not load") | ||
| selectedImage.tap() | ||
| } | ||
|
|
||
| func insertSelectedImage() { | ||
| insertButton.tap() | ||
| app.buttons["SelectedActionButton"].tap() | ||
| } | ||
|
|
||
| public static func isLoaded() -> Bool { | ||
| public static func isLoaded(app: XCUIApplication = XCUIApplication()) -> Bool { | ||
| // Check if the media picker is loaded as a component within the editor | ||
| // and only return true if the media picker is a full screen | ||
| if XCUIApplication().navigationBars["Azctec Editor Navigation Bar"].exists { | ||
| if app.navigationBars["Azctec Editor Navigation Bar"].exists { | ||
| return false | ||
| } | ||
|
|
||
| return XCUIApplication().collectionViews["MediaCollection"].exists | ||
| return (try? MediaPickerAlbumScreen().isLoaded) ?? false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You might notice that this code is part of
BaseScreen, which this train of work aims to remove.This change here moved the logic to a dedicated extension (feb932e) so that both
BaseScreenandScreenObjectcould share it in the context of this project.Better than copy-pasting, in particular because this code is fit to live in the XCUITestHelpers project.