Skip to content

Fix E2E shopper tests around 3DS and UPE settings #8123

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

Merged
merged 9 commits into from
Feb 5, 2024
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/fix-e2e-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Fix for E2E shopper tests around 3DS and UPE settings
2 changes: 2 additions & 0 deletions tests/e2e/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"addressfirstline": "Rue de l’Étuve, 1000",
"addresssecondline": "billing-be",
"city": "Bruxelles",
"postcode": "1000",
"phone": "123456789",
"email": "[email protected]"
},
Expand All @@ -95,6 +96,7 @@
"addressfirstline": "Petuelring 130",
"addresssecondline": "billing-de",
"city": "München",
"postcode": "80809",
"state": "DE-BY",
"phone": "123456789",
"email": "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describeif( RUN_WC_BLOCKS_TESTS )(
await expect( page ).toClick( 'button > span', {
text: 'Place Order',
} );
await confirmCardAuthentication( page, '3DS' );
await confirmCardAuthentication( page );
await page.waitForSelector( 'div.wc-block-components-notices' );
const declined3dsCardError = await page.$eval(
'div.wc-block-components-notices > div > div.components-notice__content',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describeif( RUN_WC_BLOCKS_TESTS )(
'.wc-block-components-main button:not(:disabled)'
);
await expect( page ).toClick( 'button', { text: 'Place Order' } );
await confirmCardAuthentication( page, '3DS' );
await confirmCardAuthentication( page );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describeif( RUN_SUBSCRIPTIONS_TESTS )(
await expect( page ).toClick(
testSelectors.checkoutPlaceOrderButton
);
await confirmCardAuthentication( page, '3DS', true );
await confirmCardAuthentication( page, true );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe( 'Successful purchase', () => {
const card = config.get( 'cards.3ds' );
await fillCardDetails( page, card );
await expect( page ).toClick( '#place_order' );
await confirmCardAuthentication( page, '3DS' );
await confirmCardAuthentication( page );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe( 'Saved cards ', () => {
await shopper.placeOrder();
} else {
await expect( page ).toClick( '#place_order' );
await confirmCardAuthentication( page, cardType );
await confirmCardAuthentication( page );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down Expand Up @@ -73,7 +73,7 @@ describe( 'Saved cards ', () => {
await shopper.placeOrder();
} else {
await expect( page ).toClick( '#place_order' );
await confirmCardAuthentication( page, cardType );
await confirmCardAuthentication( page );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe( 'Payment Methods', () => {
text: 'Add payment method',
} );
if ( cardType === 'declined-3ds' ) {
await confirmCardAuthentication( page, '3DS2' );
await confirmCardAuthentication( page );
}
await expect( page ).toMatchElement( '.woocommerce-error', {
timeout: 30000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe( 'Saved cards ', () => {
await shopper.placeOrder();
} else {
await expect( page ).toClick( '#place_order' );
await confirmCardAuthentication( page, cardType );
await confirmCardAuthentication( page );
await page.waitForNavigation( {
waitUntil: 'networkidle0',
} );
Expand Down
14 changes: 12 additions & 2 deletions tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const shopperWCP = {
! cardType.toLowerCase().includes( 'declined' );

if ( cardIs3DS ) {
await confirmCardAuthentication( page, cardType );
await confirmCardAuthentication( page );
}

await page.waitForNavigation( {
Expand Down Expand Up @@ -426,7 +426,17 @@ export const merchantWCP = {
button.click()
);
}
await page.$eval( paymentMethod, ( method ) => method.click() );
// Check if paymentMethod is an XPath
if ( paymentMethod.startsWith( '//' ) ) {
// Find the element using XPath and click it
const elements = await page.$x( paymentMethod );
if ( elements.length > 0 ) {
await elements[ 0 ].click();
}
} else {
// If it's a CSS selector, use $eval
await page.$eval( paymentMethod, ( method ) => method.click() );
}
await expect( page ).toClick( 'button', {
text: 'Remove',
} );
Expand Down
15 changes: 2 additions & 13 deletions tests/e2e/utils/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ export async function clearWCBCardDetails() {
await page.keyboard.press( 'Backspace' );
}

export async function confirmCardAuthentication(
page,
cardType = '3DS',
authorize = true
) {
export async function confirmCardAuthentication( page, authorize = true ) {
const target = authorize
? '#test-source-authorize-3ds'
: '#test-source-fail-3ds';
Expand All @@ -195,14 +191,7 @@ export async function confirmCardAuthentication(
const challengeFrameHandle = await stripeFrame.waitForSelector(
'iframe#challengeFrame'
);
let challengeFrame = await challengeFrameHandle.contentFrame();
// 3DS 1 cards have another iframe enclosing the authorize form
if ( cardType.toUpperCase() === '3DS' ) {
const acsFrameHandle = await challengeFrame.waitForSelector(
'iframe[name="acsFrame"]'
);
challengeFrame = await acsFrameHandle.contentFrame();
}
const challengeFrame = await challengeFrameHandle.contentFrame();
// Need to wait for the CSS animations to complete.
await page.waitFor( 500 );
const button = await challengeFrame.waitForSelector( target );
Expand Down