[Flaky Test] Wait for response across all requests, including on the checkout page (#51048)
* Wait for response across all requests, including on the checkout page * Add changefile(s) from automation for the following project(s): woocommerce * Update Docblock --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
115d4f16c9
commit
bdf8f2b1a4
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: tweak
|
||||||
|
Comment: Fixes flaky coupon tests.
|
||||||
|
|
|
@ -8,12 +8,16 @@ const excludedProductName = 'Excluded test product';
|
||||||
const includedCategoryName = 'Included Category';
|
const includedCategoryName = 'Included Category';
|
||||||
const excludedCategoryName = 'Excluded Category';
|
const excludedCategoryName = 'Excluded Category';
|
||||||
|
|
||||||
// This waits for the cart page to refresh after applying the coupon to prevent flakyness.
|
// This applies a coupon and waits for the result to prevent flakyness.
|
||||||
const awaitCartPageResponse = ( page ) =>
|
const applyCoupon = async ( page ) => {
|
||||||
page.waitForResponse(
|
const responsePromise = page.waitForResponse(
|
||||||
( response ) =>
|
( response ) =>
|
||||||
response.url().includes( '/cart/' ) && response.status() === 200
|
response.url().includes( '?wc-ajax=apply_coupon' ) &&
|
||||||
|
response.status() === 200
|
||||||
);
|
);
|
||||||
|
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
|
||||||
|
await responsePromise;
|
||||||
|
};
|
||||||
|
|
||||||
test.describe(
|
test.describe(
|
||||||
'Cart & Checkout Restricted Coupons',
|
'Cart & Checkout Restricted Coupons',
|
||||||
|
@ -202,10 +206,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'expired-coupon' );
|
.fill( 'expired-coupon' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'This coupon has expired.' )
|
page.getByText( 'This coupon has expired.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
@ -225,9 +226,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'expired-coupon' );
|
.fill( 'expired-coupon' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'This coupon has expired.' )
|
page.getByText( 'This coupon has expired.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
@ -245,10 +244,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'min-max-spend-individual' );
|
.fill( 'min-max-spend-individual' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// failed because we need to have at least $50 in cart (single product is only $20)
|
// failed because we need to have at least $50 in cart (single product is only $20)
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -264,10 +260,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'min-max-spend-individual' );
|
.fill( 'min-max-spend-individual' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
@ -277,10 +270,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
'Sorry, coupon "min-max-spend-individual" has already been applied and cannot be used in conjunction with other coupons.'
|
'Sorry, coupon "min-max-spend-individual" has already been applied and cannot be used in conjunction with other coupons.'
|
||||||
|
@ -302,9 +292,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'min-max-spend-individual' );
|
.fill( 'min-max-spend-individual' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// failed because we need to have at least $50 in cart (single product is only $20)
|
// failed because we need to have at least $50 in cart (single product is only $20)
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -325,9 +313,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'min-max-spend-individual' );
|
.fill( 'min-max-spend-individual' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
@ -342,9 +328,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
'Sorry, coupon "min-max-spend-individual" has already been applied and cannot be used in conjunction with other coupons.'
|
'Sorry, coupon "min-max-spend-individual" has already been applied and cannot be used in conjunction with other coupons.'
|
||||||
|
@ -364,10 +348,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// failed because this product is on sale.
|
// failed because this product is on sale.
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -390,9 +371,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// failed because this product is on sale
|
// failed because this product is on sale
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -449,10 +428,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// failed because this coupon code has been used too much
|
// failed because this coupon code has been used too much
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -475,9 +451,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'no-sale-use-limit' );
|
.fill( 'no-sale-use-limit' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// failed because this coupon code has been used too much
|
// failed because this coupon code has been used too much
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -502,10 +476,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// failed because this product is not included for coupon
|
// failed because this product is not included for coupon
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -528,9 +499,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// failed because this product is not included for coupon
|
// failed because this product is not included for coupon
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -551,10 +520,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// succeeded
|
// succeeded
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
|
@ -575,9 +541,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// succeeded
|
// succeeded
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
|
@ -596,10 +560,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// failed because this product is excluded from coupon
|
// failed because this product is excluded from coupon
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -622,9 +583,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// failed because this product is excluded from coupon
|
// failed because this product is excluded from coupon
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
|
@ -645,10 +604,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
// succeeded
|
// succeeded
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
|
@ -669,9 +625,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'product-and-category-included' );
|
.fill( 'product-and-category-included' );
|
||||||
await page
|
await applyCoupon( page );
|
||||||
.getByRole( 'button', { name: 'Apply coupon' } )
|
|
||||||
.click();
|
|
||||||
// succeeded
|
// succeeded
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
|
@ -688,8 +642,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'email-restricted' );
|
.fill( 'email-restricted' );
|
||||||
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
|
await applyCoupon( page );
|
||||||
await awaitCartPageResponse( page );
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
'Please enter a valid email at checkout to use coupon code "email-restricted".'
|
'Please enter a valid email at checkout to use coupon code "email-restricted".'
|
||||||
|
@ -727,8 +680,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'email-restricted' );
|
.fill( 'email-restricted' );
|
||||||
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
|
await applyCoupon( page );
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(
|
||||||
'Please enter a valid email to use coupon code "email-restricted".'
|
'Please enter a valid email to use coupon code "email-restricted".'
|
||||||
|
@ -774,7 +726,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'email-restricted' );
|
.fill( 'email-restricted' );
|
||||||
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
|
await applyCoupon( page );
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
@ -814,7 +766,7 @@ test.describe(
|
||||||
await page
|
await page
|
||||||
.getByPlaceholder( 'Coupon code' )
|
.getByPlaceholder( 'Coupon code' )
|
||||||
.fill( 'email-restricted' );
|
.fill( 'email-restricted' );
|
||||||
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
|
await applyCoupon( page );
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText( 'Coupon code applied successfully.' )
|
page.getByText( 'Coupon code applied successfully.' )
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
|
Loading…
Reference in New Issue