Skip to content

Commit 9a96c92

Browse files
authored
[UI Tests] Re-enable media picker tests with support to PHPicker (#21447)
* Add PHPicker Screen Object * Update setFeatureImage() including chooseFromMediaButton * Make chooseFromDevice() return PHPicker Screen Object * Re-enable media picker tests
1 parent 5beef7f commit 9a96c92

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

WordPress/UITests/JetpackUITests.xctestplan

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
"parallelizable" : true,
2424
"skippedTests" : [
2525
"EditorAztecTests",
26-
"EditorGutenbergTests\/testAddGalleryBlock()",
27-
"EditorGutenbergTests\/testAddMediaBlocks()",
28-
"EditorGutenbergTests\/testAddRemoveFeaturedImage()",
29-
"EditorGutenbergTests\/testBasicPostPublishWithCategoryAndTag()",
3026
"LoginTests\/testEmailMagicLinkLogin()",
3127
"SignupTests",
3228
"SignupTests\/testEmailSignup()",

WordPress/UITestsFoundation/Screens/Editor/BlockEditorScreen.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,10 @@ public class BlockEditorScreen: ScreenObject {
392392
.selectMultipleImages(numberOfImages)
393393
}
394394

395-
private func chooseFromDevice() throws -> MediaPickerAlbumScreen {
395+
private func chooseFromDevice() throws -> PHPickerScreen {
396396
chooseFromDeviceButton.tap()
397397

398-
// Allow access to device media
399-
app.tap() // trigger the media permissions alert handler
400-
401-
return try MediaPickerAlbumListScreen()
402-
.selectAlbum(atIndex: 0)
398+
return try PHPickerScreen()
403399
}
404400

405401
private func confirmPost(button: XCUIElement) throws {

WordPress/UITestsFoundation/Screens/Editor/EditorPostSettings.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class EditorPostSettings: ScreenObject {
1111
$0.cells["Categories"]
1212
}
1313

14+
private let chooseFromMediaButtonGetter: (XCUIApplication) -> XCUIElement = {
15+
$0.buttons["Choose from Media"]
16+
}
17+
1418
private let tagsSectionGetter: (XCUIApplication) -> XCUIElement = {
1519
$0.cells["Tags"]
1620
}
@@ -44,6 +48,7 @@ public class EditorPostSettings: ScreenObject {
4448
}
4549

4650
var categoriesSection: XCUIElement { categoriesSectionGetter(app) }
51+
var chooseFromMediaButton: XCUIElement { chooseFromMediaButtonGetter(app) }
4752
var currentFeaturedImage: XCUIElement { currentFeaturedImageGetter(app) }
4853
var dateSelector: XCUIElement { dateSelectorGetter(app) }
4954
var doneButton: XCUIElement { doneButtonGetter(app) }
@@ -96,8 +101,8 @@ public class EditorPostSettings: ScreenObject {
96101

97102
public func setFeaturedImage() throws -> EditorPostSettings {
98103
featuredImageButton.tap()
99-
try MediaPickerAlbumListScreen()
100-
.selectAlbum(atIndex: 0) // Select media library
104+
chooseFromMediaButton.tap()
105+
try MediaPickerAlbumScreen()
101106
.selectImage(atIndex: 0) // Select latest uploaded image
102107

103108
return try EditorPostSettings()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import ScreenObject
2+
import XCTest
3+
4+
public class PHPickerScreen: ScreenObject {
5+
6+
private let addButtonGetter: (XCUIApplication) -> XCUIElement = {
7+
$0.buttons["Add"]
8+
}
9+
10+
private let photosNavigationBarGetter: (XCUIApplication) -> XCUIElement = {
11+
$0.navigationBars["Photos"]
12+
}
13+
14+
private let photosScrollViewGetter: (XCUIApplication) -> XCUIElement = {
15+
$0.otherElements["Photos"].scrollViews.firstMatch
16+
}
17+
18+
var addButton: XCUIElement { addButtonGetter(app) }
19+
var photosNavigationBar: XCUIElement { photosNavigationBarGetter(app) }
20+
var photosScrollView: XCUIElement { photosScrollViewGetter(app) }
21+
22+
public init(app: XCUIApplication = XCUIApplication()) throws {
23+
try super.init(
24+
expectedElementGetter: photosNavigationBarGetter,
25+
app: app
26+
)
27+
}
28+
29+
public func selectImage(atIndex index: Int) {
30+
let selectedImage = photosScrollView.images.element(boundBy: index)
31+
XCTAssertTrue(selectedImage.waitForExistence(timeout: 5), "Selected image did not load")
32+
selectedImage.tap()
33+
}
34+
35+
public func selectMultipleImages(_ numberOfImages: Int) {
36+
var index = 0
37+
while index < numberOfImages {
38+
selectImage(atIndex: index)
39+
index += 1
40+
}
41+
42+
addButton.tap()
43+
}
44+
45+
public static func isLoaded(app: XCUIApplication = XCUIApplication()) -> Bool {
46+
return (try? PHPickerScreen().isLoaded) ?? false
47+
}
48+
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,6 +3462,7 @@
34623462
EA85B7AF2A688AB00096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
34633463
EA85B7B02A688B1C0096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
34643464
EAB10E4027487F5D000DA4C1 /* ReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */; };
3465+
EABE86612A995124004281A8 /* PHPickerScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABE86602A995124004281A8 /* PHPickerScreen.swift */; };
34653466
EAD08D0E29D45E23001A72F9 /* CommentsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD08D0D29D45E23001A72F9 /* CommentsScreen.swift */; };
34663467
EAD2BF4227594DAB00A847BB /* StatsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD2BF4127594DAB00A847BB /* StatsTests.swift */; };
34673468
EB6DF027AF96D801F280E805 /* Pods_WordPressStatsWidgets.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D670B9448DF9991366CF42D /* Pods_WordPressStatsWidgets.framework */; };
@@ -8840,6 +8841,7 @@
88408841
EA78189327596B2F00554DFA /* ContactUsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactUsScreen.swift; sourceTree = "<group>"; };
88418842
EA85B7A92A6860370096E097 /* TestObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
88428843
EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderTests.swift; sourceTree = "<group>"; };
8844+
EABE86602A995124004281A8 /* PHPickerScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PHPickerScreen.swift; sourceTree = "<group>"; };
88438845
EAD08D0D29D45E23001A72F9 /* CommentsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsScreen.swift; sourceTree = "<group>"; };
88448846
EAD2BF4127594DAB00A847BB /* StatsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsTests.swift; sourceTree = "<group>"; };
88458847
EEF80689364FA9CAE10405E8 /* Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressNotificationServiceExtension/Pods-WordPressNotificationServiceExtension.release-alpha.xcconfig"; sourceTree = "<group>"; };
@@ -11221,6 +11223,7 @@
1122111223
children = (
1122211224
CC5218992279CF3B008998CE /* MediaPickerAlbumListScreen.swift */,
1122311225
CC52189B2279D295008998CE /* MediaPickerAlbumScreen.swift */,
11226+
EABE86602A995124004281A8 /* PHPickerScreen.swift */,
1122411227
);
1122511228
path = Media;
1122611229
sourceTree = "<group>";
@@ -22862,6 +22865,7 @@
2286222865
3FE39A3B26F837FF006E2B3A /* PostsScreen.swift in Sources */,
2286322866
3F2F855C26FAF227000FCDA5 /* LinkOrPasswordScreen.swift in Sources */,
2286422867
3F2F855226FAF227000FCDA5 /* SignupCheckMagicLinkScreen.swift in Sources */,
22868+
EABE86612A995124004281A8 /* PHPickerScreen.swift in Sources */,
2286522869
3FE39A4026F8386A006E2B3A /* SiteSettingsScreen.swift in Sources */,
2286622870
D8E7529B2A29DC4C00E73B2D /* XCUIApplication+ScrollDownToElement.swift in Sources */,
2286722871
3FE39A3526F83701006E2B3A /* LoginEpilogueScreen.swift in Sources */,

0 commit comments

Comments
 (0)