Skip to content

Commit

Permalink
Misc e2e test fixes (#44325)
Browse files Browse the repository at this point in the history
* Change local workers to 1

* Add helpers for adding shipping

* Add shipping zone before order

* Fix tax assertion

* Fix assertion

* Tightened up locators

* Dismiss tour if visible

* Back to function

* Update tax label

* Enable shipping

* Update locator

* Changelog

---------

Co-authored-by: Jon Lane <jon.lane@automattic.com>
  • Loading branch information
2 people authored and samueljseay committed Feb 6, 2024
1 parent 6fb67ee commit 98fd803
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 26 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-e2e-test-fixes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Misc e2e test fixes
2 changes: 1 addition & 1 deletion plugins/woocommerce/tests/e2e-pw/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const config = {
testDir: 'tests',
retries: CI ? 2 : 0,
repeatEach: REPEAT_EACH ? Number( REPEAT_EACH ) : 1,
workers: CI ? 1 : 4,
workers: 1,
reporter: [
[ 'list' ],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ test.describe( 'WooCommerce Shipping Settings - Add new shipping zone', () => {
await page.goto(
'wp-admin/admin.php?page=wc-settings&tab=shipping'
);

try {
await page
.getByLabel( 'Close Tour' )
.click( { timeout: 5000 } ); // close the tour if visible
} catch ( e ) {}

await page.reload(); // Playwright runs so fast, the location shows up as "Everywhere" at first
}
await expect( page.locator( '.wc-shipping-zones' ) ).toHaveText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;

async function dismissFeedbackModalIfShown( page ) {
try {
await page.getByText( 'Skip' ).nth( 3 ).click( { timeout: 5000 } );
await page
.getByRole( 'button', { name: 'Skip' } )
.click( { timeout: 10000 } );
} catch ( error ) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: '$125.00 (includes $25.00 Nasty Tax)',
name: '$125.00 (includes $25.00 Tax)',
} )
).toBeVisible();
} );
Expand All @@ -182,7 +182,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Total $125.00 (includes $25.00 Nasty Tax)',
name: 'Total $125.00 (includes $25.00 Tax)',
} )
).toBeVisible();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const includedCategoryName = 'Included Category';
const excludedCategoryName = 'Excluded Category';

test.describe( 'Cart & Checkout Restricted Coupons', () => {
let firstProductId, secondProductId, firstCategoryId, secondCategoryId;
let firstProductId,
secondProductId,
firstCategoryId,
secondCategoryId,
shippingZoneId;
const couponBatchId = [];

test.beforeAll( async ( { baseURL } ) => {
Expand All @@ -26,6 +30,17 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
await api.put( 'payment_gateways/cod', {
enabled: true,
} );
// add a shipping zone and method
await api
.post( 'shipping/zones', {
name: 'Free Shipping',
} )
.then( ( response ) => {
shippingZoneId = response.data.id;
} );
await api.post( `shipping/zones/${ shippingZoneId }/methods`, {
method_id: 'free_shipping',
} );
// add categories
await api
.post( 'products/categories', {
Expand Down Expand Up @@ -162,6 +177,9 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
await api.put( 'payment_gateways/cod', {
enabled: false,
} );
await api.delete( `shipping/zones/${ shippingZoneId }`, {
force: true,
} );
} );

test( 'expired coupon cannot be used', async ( { page, context } ) => {
Expand Down Expand Up @@ -623,15 +641,19 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
page.getByText( 'Coupon code applied successfully.' )
).toBeVisible();

await page.getByLabel( 'First name' ).fill( 'Marge' );
await page.getByLabel( 'Last name' ).fill( 'Simpson' );
await page.getByLabel( 'First name' ).first().fill( 'Marge' );
await page.getByLabel( 'Last name' ).first().fill( 'Simpson' );
await page
.getByLabel( 'Street address' )
.first()
.fill( '123 Evergreen Terrace' );
await page.getByLabel( 'Town / City' ).fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).fill( '55555' );
await page.getByLabel( 'Phone' ).fill( '555-555-5555' );
await page.getByLabel( 'Email address' ).fill( 'marge@example.com' );
await page.getByLabel( 'Town / City' ).first().fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).first().fill( '55555' );
await page.getByLabel( 'Phone' ).first().fill( '555-555-5555' );
await page
.getByLabel( 'Email address' )
.first()
.fill( 'marge@example.com' );
await page.getByRole( 'button', { name: 'Place order' } ).click();

await expect(
Expand Down Expand Up @@ -665,15 +687,19 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
page.getByText( 'Coupon code applied successfully.' )
).toBeVisible();

await page.getByLabel( 'First name' ).fill( 'Homer' );
await page.getByLabel( 'Last name' ).fill( 'Simpson' );
await page.getByLabel( 'First name' ).first().fill( 'Homer' );
await page.getByLabel( 'Last name' ).first().fill( 'Simpson' );
await page
.getByLabel( 'Street address' )
.first()
.fill( '123 Evergreen Terrace' );
await page.getByLabel( 'Town / City' ).fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).fill( '55555' );
await page.getByLabel( 'Phone' ).fill( '555-555-5555' );
await page.getByLabel( 'Email address' ).fill( 'homer@example.com' );
await page.getByLabel( 'Town / City' ).first().fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).first().fill( '55555' );
await page.getByLabel( 'Phone' ).first().fill( '555-555-5555' );
await page
.getByLabel( 'Email address' )
.first()
.fill( 'homer@example.com' );
await page.getByRole( 'button', { name: 'Place order' } ).click();

await expect(
Expand All @@ -698,15 +724,19 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
page.getByText( 'Coupon code applied successfully.' )
).toBeVisible();

await page.getByLabel( 'First name' ).fill( 'Homer' );
await page.getByLabel( 'Last name' ).fill( 'Simpson' );
await page.getByLabel( 'First name' ).first().fill( 'Homer' );
await page.getByLabel( 'Last name' ).first().fill( 'Simpson' );
await page
.getByLabel( 'Street address' )
.first()
.fill( '123 Evergreen Terrace' );
await page.getByLabel( 'Town / City' ).fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).fill( '55555' );
await page.getByLabel( 'Phone' ).fill( '555-555-5555' );
await page.getByLabel( 'Email address' ).fill( 'homer@example.com' );
await page.getByLabel( 'Town / City' ).first().fill( 'Springfield' );
await page.getByLabel( 'ZIP Code' ).first().fill( '55555' );
await page.getByLabel( 'Phone' ).first().fill( '555-555-5555' );
await page
.getByLabel( 'Email address' )
.first()
.fill( 'homer@example.com' );
await page.getByRole( 'button', { name: 'Place order' } ).click();

await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ const { test, expect } = require( '@playwright/test' );
const { customer, storeDetails } = require( '../../test-data/data' );
const { api } = require( '../../utils' );

let productId, orderId;
let productId, orderId, zoneId;

const product = {
name: 'Order email product',
type: 'simple',
regular_price: '42.77',
};
const zoneInfo = {
name: 'Free shipping',
};
const methodInfo = {
method_id: 'free_shipping',
};

const storeName = 'WooCommerce Core E2E Test Suite';

Expand All @@ -18,6 +24,9 @@ test.describe( 'Shopper Order Email Receiving', () => {
test.beforeAll( async () => {
productId = await api.create.product( product );
await api.update.enableCashOnDelivery();

zoneId = await api.create.shippingZone( zoneInfo );
await api.create.shippingMethod( zoneId, methodInfo );
} );

test.beforeEach( async ( { page } ) => {
Expand Down Expand Up @@ -48,6 +57,8 @@ test.describe( 'Shopper Order Email Receiving', () => {
await api.deletePost.order( orderId );
}
await api.update.disableCashOnDelivery();

await api.deletePost.shippingZone( zoneId );
} );

test( 'should receive order email after purchasing an item', async ( {
Expand Down
13 changes: 13 additions & 0 deletions plugins/woocommerce/tests/e2e-pw/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ const create = {

return response.data.id;
},
shippingZone: async ( zone ) => {
const response = await api.post( 'shipping/zones', zone );

return response.data.id;
},
shippingMethod: async ( zoneId, method ) => {
const response = await api.post(
`shipping/zones/${ zoneId }/methods`,
method
);

return response.data.id;
},
/**
* Batch create product variations.
*
Expand Down
4 changes: 2 additions & 2 deletions plugins/woocommerce/tests/e2e-pw/utils/simple-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ async function clickAddNewMenuItem( page ) {
*/
async function expectOldProductEditor( page ) {
await expect(
page.locator( '#woocommerce-product-data h2' )
).toContainText( 'Product data' );
page.getByRole( 'heading', { name: 'Product data' } )
).toBeVisible();
}

/**
Expand Down

0 comments on commit 98fd803

Please sign in to comment.