Skip to content

Conversation

@tiagomar
Copy link
Contributor

Description

This PR moves the interaction with the post publish notice from its dedicated Screen Object into BlockEditorScreen to mitigate the risk of the notice being gone by the time the script tries to tap the View button, as discussed in #21402 (review). The notice doesn't last long in the screen and the Screen Object init takes up to a couple seconds, which is quite relevant especially running in CI. 12 out of 17 failures have the same error caused by this timing issue. The changes in this PR saves up to 3-4 seconds for the testCreateScheduledPost() between tapping the Schedule Now button and tapping the notice's View button.

Testing

CI should be 🟢

@tiagomar tiagomar added the Testing Unit and UI Tests and Tooling label Aug 24, 2023
@tiagomar tiagomar added this to the Someday milestone Aug 24, 2023
@tiagomar tiagomar requested a review from a team as a code owner August 24, 2023 23:40
Comment on lines +423 to +424
guard action == .publish else { return }
dismissBloggingRemindersAlertIfNeeded()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blogging Reminder is only displayed when a post is published, so we can save the 3 seconds timeout from dismissBloggingRemindersAlertIfNeeded() when scheduling a post. ⏱️

Comment on lines -406 to -403
if FancyAlertComponent.isLoaded() {
try FancyAlertComponent().acceptAlert()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know which FancyAlert we could expect here. I've run all the editor tests several times and haven't seen it. We are saving some time here but it doesn't impact the target issue as it comes before tapping the Schedule Now button.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 25, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21414-0af55e8
Version23.1
Bundle IDorg.wordpress.alpha
Commit0af55e8
App Center BuildWPiOS - One-Offs #6887
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 25, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21414-0af55e8
Version23.1
Bundle IDcom.jetpack.alpha
Commit0af55e8
App Center Buildjetpack-installable-builds #5927
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@jostnes
Copy link
Contributor

jostnes commented Aug 25, 2023

Thanks for following up on the review comment @tiagomar! The changes look fine, but I noticed that the execution time for iPad has increased quite a bit:
image

I'm not sure if it was just a coincidence (random slowness does happen in CI), but to be sure, I'm pushing an empty commit to this PR to make it run the tests again on iPad.

@jostnes
Copy link
Contributor

jostnes commented Aug 25, 2023

The second (empty commit) run looks more in the normal time range, phewww! 😌

image

Copy link
Contributor

@jostnes jostnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a suggestion to DRY the code and one really nitpicky one, other than that I think the code looks good!

Comment on lines 115 to 116
var noticeViewButton: XCUIElement { noticeViewButtonGetter(app) }
var noticeViewTitle: XCUIElement { noticeViewTitleGetter(app) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpick - one of the things i'm trying to do is to sort the vars here alphabetically so it's easier to scan through the list of available elements, do you mind moving this alphabetically too? 🙏

    var addBlockButton: XCUIElement { addBlockButtonGetter(app) }
    var applyButton: XCUIElement { applyButtonGetter(app) }
    var chooseFromDeviceButton: XCUIElement { chooseFromDeviceButtonGetter(app) }
    var closeButton: XCUIElement { closeButtonGetter(app) }
    var discardButton: XCUIElement { discardButtonGetter(app) }
    var dismissPopoverRegion: XCUIElement { dismissPopoverRegionGetter(app) }
    var editorCloseButton: XCUIElement { editorCloseButtonGetter(app) }
    var editorNavigationBar: XCUIElement { editorNavigationBarGetter(app) }
    var firstParagraphBlock: XCUIElement { firstParagraphBlockGetter(app) }
    var fullScreenImage: XCUIElement { fullScreenImageGetter(app) }
    var insertFromUrlButton: XCUIElement { insertFromUrlButtonGetter(app) }
    var keepEditingButton: XCUIElement { keepEditingButtonGetter(app) }
    var moreButton: XCUIElement { moreButtonGetter(app) }
    var noticeViewButton: XCUIElement { noticeViewButtonGetter(app) }
    var noticeViewTitle: XCUIElement { noticeViewTitleGetter(app) }
    var postSettingsButton: XCUIElement { postSettingsButtonGetter(app) }
    var postTitleView: XCUIElement { postTitleViewGetter(app) }
    var redoButton: XCUIElement { redoButtonGetter(app) }
    var setRemindersButton: XCUIElement { setRemindersButtonGetter(app) }
    var switchToHTMLModeButton: XCUIElement { switchToHTMLModeButtonGetter(app) }
    var undoButton: XCUIElement { undoButtonGetter(app) }
    var unsavedChangesLabel: XCUIElement { unsavedChangesLabelGetter(app) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Moved these and a few others, as well as the getters, in f5e4ec4.

Comment on lines 252 to 270
public func publish() throws {
return try post(action: .publish)
}

public func publishAndViewEpilogue() throws -> EditorPublishEpilogueScreen {
try publish()
waitAndTap(noticeViewButton)
return try EditorPublishEpilogueScreen()
}

public func schedulePost() throws -> EditorNoticeComponent {
return try post(action: "Schedule")
public func schedulePost() throws {
try post(action: .schedule)
}

private func post(action: String) throws -> EditorNoticeComponent {
let postButton = app.buttons[action]
let postNowButton = app.buttons["\(action) Now"]
public func schedulePostAndViewEpilogue() throws -> EditorPublishEpilogueScreen {
try schedulePost()
waitAndTap(noticeViewButton)
return try EditorPublishEpilogueScreen()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can DRY this further, possibly by moving the ViewEpilogue part of the method into the post(action: postAction)? this way we won't need to create publishAndViewEpilogue() and schedulePostAndViewEpilogue(). wdyt?

something like:

    public func publish() throws -> EditorPublishEpilogueScreen {
        return try postAndViewEpilogue(action: .publish)
    }

    public func schedulePost() throws -> EditorPublishEpilogueScreen {
        return try postAndViewEpilogue(action: .schedule)
    }

    private func postAndViewEpilogue(action: postAction) throws -> EditorPublishEpilogueScreen {
        let postButton = app.buttons[action.rawValue]
        let postNowButton = app.buttons["\(action.rawValue) Now"]
        var tries = 0
        // This loop to check for Publish/Schedule Now Button is an attempt to confirm that the postButton.tap() call took effect.
        // The tests would fail sometimes in the pipeline with no apparent reason.
        repeat {
            postButton.tap()
            tries += 1
        } while !postNowButton.waitForIsHittable(timeout: 3) && tries <= 3

        try confirmPost(button: postNowButton, action: action)

        waitAndTap(noticeViewButton)
        return try EditorPublishEpilogueScreen()
    }

or if we want to keep post and view epilogue separate, we can DRY it by calling post(action: postAction) directly in publishAndViewEpilogue():

    public func publishAndViewEpilogue() throws -> EditorPublishEpilogueScreen {
        try post(action: .publish)
        waitAndTap(noticeViewButton)
        return try EditorPublishEpilogueScreen()
    }

Copy link
Contributor Author

@tiagomar tiagomar Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, @jostnes! While working on it I decided to keep publish() in order make it possible to publish without viewing the Epilogue and maybe go to Posts or somewhere else right away? Not deeply attached to it though. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah think that makes sense and very possible that we'd want to use it without viewing Epilogue so I think that's fine to keep it that way.

my second suggestion above is about publishAndViewEpilogue(), where instead of calling publish() or schedulePost, we call try post(action: PostAction) directly to remove that one extra level. not sure if it'll make a big difference in terms of timing but i think keeping the calls as direct as possible (when/if possible) usually helps with timing issues in UI tests. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally! Addressed in 0af55e8.

@tiagomar
Copy link
Contributor Author

And the long execution you mentioned previously #21414 (comment) cause the testCreateScheduledPost() to fail the same way despite of the improvement in this PR. 😓

While the current improvements benefit other tests, I start to think that, for testCreateScheduledPost(), maybe it's better to not rely on the Notice and change the test to confirm the post information in Posts list? WDYT?

@tiagomar tiagomar requested a review from jostnes August 25, 2023 13:20
@jostnes
Copy link
Contributor

jostnes commented Aug 28, 2023

While the current improvements benefit other tests, I start to think that, for testCreateScheduledPost(), maybe it's better to not rely on the Notice and change the test to confirm the post information in Posts list? WDYT?

i think the same, the notice is really unpredictable in CI runs as seen for this test. i'm good with using the Posts list instead of the notice, i also did a quick check on tracks, and the number of views on the posts list is ~10x more than the epilogue views so i think in terms of coverage that could be better too (jpios_post_epilogue_view vs jpios_post_list_button_pressed).

Copy link
Contributor

@jostnes jostnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for considering the changes, CI is 🟢 , it's good to :shipit:

@jostnes jostnes merged commit c767bb9 into trunk Aug 29, 2023
@jostnes jostnes deleted the ui-tests-improve-scheduled-post-test branch August 29, 2023 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing Unit and UI Tests and Tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants