From ec8500df050aaa314e168c3f1c9e428a50a0975c Mon Sep 17 00:00:00 2001 From: Anne Mirasol Date: Mon, 30 Dec 2024 20:06:19 -0600 Subject: [PATCH] Improve e2e flakiness --- tests/e2e/test-data/default.json | 20 +++++++++++++++---- .../woocommerce-blocks/sca-card.spec.js | 2 +- .../blocks/subscription-product.spec.js | 4 ++-- .../checkout/shortcode/card-failures.spec.js | 2 +- .../checkout/shortcode/normal-card.spec.js | 2 +- .../checkout/shortcode/saved-card.spec.js | 4 ++-- .../tests/checkout/shortcode/sca-card.spec.js | 2 +- .../shortcode/subscription-product.spec.js | 2 +- tests/e2e/tests/default.setup.js | 16 +++++++++++++++ tests/e2e/tests/orders/full-refund.spec.js | 2 +- .../subscription-renewal.spec.js | 4 +++- tests/e2e/utils/payments.js | 10 +++++++--- 12 files changed, 52 insertions(+), 18 deletions(-) diff --git a/tests/e2e/test-data/default.json b/tests/e2e/test-data/default.json index c7a96984e..70521fd46 100644 --- a/tests/e2e/test-data/default.json +++ b/tests/e2e/test-data/default.json @@ -153,7 +153,9 @@ "label": "Visa ending in 0002", "error": [ "The card was declined.", - "Your card was declined." + "Your card was declined.", + "The card has been declined.", + "Your card has been declined." ] }, "declined-funds": { @@ -190,7 +192,7 @@ }, "cvc": "626", "label": "Visa ending in 0069", - "error": [ "The card has expired.", "Your card has expired." ] + "error": [ "The card has expired.", "Your card has expired.", "Your card is expired." ] }, "declined-cvc": { "number": "4000000000000127", @@ -202,7 +204,8 @@ "label": "Visa ending in 0127", "error": [ "The card's security code is incorrect.", - "Your card's security code is incorrect." + "Your card's security code is incorrect.", + "Your card.s CVC is incorrect." ] }, "declined-processing": { @@ -215,7 +218,7 @@ "label": "Visa ending in 0119", "error": [ "An error occurred while processing the card.", - "An error occurred while processing your card. Try again in a little bit." + "An error occurred while processing your card." ] }, "declined-3ds": { @@ -244,6 +247,15 @@ }, "cvc": "11", "label": "Visa ending in 4242" + }, + "no-3ds": { + "number": "378282246310005", + "expires": { + "month": "06", + "year": "29" + }, + "cvc": "626", + "label": "3DS not supported" } } } diff --git a/tests/e2e/tests/_legacy-experience/woocommerce-blocks/sca-card.spec.js b/tests/e2e/tests/_legacy-experience/woocommerce-blocks/sca-card.spec.js index 93628919f..d63b6b61f 100644 --- a/tests/e2e/tests/_legacy-experience/woocommerce-blocks/sca-card.spec.js +++ b/tests/e2e/tests/_legacy-experience/woocommerce-blocks/sca-card.spec.js @@ -35,7 +35,7 @@ test( 'customer can checkout with a SCA card @smoke @blocks', async ( { name: 'stripe-challenge-frame', } ) .getByRole( 'button', { name: 'Complete' } ) - .click(); + .dispatchEvent( 'click' ); await page.waitForURL( '**/checkout/order-received/**' ); diff --git a/tests/e2e/tests/checkout/blocks/subscription-product.spec.js b/tests/e2e/tests/checkout/blocks/subscription-product.spec.js index facf28db9..4fd5cd031 100644 --- a/tests/e2e/tests/checkout/blocks/subscription-product.spec.js +++ b/tests/e2e/tests/checkout/blocks/subscription-product.spec.js @@ -43,10 +43,10 @@ test( 'customer can purchase a subscription product @smoke @blocks @subscription }; await setupBlocksCheckout( page, customerData ); - await fillCreditCardDetails( page, config.get( 'cards.basic' ) ); + await fillCreditCardDetails( page, config.get( 'cards.no-3ds' ) ); await page.locator( 'text=Sign up now' ).click(); - await page.waitForNavigation(); + await page.waitForURL( '**/checkout/order-received/**' ); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( 'Order received' diff --git a/tests/e2e/tests/checkout/shortcode/card-failures.spec.js b/tests/e2e/tests/checkout/shortcode/card-failures.spec.js index 20ce9f214..0219efcce 100644 --- a/tests/e2e/tests/checkout/shortcode/card-failures.spec.js +++ b/tests/e2e/tests/checkout/shortcode/card-failures.spec.js @@ -22,7 +22,7 @@ const testCard = async ( page, cardKey ) => { const card = config.get( cardKey ); await fillCreditCardDetailsShortcode( page, card ); - await page.locator( 'text=Place order' ).click(); + await page.locator( 'text=Place order' ).dispatchEvent( 'click' ); expect .soft( await page.innerText( '.woocommerce-error' ) ) diff --git a/tests/e2e/tests/checkout/shortcode/normal-card.spec.js b/tests/e2e/tests/checkout/shortcode/normal-card.spec.js index 8df8d3cc1..519156609 100644 --- a/tests/e2e/tests/checkout/shortcode/normal-card.spec.js +++ b/tests/e2e/tests/checkout/shortcode/normal-card.spec.js @@ -19,7 +19,7 @@ test( 'customer can checkout with a normal credit card @smoke', async ( { config.get( 'addresses.customer.billing' ) ); await fillCreditCardDetailsShortcode( page, config.get( 'cards.basic' ) ); - await page.locator( 'text=Place order' ).click(); + await page.locator( 'text=Place order' ).dispatchEvent( 'click' ); await page.waitForNavigation(); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( diff --git a/tests/e2e/tests/checkout/shortcode/saved-card.spec.js b/tests/e2e/tests/checkout/shortcode/saved-card.spec.js index 5c1d73f82..49fad32f5 100644 --- a/tests/e2e/tests/checkout/shortcode/saved-card.spec.js +++ b/tests/e2e/tests/checkout/shortcode/saved-card.spec.js @@ -48,7 +48,7 @@ test( 'customer can checkout with a saved card @smoke', async ( { page } ) => { // check box to save payment method. await page.locator( '#wc-stripe-new-payment-method' ).click(); - await page.locator( 'text=Place order' ).click(); + await page.locator( 'text=Place order' ).dispatchEvent( 'click' ); await page.waitForNavigation(); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( @@ -68,7 +68,7 @@ test( 'customer can checkout with a saved card @smoke', async ( { page } ) => { ) ).toHaveCount( 1 ); - await page.locator( 'text=Place order' ).click(); + await page.locator( 'text=Place order' ).dispatchEvent( 'click' ); await page.waitForNavigation(); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( diff --git a/tests/e2e/tests/checkout/shortcode/sca-card.spec.js b/tests/e2e/tests/checkout/shortcode/sca-card.spec.js index 74aef73e4..227c4c22c 100644 --- a/tests/e2e/tests/checkout/shortcode/sca-card.spec.js +++ b/tests/e2e/tests/checkout/shortcode/sca-card.spec.js @@ -17,7 +17,7 @@ test( 'customer can checkout with a SCA card @smoke', async ( { page } ) => { config.get( 'addresses.customer.billing' ) ); await fillCreditCardDetailsShortcode( page, config.get( 'cards.3ds' ) ); - await page.locator( 'text=Place order' ).click(); + await page.locator( 'text=Place order' ).dispatchEvent( 'click' ); // Wait until the SCA frame is available while ( diff --git a/tests/e2e/tests/checkout/shortcode/subscription-product.spec.js b/tests/e2e/tests/checkout/shortcode/subscription-product.spec.js index e7e043efe..ae6bbc258 100644 --- a/tests/e2e/tests/checkout/shortcode/subscription-product.spec.js +++ b/tests/e2e/tests/checkout/shortcode/subscription-product.spec.js @@ -46,7 +46,7 @@ test( 'customer can purchase a subscription product @smoke @subscriptions', asyn await fillCreditCardDetailsShortcode( page, config.get( 'cards.basic' ) ); await page.locator( 'text=Sign up now' ).click(); - await page.waitForNavigation(); + await page.waitForURL( '**/checkout/order-received/**' ); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( 'Order received' diff --git a/tests/e2e/tests/default.setup.js b/tests/e2e/tests/default.setup.js index bd148c50b..1148da6e7 100644 --- a/tests/e2e/tests/default.setup.js +++ b/tests/e2e/tests/default.setup.js @@ -21,3 +21,19 @@ setup( 'Disable legacy checkout experience', async ( { browser } ) => { page.getByTestId( 'legacy-checkout-experience-checkbox' ) ).not.toBeChecked(); } ); + +setup( 'Disable Link by Stripe', async ( { browser } ) => { + const adminContext = await browser.newContext( { + storageState: process.env.ADMINSTATE, + } ); + const page = await adminContext.newPage(); + + await page.goto( + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=stripe&panel=methods' + ); + await page.getByLabel( 'Link by Stripe Input' ).uncheck(); + await page.click( 'text=Save changes' ); + + await expect( page.getByText( 'Settings saved.' ) ).toBeDefined(); + await expect( page.getByLabel( 'Link by Stripe Input' ) ).not.toBeChecked(); +} ); diff --git a/tests/e2e/tests/orders/full-refund.spec.js b/tests/e2e/tests/orders/full-refund.spec.js index bfab3907b..17da2a2c8 100644 --- a/tests/e2e/tests/orders/full-refund.spec.js +++ b/tests/e2e/tests/orders/full-refund.spec.js @@ -33,7 +33,7 @@ test( 'merchant can issue a full refund @smoke', async ( { browser } ) => { userPage, config.get( 'cards.basic' ) ); - await userPage.locator( 'text=Place order' ).click(); + await userPage.locator( 'text=Place order' ).dispatchEvent( 'click' ); await userPage.waitForURL( '**/checkout/order-received/**' ); await expect( userPage.locator( 'h1.entry-title' ) ).toHaveText( diff --git a/tests/e2e/tests/subscriptions/subscription-renewal.spec.js b/tests/e2e/tests/subscriptions/subscription-renewal.spec.js index 369925250..86c10fc61 100644 --- a/tests/e2e/tests/subscriptions/subscription-renewal.spec.js +++ b/tests/e2e/tests/subscriptions/subscription-renewal.spec.js @@ -86,7 +86,9 @@ test( 'customer can renew a subscription @smoke @subscriptions', async ( { await page.click( 'input[id^="radio-control-wc-payment-method-saved-tokens-"]' ); - await page.click( 'text=Renew subscription' ); + await page + .locator( 'text=Renew subscription' ) + .dispatchEvent( 'click' ); await expect( page.locator( 'h1.entry-title' ) ).toHaveText( 'Order received' ); diff --git a/tests/e2e/utils/payments.js b/tests/e2e/utils/payments.js index b6efdb4a9..6ab510cd8 100644 --- a/tests/e2e/utils/payments.js +++ b/tests/e2e/utils/payments.js @@ -188,9 +188,13 @@ export async function setupShortcodeCheckout( page, billingDetails = null ) { for ( const fieldName of Object.keys( billingDetails ) ) { if ( - [ 'state', 'country', 'state_iso', 'country_iso' ].includes( - fieldName - ) + [ + 'state', + 'country', + 'state_iso', + 'country_iso', + 'company', + ].includes( fieldName ) ) { continue; }