-
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
Migrated nux.test.js to Playwright #39772
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e2a3be0
Updated playwright config for windows Git bash support
sandeshjangam 2812aa3
Migrated new-post and it's util create-new-post
sandeshjangam aebe07a
Migrated nux.spec.js
sandeshjangam 268c0cb
Removed temporary commented code
sandeshjangam 5bfb452
Reverted plywright config
sandeshjangam 49e6916
Removed unwanted new-post spec
sandeshjangam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/e2e-test-utils-playwright/src/page/click-on-more-menu-item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Clicks on More Menu item, searches for the button with the text provided and clicks it. | ||
* | ||
* @param {string} buttonLabel The label to search the button for. | ||
*/ | ||
export async function clickOnMoreMenuItem( buttonLabel ) { | ||
const menuSelector = await this.page.locator( | ||
'.interface-more-menu-dropdown [aria-label="Options"]' | ||
); | ||
|
||
await menuSelector.click(); | ||
|
||
const moreMenuContainerSelector = | ||
'//*[contains(concat(" ", @class, " "), " interface-more-menu-dropdown__content ")]'; | ||
|
||
const elementToClick = await this.page | ||
.locator( | ||
`${ moreMenuContainerSelector }//span[contains(concat(" ", @class, " "), " components-menu-item__item ")][contains(text(), "${ buttonLabel }")]` | ||
) | ||
.first(); | ||
await elementToClick.click(); | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/e2e-test-utils-playwright/src/page/create-new-post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Creates new post. | ||
* | ||
* @this {import('./').PageUtils} | ||
* @param {Object} object Object to create new post, along with tips enabling option. | ||
* @param {string} [object.postType] Post type of the new post. | ||
* @param {string} [object.title] Title of the new post. | ||
* @param {string} [object.content] Content of the new post. | ||
* @param {string} [object.excerpt] Excerpt of the new post. | ||
* @param {boolean} [object.showWelcomeGuide] Whether to show the welcome guide. | ||
*/ | ||
export async function createNewPost( { | ||
postType, | ||
title, | ||
content, | ||
excerpt, | ||
showWelcomeGuide = false, | ||
} = {} ) { | ||
const query = addQueryArgs( '', { | ||
post_type: postType, | ||
post_title: title, | ||
content, | ||
excerpt, | ||
} ).slice( 1 ); | ||
|
||
await this.visitAdminPage( 'post-new.php', query ); | ||
|
||
await this.page.waitForSelector( '.edit-post-layout' ); | ||
|
||
const isWelcomeGuideActive = await this.page.evaluate( () => | ||
window.wp.data | ||
.select( 'core/edit-post' ) | ||
.isFeatureActive( 'welcomeGuide' ) | ||
); | ||
const isFullscreenMode = await this.page.evaluate( () => | ||
window.wp.data | ||
.select( 'core/edit-post' ) | ||
.isFeatureActive( 'fullscreenMode' ) | ||
); | ||
|
||
if ( showWelcomeGuide !== isWelcomeGuideActive ) { | ||
await this.page.evaluate( () => | ||
window.wp.data | ||
.dispatch( 'core/edit-post' ) | ||
.toggleFeature( 'welcomeGuide' ) | ||
); | ||
|
||
await this.page.reload(); | ||
await this.page.waitForSelector( '.edit-post-layout' ); | ||
} | ||
|
||
if ( isFullscreenMode ) { | ||
await this.page.evaluate( () => | ||
window.wp.data | ||
.dispatch( 'core/edit-post' ) | ||
.toggleFeature( 'fullscreenMode' ) | ||
); | ||
|
||
await this.page.waitForSelector( 'body:not(.is-fullscreen-mode)' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'New User Experience (NUX)', () => { | ||
test( 'should show the guide to first-time users', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
let welcomeGuideText, welcomeGuide; | ||
|
||
// Create a new post as a first-time user. | ||
await pageUtils.createNewPost( { showWelcomeGuide: true } ); | ||
|
||
// Guide should be on page 1 of 4 | ||
welcomeGuideText = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuideText ).toContainText( | ||
'Welcome to the block editor' | ||
); | ||
|
||
// Click on the 'Next' button. | ||
const nextButton = await page.locator( | ||
'//button[contains(text(), "Next")]' | ||
); | ||
await nextButton.click(); | ||
|
||
// Guide should be on page 2 of 4 | ||
welcomeGuideText = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuideText ).toContainText( | ||
'Make each block your own' | ||
); | ||
|
||
// Click on the 'Previous' button. | ||
const previousButton = await page.locator( | ||
'//button[contains(text(), "Previous")]' | ||
); | ||
await previousButton.click(); | ||
|
||
// Guide should be on page 1 of 4 | ||
welcomeGuideText = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuideText ).toContainText( | ||
'Welcome to the block editor' | ||
); | ||
|
||
// Press the button for Page 2. | ||
await page.click( 'button[aria-label="Page 2 of 4"]' ); | ||
await page.locator( | ||
'//h1[contains(text(), "Make each block your own")]' | ||
); | ||
|
||
// Press the right arrow key for Page 3. | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.locator( | ||
'//h1[contains(text(), "Get to know the block library")]' | ||
); | ||
|
||
// Press the right arrow key for Page 4. | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.locator( | ||
'//h1[contains(text(), "Learn how to use the block editor")]' | ||
); | ||
|
||
// Click on the *visible* 'Get started' button. There are two in the DOM | ||
// but only one is shown depending on viewport size. | ||
const getStartedButton = page.locator( | ||
'.components-guide__footer button:text("Get started")' | ||
); | ||
await getStartedButton.click(); | ||
|
||
// Guide should be closed | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).not.toBeVisible(); | ||
|
||
// Reload the editor. | ||
await page.reload(); | ||
await page.waitForSelector( '.edit-post-layout' ); | ||
|
||
// Guide should be closed | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).not.toBeVisible(); | ||
} ); | ||
|
||
test( 'should not show the welcome guide again if it is dismissed', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
let welcomeGuide; | ||
|
||
// Create a new post as a first-time user. | ||
await pageUtils.createNewPost( { showWelcomeGuide: true } ); | ||
|
||
// Guide should be open | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).toBeVisible(); | ||
|
||
// Close the guide | ||
await page.click( 'button[aria-label="Close dialog"]' ); | ||
|
||
// Reload the editor. | ||
await page.reload(); | ||
await page.waitForSelector( '.edit-post-layout' ); | ||
|
||
// Guide should be closed | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).not.toBeVisible(); | ||
} ); | ||
|
||
test( 'should show the welcome guide if it is manually opened', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
let welcomeGuide; | ||
|
||
// Create a new post as a returning user. | ||
await pageUtils.createNewPost(); | ||
|
||
// Guide should be closed | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).not.toBeVisible(); | ||
|
||
// Manually open the guide | ||
await pageUtils.clickOnMoreMenuItem( 'Welcome Guide' ); | ||
|
||
// Guide should be open | ||
welcomeGuide = await page.locator( '.edit-post-welcome-guide' ); | ||
await expect( welcomeGuide ).toBeVisible(); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we want to change this?