Skip to content

Commit c767bb9

Browse files
authored
Merge pull request #21414 from wordpress-mobile/ui-tests-improve-scheduled-post-test
Move post publish notice interaction to BlockEditorScreen
2 parents ac41d5a + 0af55e8 commit c767bb9

File tree

5 files changed

+77
-68
lines changed

5 files changed

+77
-68
lines changed

WordPress/UITests/Tests/EditorGutenbergTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class EditorGutenbergTests: XCTestCase {
2929
.enterTextInTitle(text: postTitle)
3030
.addParagraphBlock(withText: postContent)
3131
.verifyContentStructure(blocks: 1, words: postContent.components(separatedBy: " ").count, characters: postContent.count)
32-
.publish()
33-
.viewPublishedPost(withTitle: postTitle)
32+
.postAndViewEpilogue(action: .publish)
3433
.verifyEpilogueDisplays(postTitle: postTitle, siteAddress: WPUITestCredentials.testWPcomPaidSite)
3534
.tapDone()
3635
}
@@ -48,8 +47,7 @@ class EditorGutenbergTests: XCTestCase {
4847
.selectCategory(name: category)
4948
.addTag(name: tag)
5049
.closePostSettings()
51-
.publish()
52-
.viewPublishedPost(withTitle: postTitle)
50+
.postAndViewEpilogue(action: .publish)
5351
.verifyEpilogueDisplays(postTitle: postTitle, siteAddress: WPUITestCredentials.testWPcomPaidSite)
5452
.tapDone()
5553
}

WordPress/UITests/Tests/PostTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class PostTests: XCTestCase {
3131
.updatePublishDateToFutureDate()
3232
.closePublishDateSelector()
3333
.closePostSettings()
34-
.schedulePost()
35-
.viewPublishedPost(withTitle: postTitle)
36-
.verifyEpilogueDisplays(postTitle: postTitle, siteAddress: WPUITestCredentials.testWPcomSiteForScheduledPost)
37-
.tapDone()
34+
.post(action: .schedule)
35+
36+
try MySiteScreen()
37+
.goToPostsScreen()
38+
.showOnly(.scheduled)
39+
.verifyPostExists(withTitle: postTitle)
3840
}
3941
}

WordPress/UITestsFoundation/Screens/Editor/BlockEditorScreen.swift

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,88 @@ import XCUITestHelpers
44

55
public class BlockEditorScreen: ScreenObject {
66

7-
private let editorCloseButtonGetter: (XCUIApplication) -> XCUIElement = {
8-
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Close"]
9-
}
10-
11-
private let undoButtonGetter: (XCUIApplication) -> XCUIElement = {
12-
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Undo"]
13-
}
14-
15-
private let redoButtonGetter: (XCUIApplication) -> XCUIElement = {
16-
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Redo"]
17-
}
18-
197
private let addBlockButtonGetter: (XCUIApplication) -> XCUIElement = {
208
$0.buttons["add-block-button"]
219
}
2210

23-
private let moreButtonGetter: (XCUIApplication) -> XCUIElement = {
24-
$0.buttons["more_post_options"]
11+
private let applyButtonGetter: (XCUIApplication) -> XCUIElement = {
12+
$0.buttons["Apply"]
2513
}
2614

27-
private let insertFromUrlButtonGetter: (XCUIApplication) -> XCUIElement = {
28-
$0.buttons["Insert from URL"]
15+
private let chooseFromDeviceButtonGetter: (XCUIApplication) -> XCUIElement = {
16+
$0.buttons["Choose from device"]
2917
}
3018

31-
private let applyButtonGetter: (XCUIApplication) -> XCUIElement = {
32-
$0.buttons["Apply"]
19+
private let closeButtonGetter: (XCUIApplication) -> XCUIElement = {
20+
$0.buttons["Close"]
3321
}
3422

3523
private let discardButtonGetter: (XCUIApplication) -> XCUIElement = {
3624
$0.buttons["Discard"]
3725
}
3826

39-
private let firstParagraphBlockGetter: (XCUIApplication) -> XCUIElement = {
40-
$0.otherElements["Paragraph Block. Row 1. Empty"]
27+
private let dismissPopoverRegionGetter: (XCUIApplication) -> XCUIElement = {
28+
$0.otherElements["PopoverDismissRegion"]
4129
}
4230

43-
private let postTitleViewGetter: (XCUIApplication) -> XCUIElement = {
44-
$0.otherElements["Post title. Empty"]
31+
private let editorCloseButtonGetter: (XCUIApplication) -> XCUIElement = {
32+
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Close"]
4533
}
4634

4735
private let editorNavigationBarGetter: (XCUIApplication) -> XCUIElement = {
4836
$0.navigationBars["Gutenberg Editor Navigation Bar"]
4937
}
5038

51-
private let closeButtonGetter: (XCUIApplication) -> XCUIElement = {
52-
$0.buttons["Close"]
39+
private let firstParagraphBlockGetter: (XCUIApplication) -> XCUIElement = {
40+
$0.otherElements["Paragraph Block. Row 1. Empty"]
5341
}
5442

55-
private let dismissPopoverRegionGetter: (XCUIApplication) -> XCUIElement = {
56-
$0.otherElements["PopoverDismissRegion"]
43+
private let fullScreenImageGetter: (XCUIApplication) -> XCUIElement = {
44+
$0.images["Fullscreen view of image. Double tap to dismiss"]
45+
}
46+
47+
private let insertFromUrlButtonGetter: (XCUIApplication) -> XCUIElement = {
48+
$0.buttons["Insert from URL"]
5749
}
5850

5951
private let keepEditingButtonGetter: (XCUIApplication) -> XCUIElement = {
6052
$0.buttons["Keep Editing"]
6153
}
6254

55+
private let moreButtonGetter: (XCUIApplication) -> XCUIElement = {
56+
$0.buttons["more_post_options"]
57+
}
58+
59+
private let noticeViewButtonGetter: (XCUIApplication) -> XCUIElement = {
60+
$0.buttons["View"]
61+
}
62+
63+
private let noticeViewTitleGetter: (XCUIApplication) -> XCUIElement = {
64+
$0.otherElements["notice_title_and_message"]
65+
}
66+
6367
private let postSettingsButtonGetter: (XCUIApplication) -> XCUIElement = {
6468
$0.buttons["Post Settings"]
6569
}
6670

67-
private let switchToHTMLModeButtonGetter: (XCUIApplication) -> XCUIElement = {
68-
$0.buttons["Switch to HTML Mode"]
71+
private let postTitleViewGetter: (XCUIApplication) -> XCUIElement = {
72+
$0.otherElements["Post title. Empty"]
6973
}
7074

71-
private let chooseFromDeviceButtonGetter: (XCUIApplication) -> XCUIElement = {
72-
$0.buttons["Choose from device"]
75+
private let redoButtonGetter: (XCUIApplication) -> XCUIElement = {
76+
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Redo"]
7377
}
7478

7579
private let setRemindersButtonGetter: (XCUIApplication) -> XCUIElement = {
7680
$0.buttons["Set reminders"]
7781
}
7882

79-
private let fullScreenImageGetter: (XCUIApplication) -> XCUIElement = {
80-
$0.images["Fullscreen view of image. Double tap to dismiss"]
83+
private let switchToHTMLModeButtonGetter: (XCUIApplication) -> XCUIElement = {
84+
$0.buttons["Switch to HTML Mode"]
85+
}
86+
87+
private let undoButtonGetter: (XCUIApplication) -> XCUIElement = {
88+
$0.navigationBars["Gutenberg Editor Navigation Bar"].buttons["Undo"]
8189
}
8290

8391
private let unsavedChangesLabelGetter: (XCUIApplication) -> XCUIElement = {
@@ -97,11 +105,13 @@ public class BlockEditorScreen: ScreenObject {
97105
var insertFromUrlButton: XCUIElement { insertFromUrlButtonGetter(app) }
98106
var keepEditingButton: XCUIElement { keepEditingButtonGetter(app) }
99107
var moreButton: XCUIElement { moreButtonGetter(app) }
108+
var noticeViewButton: XCUIElement { noticeViewButtonGetter(app) }
109+
var noticeViewTitle: XCUIElement { noticeViewTitleGetter(app) }
100110
var postSettingsButton: XCUIElement { postSettingsButtonGetter(app) }
101-
var switchToHTMLModeButton: XCUIElement { switchToHTMLModeButtonGetter(app) }
102111
var postTitleView: XCUIElement { postTitleViewGetter(app) }
103112
var redoButton: XCUIElement { redoButtonGetter(app) }
104113
var setRemindersButton: XCUIElement { setRemindersButtonGetter(app) }
114+
var switchToHTMLModeButton: XCUIElement { switchToHTMLModeButtonGetter(app) }
105115
var undoButton: XCUIElement { undoButtonGetter(app) }
106116
var unsavedChangesLabel: XCUIElement { unsavedChangesLabelGetter(app) }
107117

@@ -234,37 +244,29 @@ public class BlockEditorScreen: ScreenObject {
234244
}
235245
}
236246

237-
public func publish() throws -> EditorNoticeComponent {
238-
return try post(action: "Publish")
247+
public enum postAction: String {
248+
case publish = "Publish"
249+
case schedule = "Schedule"
239250
}
240251

241-
public func schedulePost() throws -> EditorNoticeComponent {
242-
return try post(action: "Schedule")
252+
public func postAndViewEpilogue(action: postAction) throws -> EditorPublishEpilogueScreen {
253+
try post(action: action)
254+
waitAndTap(noticeViewButton)
255+
return try EditorPublishEpilogueScreen()
243256
}
244257

245-
private func post(action: String) throws -> EditorNoticeComponent {
246-
let postButton = app.buttons[action]
247-
let postNowButton = app.buttons["\(action) Now"]
258+
public func post(action: postAction) throws {
259+
let postButton = app.buttons[action.rawValue]
260+
let postNowButton = app.buttons["\(action.rawValue) Now"]
248261
var tries = 0
249262
// This loop to check for Publish/Schedule Now Button is an attempt to confirm that the postButton.tap() call took effect.
250263
// The tests would fail sometimes in the pipeline with no apparent reason.
251264
repeat {
252265
postButton.tap()
253266
tries += 1
254267
} while !postNowButton.waitForIsHittable(timeout: 3) && tries <= 3
255-
try confirmPost(button: postNowButton)
256268

257-
let actionInNotice: String
258-
259-
if action == "Schedule" {
260-
actionInNotice = "scheduled"
261-
} else if action == "Publish" {
262-
actionInNotice = "published"
263-
} else {
264-
throw NSError(domain: "InvalidAction", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid action: \(action)"])
265-
}
266-
267-
return try EditorNoticeComponent(withNotice: "Post \(actionInNotice)")
269+
try confirmPost(button: postNowButton, action: action)
268270
}
269271

270272
@discardableResult
@@ -398,13 +400,10 @@ public class BlockEditorScreen: ScreenObject {
398400
return try PHPickerScreen()
399401
}
400402

401-
private func confirmPost(button: XCUIElement) throws {
402-
if FancyAlertComponent.isLoaded() {
403-
try FancyAlertComponent().acceptAlert()
404-
} else {
405-
button.tap()
406-
dismissBloggingRemindersAlertIfNeeded()
407-
}
403+
private func confirmPost(button: XCUIElement, action: postAction) throws {
404+
button.tap()
405+
guard action == .publish else { return }
406+
dismissBloggingRemindersAlertIfNeeded()
408407
}
409408

410409
public func dismissBloggingRemindersAlertIfNeeded() {

WordPress/UITestsFoundation/Screens/MySiteScreen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public class MySiteScreen: ScreenObject {
180180
}
181181

182182
public func goToPostsScreen() throws -> PostsScreen {
183+
goToMenu()
183184
postsButton.tap()
184185
return try PostsScreen()
185186
}
@@ -219,7 +220,7 @@ public class MySiteScreen: ScreenObject {
219220
@discardableResult
220221
public func goToMenu() -> Self {
221222
// On iPad, the menu items are already listed on screen, so we don't need to tap the menu button
222-
guard XCUIDevice.isPhone else {
223+
guard XCUIDevice.isPhone && !segmentedControlMenuButton.isSelected else {
223224
return self
224225
}
225226

WordPress/UITestsFoundation/Screens/PostsScreen.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class PostsScreen: ScreenObject {
66
public enum PostStatus {
77
case published
88
case drafts
9+
case scheduled
910
}
1011

1112
private var currentlyFilteredPostStatus: PostStatus = .published
@@ -56,6 +57,8 @@ public class PostsScreen: ScreenObject {
5657
publishedButton.tap()
5758
case .drafts:
5859
draftsButton.tap()
60+
case .scheduled:
61+
scheduledButton.tap()
5962
}
6063

6164
currentlyFilteredPostStatus = status
@@ -89,6 +92,12 @@ public class PostsScreen: ScreenObject {
8992
autosaveAlert.buttons.firstMatch.tap()
9093
}
9194
}
95+
96+
public func verifyPostExists(withTitle title: String) {
97+
let expectedPost = app.cells.containing(.staticText, identifier: title).element
98+
99+
XCTAssertTrue(expectedPost.exists)
100+
}
92101
}
93102

94103
public struct EditorScreen {

0 commit comments

Comments
 (0)