[@wordpress/e2e-test-utils-playwright] Add openPostInEditor function#51333
[@wordpress/e2e-test-utils-playwright] Add openPostInEditor function#51333opr wants to merge 2 commits into
@wordpress/e2e-test-utils-playwright] Add openPostInEditor function#51333Conversation
|
Thanks for the PR! I have some questions about the motivation:
I didn't imagine the utils would be used in this way. That's why we clear all posts/pages before starting the tests to guarantee a consistent testing environment. Under such an assumption, I would imagine the API to be implemented and used as the following instead: const postContent = await fs.readFile( './my/test/post.html' );
const { id: postId } = await requestUtils.createPost( {
title: 'My test post',
content: postContent,
status: 'publish',
} );
await admin.visitPostById( postId );This ensures the post we're interacting with is always an isolated post that can't be intercepted by other parallel tests. It also enables full parallel testing in the future for more speed. It's also a lot faster because we don't have to visit the post list page to search for something by its title. The test is also portable since we just need the html file somewhere and don't need the post to exist in the database. Most of the API are already supported. IIRC, we only need to implement WDYT of this approach? |
|
hi @kevin940726 thanks for the review and your patience while I responded!
ah this is a great idea, I see what you mean, I agree with all the reasons you mention about parallel testing too, thanks for the insight.
Would it make sense to create Please let me know if closing is your preference. |
What?
Adds an
openPostInEditorfunction to theAdminclass. This function will search for (by title), then open the specified page in the editor.Why?
When testing, people may set up their test env with pre-published pages containing blocks they wish to test. The tests may need to open these pages to update block-specific settings to test different code paths.
It is not guaranteed that the IDs of the specific pages will be the same across runs, so it makes sense to be able to open the page by name, like a user would.
How?
It opens the admin page for the specified post type and searches for the specified post name. When the search is complete, it finds the link to edit the post and then clicks it. When the network is idle the function returns.
Testing Instructions
Set up
wp-env.Add a new test file,
test/e2e/specs/editor/various/open-in-editor.spec.jsand add the following code:Run
npm run test:e2e:playwright -- open-in-editorand ensure the test passes.Note: If you run this multiple times it will fail because the pages will be duplicated, so be sure to clear them between runs!
Open a test file, for example:
Testing Instructions for Keyboard
This PR does not affect the UI.