Skip to content

Commit 82ac1b9

Browse files
Convert the Shopper Pay for Order spec to Playwright (#10104)
1 parent 700b287 commit 82ac1b9

File tree

4 files changed

+135
-84
lines changed

4 files changed

+135
-84
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: dev
3+
4+
Add the Playwright Pay for Order spec and remove the equivalent Puppeteer spec.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { test, expect } from '@playwright/test';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import { config } from '../../config/default';
10+
import * as shopper from '../../utils/shopper';
11+
import * as shopperNavigation from '../../utils/shopper-navigation';
12+
import * as devtools from '../../utils/devtools';
13+
import { getMerchant, getShopper } from '../../utils/helpers';
14+
15+
const cardTestingPreventionStates = [
16+
{ cardTestingPreventionEnabled: false },
17+
{ cardTestingPreventionEnabled: true },
18+
];
19+
20+
test.describe( 'Shopper > Pay for Order', () => {
21+
cardTestingPreventionStates.forEach(
22+
( { cardTestingPreventionEnabled } ) => {
23+
test( `should be able to pay for a failed order with card testing protection ${ cardTestingPreventionEnabled }`, async ( {
24+
browser,
25+
} ) => {
26+
const { merchantPage } = await getMerchant( browser );
27+
const { shopperPage } = await getShopper( browser );
28+
29+
// Enable or disable card testing protection.
30+
if ( ! cardTestingPreventionEnabled ) {
31+
await devtools.disableCardTestingProtection( merchantPage );
32+
} else {
33+
await devtools.enableCardTestingProtection( merchantPage );
34+
}
35+
36+
// Attempt to pay with a declined card.
37+
await shopper.addCartProduct( shopperPage );
38+
await shopper.setupCheckout(
39+
shopperPage,
40+
config.addresses.customer.billing
41+
);
42+
await shopper.fillCardDetails(
43+
shopperPage,
44+
config.cards.declined
45+
);
46+
await shopper.placeOrder( shopperPage );
47+
48+
await expect(
49+
shopperPage.getByText( 'Your card was declined' ).first()
50+
).toBeVisible();
51+
52+
// Go to the orders page and pay with a basic card.
53+
await shopperNavigation.goToOrders( shopperPage );
54+
55+
const payForOrderButton = shopperPage
56+
.locator( '.woocommerce-button.button.pay', {
57+
hasText: 'Pay',
58+
} )
59+
.first();
60+
await payForOrderButton.click();
61+
await shopper.fillCardDetails(
62+
shopperPage,
63+
config.cards.basic
64+
);
65+
66+
// Check for the fraud prevenction token presence.
67+
const token = await shopperPage.evaluate( () => {
68+
return ( window as any ).wcpayFraudPreventionToken;
69+
} );
70+
71+
if ( cardTestingPreventionEnabled ) {
72+
expect( token ).not.toBeUndefined();
73+
} else {
74+
expect( token ).toBeUndefined();
75+
}
76+
77+
// Click the pay for order button.
78+
await shopper.placeOrder( shopperPage );
79+
80+
await expect(
81+
shopperPage.getByText( 'Order received' ).first()
82+
).toBeVisible();
83+
84+
// Disable card testing protection if necessary.
85+
if ( cardTestingPreventionEnabled ) {
86+
await devtools.disableCardTestingProtection( merchantPage );
87+
}
88+
} );
89+
}
90+
);
91+
} );

tests/e2e-pw/utils/devtools.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { Page, expect } from '@playwright/test';
5+
6+
const goToDevToolsSettings = ( page: Page ) =>
7+
page.goto( 'wp-admin/admin.php?page=wcpaydev', {
8+
waitUntil: 'load',
9+
} );
10+
11+
const saveDevToolsSettings = async ( page: Page ) => {
12+
await page.getByRole( 'button', { name: 'Save Changes' } ).click();
13+
expect( page.getByText( /Settings saved/ ) ).toBeVisible();
14+
};
15+
16+
const getIsCardTestingProtectionEnabled = ( page: Page ) =>
17+
page.getByLabel( 'Card testing mitigations enabled' ).isChecked();
18+
19+
const toggleCardTestingProtection = ( page: Page ) =>
20+
page
21+
.locator( 'label[for="wcpaydev_force_card_testing_protection_on"]' )
22+
.click();
23+
24+
export const enableCardTestingProtection = async ( page: Page ) => {
25+
await goToDevToolsSettings( page );
26+
27+
if ( ! ( await getIsCardTestingProtectionEnabled( page ) ) ) {
28+
await toggleCardTestingProtection( page );
29+
await saveDevToolsSettings( page );
30+
}
31+
};
32+
33+
export const disableCardTestingProtection = async ( page: Page ) => {
34+
await goToDevToolsSettings( page );
35+
36+
if ( await getIsCardTestingProtectionEnabled( page ) ) {
37+
await toggleCardTestingProtection( page );
38+
await saveDevToolsSettings( page );
39+
}
40+
};

tests/e2e/specs/wcpay/shopper/shopper-pay-for-order.spec.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)