Skip to content
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

Fix flaky e2e login step #4034

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Fix - Fix issue where Legacy Checkout settings get overwritten with old value.
* Add - Add WooCommerce Pre-Orders support to Bacs.
* Tweak - Fix background in express checkout settings.
* Dev - Fix flaky e2e login step

= 9.2.0 - 2025-02-13 =
* Fix - Fix missing product_id parameter for the express checkout add-to-cart operation.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Fix - Fix issue where Legacy Checkout settings get overwritten with old value.
* Add - Add WooCommerce Pre-Orders support to Bacs.
* Tweak - Fix background in express checkout settings.
* Dev - Fix flaky e2e login step

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
36 changes: 21 additions & 15 deletions tests/e2e/utils/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,31 @@ export async function login( page, username, password, retries = 3 ) {
for ( let i = 1; i <= retries; i++ ) {
try {
await page.goto( `/wp-admin` );
await page.waitForLoadState( 'networkidle' );
await page.waitForLoadState( 'load' );

if ( await page.url().includes( 'wp-login.php' ) ) {
await page.fill( 'input[name="log"]', username );
await page.fill( 'input[name="pwd"]', password );
await page.click( 'input[value="Log In"]' );
}
await page.waitForLoadState( 'networkidle' );
// Wait for login form to be visible
await page
.locator( '#loginform' )
.waitFor( { state: 'visible', timeout: 5000 } );

if ( await page.$( 'body.logged-in' ) ) {
// customer login
return;
} else {
// admin login
await expect( page.locator( 'div.wrap > h1' ) ).toHaveText(
'Dashboard'
);
return;
// Fill in login credentials
await page.locator( 'input[name="log"]' ).fill( username );
await page.locator( 'input[name="pwd"]' ).fill( password );
page.locator( 'input[value="Log In"]' ).click();
}

// Wait for either customer or admin login success
await Promise.race( [
// Customer login success
expect( page.locator( 'body.logged-in' ) ).toBeVisible(),
// Admin login success
expect(
page.getByRole( 'heading', { name: 'Dashboard' } )
).toBeVisible(),
] );

return;
} catch ( e ) {
console.error(
`User log-in failed, Retrying... ${ i }/${ retries }.`,
Expand Down
Loading