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 flakiness while creating a page with the checkout block #10340

Merged
merged 13 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions changelog/dev-10339-wcb-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Fix potential flakiness while creating a page with the checkout block.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ describeif( shouldRunSubscriptionsTests )(
} );

test( 'should be able to purchase a subscription', async () => {
await shopper.addToCartFromShopPage(
page,
config.products.subscription_signup_fee
);

await shopper.setupCheckout( page, customerBillingConfig );
await shopper.selectPaymentMethod( page );
await shopper.fillCardDetails( page, config.cards.basic );
await shopper.placeOrder( page );
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
).toBeVisible();
await shopper.placeOrderWithOptions( page, {
product: config.products.subscription_signup_fee,
billingAddress: customerBillingConfig,
} );

subscriptionId = await page
.getByLabel( 'View subscription number' )
Expand Down Expand Up @@ -70,6 +62,7 @@ describeif( shouldRunSubscriptionsTests )(
).toBeVisible();
await shopper.focusPlaceOrderButton( page );
await shopper.placeOrder( page );
await page.waitForURL( /\/order-received\// );
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
).toBeVisible();
Expand Down
28 changes: 15 additions & 13 deletions tests/e2e-pw/specs/wcpay/shopper/shopper-pay-for-order.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { test, expect } from '@playwright/test';
import { test, expect, Page } from '@playwright/test';

/**
* Internal dependencies
Expand All @@ -18,14 +18,21 @@ const cardTestingPreventionStates = [
];

test.describe( 'Shopper > Pay for Order', () => {
let merchantPage: Page;
let shopperPage: Page;

test.beforeAll( async ( { browser } ) => {
merchantPage = ( await getMerchant( browser ) ).merchantPage;
shopperPage = ( await getShopper( browser ) ).shopperPage;
} );

test.afterAll( async () => {
await devtools.disableCardTestingProtection( merchantPage );
} );

cardTestingPreventionStates.forEach(
( { cardTestingPreventionEnabled } ) => {
test( `should be able to pay for a failed order with card testing protection ${ cardTestingPreventionEnabled }`, async ( {
browser,
} ) => {
const { merchantPage } = await getMerchant( browser );
const { shopperPage } = await getShopper( browser );

test( `should be able to pay for a failed order with card testing protection ${ cardTestingPreventionEnabled }`, async () => {
// Enable or disable card testing protection.
if ( ! cardTestingPreventionEnabled ) {
await devtools.disableCardTestingProtection( merchantPage );
Expand Down Expand Up @@ -67,7 +74,7 @@ test.describe( 'Shopper > Pay for Order', () => {
config.cards.basic
);

// Check for the fraud prevenction token presence.
// Check for the fraud prevention token presence.
const token = await shopperPage.evaluate( () => {
return ( window as any ).wcpayFraudPreventionToken;
} );
Expand All @@ -84,11 +91,6 @@ test.describe( 'Shopper > Pay for Order', () => {
await expect(
shopperPage.getByText( 'Order received' ).first()
).toBeVisible();

// Disable card testing protection if necessary.
if ( cardTestingPreventionEnabled ) {
await devtools.disableCardTestingProtection( merchantPage );
}
} );
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,7 @@ describeif( shouldRunWCBlocksTests )(
await shopper.placeOrderWCB( shopperPage, false );

if ( auth ) {
const placeOrderButton = shopperPage.locator(
'.wc-block-components-checkout-place-order-button'
);
await expect( placeOrderButton ).toBeDisabled();
await expect( placeOrderButton ).toHaveClass(
/wc-block-components-button--loading/
);
await shopper.confirmCardAuthentication( shopperPage );
await shopper.confirmCardAuthenticationWCB( shopperPage );
}

if ( errorsInsideStripeFrame.includes( card ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import { addWCBCheckoutPage } from '../../../utils/merchant';
import { goToCheckoutWCB } from '../../../utils/shopper-navigation';
import {
addToCartFromShopPage,
confirmCardAuthentication,
confirmCardAuthenticationWCB,
fillBillingAddressWCB,
fillCardDetailsWCB,
placeOrderWCB,
} from '../../../utils/shopper';
import { config } from '../../../config/default';

Expand Down Expand Up @@ -49,14 +50,7 @@ describeif( shouldRunWCBlocksTests )(
config.addresses.customer.billing
);
await fillCardDetailsWCB( shopperPage, config.cards.basic );
await shopperPage
.getByRole( 'button', { name: 'Place Order' } )
.click();
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();
await placeOrderWCB( shopperPage );
} );

test( 'using a 3DS card', async () => {
Expand All @@ -70,10 +64,8 @@ describeif( shouldRunWCBlocksTests )(
config.addresses.customer.billing
);
await fillCardDetailsWCB( shopperPage, config.cards[ '3ds' ] );
await shopperPage
.getByRole( 'button', { name: 'Place Order' } )
.click();
await confirmCardAuthentication( shopperPage );
await placeOrderWCB( shopperPage, false );
await confirmCardAuthenticationWCB( shopperPage );
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e-pw/utils/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const saveDevToolsSettings = async ( page: Page ) => {
};

const getIsCardTestingProtectionEnabled = ( page: Page ) =>
page.getByLabel( 'Card testing mitigations enabled' ).isChecked();
page.getByLabel( /Card testing mitigations enabled/ ).isChecked();

const setCardTestingProtection = ( page: Page, enabled: boolean ) =>
page
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e-pw/utils/merchant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export const addWCBCheckoutPage = async ( page: Page ) => {

await page
.locator( '#wpbody-content' )
.getByRole( 'link', { name: 'Add New Page' } )
.getByRole( 'link', { name: /^Add( New)? Page$/ } )
.click();
await page.waitForLoadState( 'load' );

Expand All @@ -442,8 +442,6 @@ export const addWCBCheckoutPage = async ( page: Page ) => {
await editor.getByLabel( 'Add title' ).fill( 'Checkout WCB' );
await editor.getByLabel( 'Add block' ).click();

await ensureBlockSettingsPanelIsOpen( page );

await page.getByPlaceholder( 'Search' ).fill( 'Checkout' );
await page.getByRole( 'option', { name: 'Checkout', exact: true } ).click();

Expand All @@ -452,6 +450,8 @@ export const addWCBCheckoutPage = async ( page: Page ) => {
await page.keyboard.press( 'Escape' ); // to dismiss a dialog if present

// Enable the "Company" field if it's not already enabled.
await ensureBlockSettingsPanelIsOpen( page );

await page.getByLabel( 'Document Overview' ).click();
await page.waitForTimeout( 1000 );
await expect( page.locator( '.editor-list-view-sidebar' ) ).toBeVisible();
Expand Down
22 changes: 22 additions & 0 deletions tests/e2e-pw/utils/shopper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,25 @@ export const removeCoupon = async ( page: Page ) => {
).toBeVisible();
}
};

/**
* When using a 3DS card, call this function after clicking the 'Place order' button
* to confirm the card authentication.
*
* @param {Page} page The Shopper page object.
* @param {boolean} authorize Whether to authorize the transaction or not.
* @return {Promise<void>} Void.
*/
export const confirmCardAuthenticationWCB = async (
page: Page,
authorize = true
): Promise< void > => {
const placeOrderButton = page.locator(
'.wc-block-components-checkout-place-order-button'
);
await expect( placeOrderButton ).toBeDisabled();
await expect( placeOrderButton ).toHaveClass(
/wc-block-components-button--loading/
);
await confirmCardAuthentication( page, authorize );
};
Loading