From cd2edff7523a18db4d3402c3c407cc1690475549 Mon Sep 17 00:00:00 2001 From: "Veljko V." Date: Thu, 24 Oct 2024 19:40:11 +0200 Subject: [PATCH] Update e2e tests to be compatible with WP 6.7 (#52304) * Updated e2e tests to be compatible with WP 6.7 * Add changelog --- .../e2e-update-tests-to-match-wp-6-7-changes | 4 ++++ .../tests/admin-marketing/coupons.spec.js | 7 +++++- .../e2e-pw/tests/merchant/page-loads.spec.js | 2 +- .../e2e-pw/tests/shopper/checkout.spec.js | 22 +++++++++++-------- 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 plugins/woocommerce/changelog/e2e-update-tests-to-match-wp-6-7-changes diff --git a/plugins/woocommerce/changelog/e2e-update-tests-to-match-wp-6-7-changes b/plugins/woocommerce/changelog/e2e-update-tests-to-match-wp-6-7-changes new file mode 100644 index 00000000000..807174b741c --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-update-tests-to-match-wp-6-7-changes @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +E2E tests: Update relevant e2e tests to be compatible with the upcoming changes in WP 6.7 diff --git a/plugins/woocommerce/tests/e2e-pw/tests/admin-marketing/coupons.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/admin-marketing/coupons.spec.js index c2600562251..822811ca996 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/admin-marketing/coupons.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/admin-marketing/coupons.spec.js @@ -9,11 +9,16 @@ test.describe( 'Coupons page', () => { await page.goto( 'wp-admin/edit.php?post_type=shop_coupon&legacy_coupon_menu=1' ); + await expect( page.locator( 'h1.wp-heading-inline' ) ).toHaveText( 'Coupons' ); + + // Use regex to allow for "Add coupon" or "Add new coupon" + // making it compatible with WP <=6.6 & 6.7+ + const addCouponRegex = /Add (coupon|new coupon)/i; await expect( page.locator( 'a.page-title-action' ) ).toHaveText( - 'Add coupon' + addCouponRegex ); } ); } ); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js index 823d896cd28..858b0cb3f1c 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js @@ -207,7 +207,7 @@ for ( const currentPage of wcPages ) { async ( { page } ) => { await page .locator( - `li.wp-menu-open > ul.wp-submenu > li a:text-is("${ currentPage.subpages[ i ].name }")` + `li.wp-menu-open > ul.wp-submenu > li a:has-text("${ currentPage.subpages[ i ].name }")` ) .click(); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js index c9e84c74770..e09d44a4a86 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js @@ -461,12 +461,12 @@ test.describe( await test.step( 'Confirm order details on the backend (as a merchant)', async () => { await page.goto( 'wp-login.php' ); await page - .locator( 'input[name="log"]' ) + .getByLabel( 'Username or Email Address' ) .fill( admin.username ); await page - .locator( 'input[name="pwd"]' ) + .getByRole( 'textbox', { name: 'Password' } ) .fill( admin.password ); - await page.locator( 'text=Log In' ).click(); + await page.getByRole( 'button', { name: 'Log In' } ).click(); // load the order placed as a guest await page.goto( @@ -497,12 +497,12 @@ test.describe( test( 'allows existing customer to place order', async ( { page } ) => { await page.goto( 'my-account/' ); await page - .locator( 'input[name="username"]' ) + .getByLabel( 'Username or Email Address' ) .fill( customer.username ); await page - .locator( 'input[name="password"]' ) + .getByRole( 'textbox', { name: 'Password' } ) .fill( customer.password ); - await page.locator( 'text=Log In' ).click(); + await page.getByRole( 'button', { name: 'Log In' } ).click(); await expect( page.getByText( `Hello ${ customer.first_name } ${ customer.last_name }` @@ -563,9 +563,13 @@ test.describe( // Switch to admin user. await page.goto( 'wp-login.php?loggedout=true' ); - await page.locator( 'input[name="log"]' ).fill( admin.username ); - await page.locator( 'input[name="pwd"]' ).fill( admin.password ); - await page.locator( 'text=Log In' ).click(); + await page + .getByLabel( 'Username or Email Address' ) + .fill( admin.username ); + await page + .getByRole( 'textbox', { name: 'Password' } ) + .fill( admin.password ); + await page.getByRole( 'button', { name: 'Log In' } ).click(); // load the order placed as a customer await page.goto(