-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Playwright Utils: Fix the method of getting post ID in 'publishPost' #56421
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,11 @@ export async function publishPost( this: Editor ) { | |
'role=region[name="Editor publish"i] >> role=button[name="Publish"i]' | ||
); | ||
|
||
const urlString = await this.page | ||
.getByRole( 'region', { name: 'Editor publish' } ) | ||
.getByRole( 'textbox', { name: 'address' } ) | ||
.inputValue(); | ||
const url = new URL( urlString ); | ||
const postId = url.searchParams.get( 'p' ); | ||
await this.page | ||
.getByRole( 'button', { name: 'Dismiss this notice' } ) | ||
.filter( { hasText: 'published' } ) | ||
.waitFor(); | ||
const postId = new URL( this.page.url() ).searchParams.get( 'post' ); | ||
|
||
return typeof postId === 'string' ? parseInt( postId, 10 ) : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which situations would the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure. The safeguard was here, so I just left it. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ test.describe( 'Sidebar Permalink', () => { | |
await editor.canvas | ||
.getByRole( 'textbox', { name: 'Add title' } ) | ||
.fill( 'aaaaa' ); | ||
await editor.saveDraft(); | ||
await editor.publishPost(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly to showcase that it works. See #56253 (comment). |
||
// Start editing again. | ||
await editor.canvas | ||
.getByRole( 'textbox', { name: 'Add title' } ) | ||
|
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.
This looks OK, but if we expect the
post
param to be there, we might want to wrap it withwaitForFunction
or anexpect.poll
so we're not fetching it too early.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.
I don't have strong opinions here, but if the query param isn't available, there's something wrong with the test, and it's better to fail.
We're already using a similar pattern without any additional checks. Here's an example from perf utils:
gutenberg/test/performance/fixtures/perf-utils.ts
Line 62 in a791158
P.S. The
post
query arg doesn't change after a post is published or saved as a draft.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.
That's why I asked if there's a situation where the post id would not be available after saving/publishing. If not, we should probably throw from this util instead of returning
null
, IIUC.Right, the subsequent saves would already have the
post
param. The only potential flakey would come from the first save, then. I guess this is fine, though it would not be the first time I see racing issues caused by assuming one element's state off of another's – in this case, URL off of the post-publish notice.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.
E2E tests have to make those assumptions, IMO.
Somethings like this?
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.
Not if we can wait for stuff! 😄 (post ID in this case)
I realized now that we could get the ID via the
getCurrentPostId()
which we don't need to wait for (id
is set when thenew-post.php
is open)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.
...but we can also wait for the
post
param, like this: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.
Thank you, @WunderBart 🙇 Do you think we should update the code or keep it as it is for now?
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.
If it ain't broke, don't fix it, right? 😄 No pressure here - let's just keep that in mind in case it starts making trouble.
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.
Sounds good!