Skip to content

Commit 7f8f392

Browse files
authored
chore(e2e): Attempt to fix flakiness (#6792)
1 parent bdbc3ce commit 7f8f392

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.changeset/curly-hats-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/testing': patch
3+
---
4+
5+
Improve reliability of checkout testing helpers.

integration/tests/pricing-table.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
306306
.getByText(/Trial/i)
307307
.locator('xpath=..')
308308
.getByText(/Free trial/i),
309-
).toBeVisible();
309+
).toBeVisible({ timeout: 15000 });
310310

311-
await expect(u.po.page.getByText(/Trial ends/i)).toBeVisible();
311+
await expect(u.po.page.getByText(/Trial ends/i)).toBeVisible({ timeout: 15000 });
312312

313313
await u.po.page.getByRole('button', { name: 'Manage' }).first().click();
314314
await u.po.subscriptionDetails.waitForMounted();
@@ -573,8 +573,10 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
573573
await u.po.checkout.waitForMounted();
574574
await u.po.checkout.closeDrawer();
575575

576-
await u.po.checkout.waitForMounted();
576+
// Ensure the checkout gets hidden before opening again to force revalidation
577+
await u.po.checkout.root.waitFor({ state: 'hidden' });
577578
await u.po.pricingTable.startCheckout({ planSlug: 'plus', period: 'monthly' });
579+
await u.po.checkout.waitForMounted();
578580
await u.po.checkout.fillTestCard();
579581
await u.po.checkout.clickPayOrSubscribe();
580582
await u.po.checkout.confirmAndContinue();

packages/testing/src/playwright/unstable/page-objects/checkout.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const createCheckoutPageObject = (testArgs: { page: EnhancedPage }) => {
66
const self = {
77
...common(testArgs),
88
waitForMounted: (selector = '.cl-checkout-root') => {
9-
return page.waitForSelector(selector, { state: 'attached' });
9+
return page.waitForSelector(selector, { state: 'attached', timeout: 20000 });
1010
},
1111
closeDrawer: () => {
1212
return page.locator('.cl-drawerClose').click();
@@ -21,6 +21,7 @@ export const createCheckoutPageObject = (testArgs: { page: EnhancedPage }) => {
2121
});
2222
},
2323
fillCard: async (card: { number: string; expiration: string; cvc: string; country: string; zip: string }) => {
24+
await self.waitForStripeElements({ state: 'visible' });
2425
const frame = page.frameLocator('iframe[src*="elements-inner-payment"]');
2526
await frame.getByLabel('Card number').fill(card.number);
2627
await frame.getByLabel('Expiration date').fill(card.expiration);
@@ -29,7 +30,19 @@ export const createCheckoutPageObject = (testArgs: { page: EnhancedPage }) => {
2930
await frame.getByLabel('ZIP code').fill(card.zip);
3031
},
3132
waitForStripeElements: async ({ state = 'visible' }: { state?: 'visible' | 'hidden' } = {}) => {
32-
return page.frameLocator('iframe[src*="elements-inner-payment"]').getByLabel('Card number').waitFor({ state });
33+
const iframe = page.locator('iframe[src*="elements-inner-payment"]');
34+
if (state === 'visible') {
35+
await iframe.waitFor({ state: 'attached', timeout: 20000 });
36+
await page.frameLocator('iframe[src*="elements-inner-payment"]').getByLabel('Card number').waitFor({
37+
state: 'visible',
38+
timeout: 20000,
39+
});
40+
} else {
41+
await page.frameLocator('iframe[src*="elements-inner-payment"]').getByLabel('Card number').waitFor({
42+
state: 'hidden',
43+
timeout: 20000,
44+
});
45+
}
3346
},
3447
clickPayOrSubscribe: async () => {
3548
await self.root.getByRole('button', { name: /subscribe|pay\s\$|start/i }).click();

0 commit comments

Comments
 (0)