mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Playwright E2E test to create new user
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Create User', () => { | ||
let username, email; | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
// Navigate to the Add New User page | ||
await admin.visitAdminPage( 'user-new.php' ); | ||
} ); | ||
|
||
test.afterEach( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllUsers(); | ||
} ); | ||
|
||
test( 'creates new user successfully', async ( { page, requestUtils } ) => { | ||
// Generate random username and email | ||
username = 'TestUser' + Date.now(); | ||
email = `user${ Date.now() }@domain.tld`; | ||
|
||
// Wait until network is idle | ||
await page.waitForLoadState( 'networkidle' ); | ||
|
||
// Fill in the username and email | ||
await page.locator( '#user_login' ).fill( username ); | ||
await page.locator( '#email' ).fill( email ); | ||
|
||
const passwordText = await page.locator( '#pass1' ).textContent(); | ||
|
||
// Click the "Add New User" button | ||
await page.click( 'role=button[name="Add New User"i]' ); | ||
|
||
// Verify success message | ||
await expect( page.locator( '#message p' ) ).toHaveText( | ||
'New user created. Edit user' | ||
); | ||
|
||
await requestUtils.login( username, passwordText ); | ||
|
||
// Verify if the expected element is visible | ||
const isLoggedIn = await page | ||
.locator( '.wp-heading-inline' ) | ||
.isVisible(); | ||
if ( isLoggedIn ) { | ||
console.log( 'Login successful with newly created user' ); | ||
} else { | ||
console.error( 'Login failed' ); | ||
} | ||
} ); | ||
} ); |