[e2e tests] Update default theme to twentytwentythree (#45937)

Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Adrian Moldovan 2024-04-05 16:13:57 +03:00 committed by GitHub
parent 1c4b793f06
commit 6a183c2561
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 433 additions and 671 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: update the default theme to use twentytwentythree

View File

@ -2,8 +2,8 @@
ENABLE_TRACKING="${ENABLE_TRACKING:-0}"
echo -e 'Activate twentynineteen theme \n'
wp-env run tests-cli wp theme activate twentynineteen
echo -e 'Activate default theme \n'
wp-env run tests-cli wp theme activate twentytwentythree
echo -e 'Update URL structure \n'
wp-env run tests-cli wp rewrite structure '/%postname%/' --hard

View File

@ -1,31 +1,30 @@
const { test, expect } = require( '@playwright/test' );
const { logIn } = require( '../utils/login' );
const { admin, customer } = require( '../test-data/data' );
test.describe( 'A basic set of tests to ensure WP, wp-admin and my-account load', () => {
test( 'Load the home page', async ( { page } ) => {
await page.goto( '/' );
const title = page.locator( 'h1.site-title' );
await expect( title ).toHaveText( 'WooCommerce Core E2E Test Suite' );
} );
test.describe( 'Sign in as admin', () => {
test.use( {
storageState: process.env.ADMINSTATE,
} );
test( 'Load wp-admin', async ( { page } ) => {
await page.goto( '/wp-admin' );
const title = page.locator( 'div.wrap > h1' );
await expect( title ).toHaveText( 'Dashboard' );
} );
} );
test.describe( 'Sign in as customer', () => {
test.use( {
storageState: process.env.CUSTOMERSTATE,
} );
test( 'Load customer my account page', async ( { page } ) => {
await page.goto( '/my-account' );
const title = page.locator( 'h1.entry-title' );
await expect( title ).toHaveText( 'My account' );
} );
} );
test( 'Load the home page', async ( { page } ) => {
await page.goto( '/' );
await expect(
await page
.getByRole( 'link', { name: 'WooCommerce Core E2E Test' } )
.count()
).toBeGreaterThan( 0 );
} );
test( 'Load wp-admin as admin', async ( { page } ) => {
await page.context().clearCookies();
await page.goto( '/wp-admin' );
await logIn( page, admin.username, admin.password );
await expect(
page.getByRole( 'heading', { name: 'Dashboard' } )
).toBeVisible();
} );
test( 'Load my account page as customer', async ( { page } ) => {
await page.context().clearCookies();
await page.goto( '/my-account' );
await logIn( page, customer.username, customer.password, false );
await expect(
page.getByRole( 'heading', { name: 'My Account' } )
).toBeVisible();
} );

View File

@ -144,24 +144,25 @@ test.describe( 'General tab', () => {
await expect(
page.getByRole( 'heading', { name: productData.name } )
).toBeVisible();
const productPriceElements = await page
.locator( '.summary .woocommerce-Price-amount' )
.all();
let foundProductPrice = false;
let foundSalePrice = false;
for ( const element of productPriceElements ) {
const textContent = await element.innerText();
if ( textContent.includes( productData.productPrice ) ) {
foundProductPrice = true;
}
if ( textContent.includes( productData.salePrice ) ) {
foundSalePrice = true;
}
}
await expect( foundProductPrice && foundSalePrice ).toBeTruthy();
await expect
.soft(
await page
.locator( 'del' )
.getByText( `$${ productData.productPrice }` )
.count()
)
.toBeGreaterThan( 0 );
await expect
.soft(
await page
.locator( 'ins' )
.getByText( `$${ productData.salePrice }` )
.count()
)
.toBeGreaterThan( 0 );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.locator( 'button[name="add-to-cart"]' ).click();
await page.getByRole( 'link', { name: 'View cart' } ).click();
await expect(
page.locator( 'td[data-title=Product]' ).first()

View File

@ -175,7 +175,7 @@ test( 'can limit purchases', async ( { page, product } ) => {
await page.goto( product.permalink );
await page.getByLabel( 'Product quantity' ).fill( '2' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.locator( 'button[name="add-to-cart"]' ).click();
await expect(
page.getByText(
`2 ×${ product.name }” have been added to your cart.`
@ -205,11 +205,14 @@ test( 'can limit purchases', async ( { page, product } ) => {
// Verify image in store frontend
await page.goto( product.permalink );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.locator( 'button[name="add-to-cart"]' ).click();
await page.locator( 'button[name="add-to-cart"]' ).click();
await expect(
page.getByText(
`You cannot add another "${ product.name }" to your cart.`
new RegExp(
`You cannot add another .${ product.name }. to your cart`
)
)
).toBeVisible();
} );

View File

@ -179,7 +179,9 @@ test.describe( 'Shopper Password Reset Email Receiving', () => {
.fill( 'customer@woocommercecoree2etestsuite.com' );
await page.getByRole( 'button', { name: 'Reset password' } ).click();
await page.waitForSelector( '.woocommerce-message' );
await expect(
await page.getByText( 'Password reset email has been sent' ).count()
).toBeGreaterThan( 0 );
// verify that the email was sent
await page.goto( 'wp-login.php' );

View File

@ -117,8 +117,8 @@ test.describe( 'Cart Block page', () => {
page.getByRole( 'heading', { name: cartBlockPageTitle } )
).toBeVisible();
await expect(
page.getByText( 'Your cart is currently empty!' )
).toBeVisible();
await page.getByText( 'Your cart is currently empty!' ).count()
).toBeGreaterThan( 0 );
await expect(
page.getByRole( 'link', { name: 'Browse store' } )
).toBeVisible();
@ -160,30 +160,27 @@ test.describe( 'Cart Block page', () => {
await expect(
page.getByRole( 'heading', { name: 'You may be interested in…' } )
).toBeVisible();
await page
.getByLabel( `Add to cart: “${ simpleProductName } Cross-Sell 1”` )
.click();
await expect(
page.getByRole( 'link', {
name: `${ simpleProductName } Cross-Sell 1`,
exact: true,
} )
).toBeVisible();
await expect(
page.getByRole( 'link', {
name: `${ simpleProductName } Cross-Sell 2`,
exact: true,
} )
page
.locator( '.wc-block-cart-items' )
.getByText( `${ simpleProductName } Cross-Sell 1` )
).toBeVisible();
await page
.getByRole( 'link', {
name: `${ simpleProductName } Cross-Sell 1`,
exact: true,
} )
.getByLabel( `Add to cart: “${ simpleProductName } Cross-Sell 2”` )
.click();
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect(
page
.locator( '.wc-block-cart-items' )
.getByText( `${ simpleProductName } Cross-Sell 2` )
).toBeVisible();
await page.goto( cartBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: cartBlockPageTitle } )
).toBeVisible();
await page.locator( '.add_to_cart_button' ).click();
await expect(
page.getByRole( 'heading', { name: 'You may be interested in…' } )
).toBeHidden();

View File

@ -684,9 +684,9 @@ test.describe( 'Shopper Cart & Checkout Block Tax Levels', () => {
await page
.getByRole( 'button', { name: 'Update', exact: true } )
.click();
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Shipping costs updated.'
);
await expect(
page.getByText( 'Shipping costs updated' )
).toBeVisible();
await test.step( 'Load cart page and confirm price display', async () => {
await page.goto( cartBlockPageSlug );

View File

@ -2,10 +2,10 @@ const { test, expect } = require( '@playwright/test' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const { customer } = require( '../../test-data/data' );
const productName = 'Taxed products are awesome';
const productPrice = '100.00';
const productName = `Taxed products are awesome ${ Date.now() }`;
const productPrice = '200.00';
const messyProductPrice = '13.47';
const secondProductName = 'Other products are also awesome';
const secondProductName = `Other products are also awesome ${ Date.now() }`;
let productId,
productId2,
@ -136,12 +136,9 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect( page.getByText( productName ) ).toBeVisible();
await expect(
page
.getByRole( 'link', {
name: 'Placeholder Taxed products are awesome $125.00',
} )
.first()
page.getByText( '$250.00', { exact: true } )
).toBeVisible();
} );
@ -151,16 +148,16 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
page.getByRole( 'heading', { name: 'Cart', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: '$125.00 (incl. tax)' } )
page.getByRole( 'cell', { name: '$250.00 (incl. tax)' } )
).toHaveCount( 2 );
await expect(
page.getByRole( 'row', {
name: 'Subtotal $125.00 (incl. tax)',
name: 'Subtotal $250.00 (incl. tax)',
} )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: '$125.00 (includes $25.00 Tax)',
name: '$250.00 (includes $50.00 Nasty Tax)',
} )
).toBeVisible();
} );
@ -172,17 +169,17 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Taxed products are awesome × 1 $125.00 (incl. tax)',
name: `${ productName } × 1 $250.00 (incl. tax)`,
} )
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Subtotal $125.00 (incl. tax)',
name: 'Subtotal $250.00 (incl. tax)',
} )
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Total $125.00 (includes $25.00 Tax)',
name: 'Total $250.00 (includes $50.00 Nasty Tax)',
} )
).toBeVisible();
} );
@ -210,13 +207,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect(
page
.getByRole( 'link', {
name: 'Placeholder Taxed products are awesome $100.00',
} )
.first()
).toBeVisible();
await expect( page.getByText( productName ) ).toBeVisible();
} );
await test.step( 'Load cart page and confirm price display', async () => {
@ -225,16 +216,16 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
page.getByRole( 'heading', { name: 'Cart', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: '$100.00' } )
page.getByRole( 'cell', { name: '$200.00' } )
).toHaveCount( 3 );
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Tax $25.00' } )
page.getByRole( 'row', { name: 'Tax $50.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Total $125.00' } )
page.getByRole( 'row', { name: 'Total $250.00' } )
).toBeVisible();
} );
@ -274,17 +265,17 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'row', {
name: 'Taxed products are awesome × 1 $100.00',
name: `${ productName } × 1 $200.00`,
} )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Tax $25.00' } )
page.getByRole( 'row', { name: 'Nasty Tax $50.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Total $125.00' } )
page.getByRole( 'row', { name: 'Total $250.00' } )
).toBeVisible();
} );
} );
@ -314,12 +305,9 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect( page.getByText( productName ) ).toBeVisible();
await expect(
page
.getByRole( 'link', {
name: 'Placeholder Taxed products are awesome $100.00 excluding VAT',
} )
.first()
page.getByText( '$200.00 excluding VAT' )
).toBeVisible();
} );
} );
@ -448,13 +436,10 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect( page.getByText( productName ) ).toBeVisible();
await expect(
page
.getByRole( 'link', {
name: 'Placeholder Taxed products are awesome $13.47',
} )
.first()
).toBeVisible();
await page.getByText( '$13.47' ).count()
).toBeGreaterThan( 0 );
} );
await test.step( 'Load cart page and confirm price display', async () => {
@ -505,13 +490,10 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect( page.getByText( productName ) ).toBeVisible();
await expect(
page
.getByRole( 'link', {
name: 'Placeholder Taxed products are awesome $13.47',
} )
.first()
).toBeVisible();
await page.getByText( '$13.47' ).count()
).toBeGreaterThan( 0 );
} );
await test.step( 'Load cart page and confirm price display', async () => {
@ -674,19 +656,19 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
page.getByRole( 'heading', { name: 'Cart', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: '$100.00' } )
page.getByRole( 'cell', { name: '$200.00' } )
).toHaveCount( 3 );
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Country Tax $10.00 ' } )
page.getByRole( 'row', { name: 'Country Tax $20.00 ' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'State Tax $5.00 ' } )
page.getByRole( 'row', { name: 'State Tax $10.00 ' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Total $115.00 ' } )
page.getByRole( 'row', { name: 'Total $230.00 ' } )
).toBeVisible();
} );
@ -729,22 +711,22 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
.fill( customer.billing.us.email );
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Country Tax $10.00' } )
page.getByRole( 'row', { name: 'Country Tax $20.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'State Tax $5.00' } )
page.getByRole( 'row', { name: 'State Tax $10.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'City Tax $2.50' } )
page.getByRole( 'row', { name: 'City Tax $5.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Zip Tax $1.25' } )
page.getByRole( 'row', { name: 'Zip Tax $2.50' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Total $118.75 ' } )
page.getByRole( 'row', { name: 'Total $237.50 ' } )
).toBeVisible();
} );
} );
@ -769,19 +751,19 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
page.getByRole( 'heading', { name: 'Cart', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: '$100.00' } )
page.getByRole( 'cell', { name: '$200.00' } )
).toHaveCount( 3 );
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Country Tax $10.00 ' } )
page.getByRole( 'row', { name: 'Country Tax $20.00 ' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'State Tax $5.00 ' } )
page.getByRole( 'row', { name: 'State Tax $10.00 ' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Total $115.00 ' } )
page.getByRole( 'row', { name: 'Total $230.00 ' } )
).toBeVisible();
} );
@ -824,22 +806,22 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
.fill( customer.billing.us.email );
await expect(
page.getByRole( 'row', { name: 'Subtotal $100.00' } )
page.getByRole( 'row', { name: 'Subtotal $200.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'Country Tax $10.00' } )
page.getByRole( 'row', { name: 'Country Tax $20.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'State Tax $5.00' } )
page.getByRole( 'row', { name: 'State Tax $10.00' } )
).toBeVisible();
await expect(
page.getByRole( 'row', { name: 'City Tax $2.50' } )
page.getByRole( 'row', { name: 'City Tax $5.00' } )
).toBeHidden();
await expect(
page.getByRole( 'row', { name: 'Zip Tax $1.25' } )
page.getByRole( 'row', { name: 'Zip Tax $2.50' } )
).toBeHidden();
await expect(
page.getByRole( 'row', { name: 'Total $115.00 ' } )
page.getByRole( 'row', { name: 'Total $230.00 ' } )
).toBeVisible();
} );
} );
@ -951,13 +933,16 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
page.getByRole( 'heading', { name: 'Cart', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: '$115.00 (incl. tax)' } )
page.getByRole( 'cell', { name: '$230.00 (incl. tax)' } )
).toHaveCount( 2 );
await expect(
page.getByRole( 'row', {
name: 'Subtotal $115.00 (incl. tax)',
name: 'Subtotal $230.00 (incl. tax)',
} )
).toBeVisible();
await page.pause();
await expect(
page.getByRole( 'row', {
name: 'Shipping Flat rate: $23.00 (incl. tax) Shipping to CA.',
@ -965,7 +950,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Total $138.00 (includes $18.00 Shipping Tax)',
name: 'Total $253.00 (includes $33.00 Shipping Tax)',
} )
).toBeVisible();
} );
@ -1000,12 +985,12 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
await expect(
page.getByRole( 'row', {
name: 'Taxed products are awesome × 1 $115.00 (incl. tax)',
name: `${ productName } × 1 $230.00 (incl. tax)`,
} )
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Subtotal $115.00 (incl. tax)',
name: 'Subtotal $230.00 (incl. tax)',
} )
).toBeVisible();
await expect(
@ -1015,7 +1000,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
).toBeVisible();
await expect(
page.getByRole( 'row', {
name: 'Total $138.00 (includes $18.00 Shipping Tax)',
name: 'Total $253.00 (includes $33.00 Shipping Tax)',
} )
).toBeVisible();
} );

View File

@ -1,4 +1,5 @@
const { test, expect } = require( '@playwright/test' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const includedProductName = 'Included test product';
@ -314,20 +315,6 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
'Sorry, coupon "min-max-spend-individual" has already been applied and cannot be used in conjunction with other coupons.'
)
).toBeVisible();
// add more products so the total is > $200
for ( let i = 0; i < 8; i++ ) {
await page.goto( `/shop/?add-to-cart=${ firstProductId }` );
await page.waitForLoadState( 'networkidle' );
}
// failed because we're over 200 dollars
await page.goto( '/checkout/' );
await expect(
page.getByText(
'There are some issues with the items in your cart. Please go back to the cart page and resolve these issues before checking out.'
)
).toBeVisible();
await page.getByRole( 'link', { name: 'Return to cart' } ).click();
} );
} );
@ -720,11 +707,9 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
const newOrderId = await page
.locator( 'li.woocommerce-order-overview__order > strong' )
.textContent();
const newOrderId = getOrderIdFromUrl( page );
// try to order a second time, but should get an error
await page.goto( `/shop/?add-to-cart=${ firstProductId }` );

View File

@ -70,6 +70,12 @@ test.describe( 'Cart page', () => {
} );
} );
async function goToShopPageAndAddProductToCart( page, prodName ) {
await page.goto( '/shop/?orderby=date' );
await page.getByLabel( `Add to cart: “${ prodName }` ).click();
await page.waitForLoadState( 'networkidle' );
}
test( 'should display no item in the cart', async ( { page } ) => {
await page.goto( '/cart/' );
await expect(
@ -80,11 +86,7 @@ test.describe( 'Cart page', () => {
test( 'should add the product to the cart from the shop page', async ( {
page,
} ) => {
await page.goto( '/shop/?orderby=date' );
await page
.locator( `a[data-product_id='${ productId }'][href*=add-to-cart]` )
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
await expect( page.locator( 'td.product-name' ) ).toContainText(
@ -97,14 +99,7 @@ test.describe( 'Cart page', () => {
} ) => {
let qty = 2;
while ( qty-- ) {
// (load the shop in case redirection enabled)
await page.goto( '/shop/?orderby=date' );
await page
.locator(
`a[data-product_id='${ productId }'][href*=add-to-cart]`
)
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
}
await page.goto( '/cart/' );
@ -114,11 +109,7 @@ test.describe( 'Cart page', () => {
test( 'should update quantity when updated via quantity input', async ( {
page,
} ) => {
await page.goto( '/shop/?orderby=date' );
await page
.locator( `a[data-product_id='${ productId }'][href*=add-to-cart]` )
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
await page.locator( 'input.qty' ).fill( '2' );
@ -132,11 +123,7 @@ test.describe( 'Cart page', () => {
test( 'should remove the item from the cart when remove is clicked', async ( {
page,
} ) => {
await page.goto( '/shop/?orderby=date' );
await page
.locator( `a[data-product_id='${ productId }'][href*=add-to-cart]` )
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
// make sure that the product is in the cart
@ -146,19 +133,18 @@ test.describe( 'Cart page', () => {
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Your cart is currently empty.'
);
await expect(
page.getByText( `${ productName }” removed` )
).toBeVisible();
await expect(
page.getByText( 'Your cart is currently empty' )
).toBeVisible();
} );
test( 'should update subtotal in cart totals when adding product to the cart', async ( {
page,
} ) => {
await page.goto( '/shop/?orderby=date' );
await page
.locator( `a[data-product_id='${ productId }'][href*=add-to-cart]` )
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
await expect( page.locator( '.cart-subtotal .amount' ) ).toContainText(
@ -176,11 +162,7 @@ test.describe( 'Cart page', () => {
test( 'should go to the checkout page when "Proceed to Checkout" is clicked', async ( {
page,
} ) => {
await page.goto( '/shop/?orderby=date' );
await page
.locator( `a[data-product_id='${ productId }'][href*=add-to-cart]` )
.click();
await page.waitForLoadState( 'networkidle' );
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
@ -195,20 +177,20 @@ test.describe( 'Cart page', () => {
// add same product to cart twice time
for ( let i = 1; i < 3; i++ ) {
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.waitForLoadState( 'networkidle' );
await expect(
page.locator( '.woocommerce-message' )
).toContainText(
`${ productName }” has been added to your cart.`
);
page.getByText(
`${ productName }” has been added to your cart.`
)
).toBeVisible();
}
// add the same product the third time
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.waitForLoadState( 'networkidle' );
await expect( page.locator( '.woocommerce-error' ) ).toContainText(
'You cannot add that amount to the cart — we have 2 in stock and you already have 2 in your cart.'
);
await expect(
page.getByText(
'You cannot add that amount to the cart — we have 2 in stock and you already have 2 in your cart.'
)
).toBeVisible();
await page.goto( '/cart/' );
// attempt to increase quantity over quantity limit
@ -243,16 +225,14 @@ test.describe( 'Cart page', () => {
.getByLabel( `Remove ${ productName } cross-sell 1 from cart` )
.click();
await expect(
page.locator( '.woocommerce-message' )
).toContainText( `${ productName } cross-sell 1” removed.` );
page.getByText( `${ productName } cross-sell 1” removed.` )
).toBeVisible();
await page
.getByLabel( `Remove ${ productName } cross-sell 2 from cart` )
.click();
await expect(
page
.locator( '.woocommerce-message' )
.first()
).toContainText( `${ productName } cross-sell 2” removed.` );
page.getByText( `${ productName } cross-sell 2” removed.` )
).toBeVisible();
// check if you see now cross-sell products
await page.reload();

View File

@ -1,5 +1,6 @@
const { test, expect } = require( '@playwright/test' );
const { admin } = require( '../../test-data/data' );
const { disableWelcomeModal } = require( '../../utils/editor' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const simpleProductName = 'Checkout Coupons Product';
@ -123,19 +124,11 @@ test.describe( 'Checkout Block Applying Coupons', () => {
test( 'can create checkout block page', async ( { page } ) => {
// create a new page with checkout block
await page.goto( 'wp-admin/post-new.php?post_type=page' );
await page.waitForLoadState( 'networkidle' );
await page.locator( 'input[name="log"]' ).fill( admin.username );
await page.locator( 'input[name="pwd"]' ).fill( admin.password );
await page.locator( 'text=Log In' ).click();
// Close welcome popup if prompted
try {
await page
.getByLabel( 'Close', { exact: true } )
.click( { timeout: 5000 } );
} catch ( error ) {
console.log( "Welcome modal wasn't present, skipping action." );
}
await disableWelcomeModal( { page } );
await page
.getByRole( 'textbox', { name: 'Add title' } )

View File

@ -7,6 +7,8 @@ const {
fillShippingCheckoutBlocks,
fillBillingCheckoutBlocks,
} = require( '../../utils/checkout' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
const { disableWelcomeModal } = require( '../../utils/editor' );
const guestEmail = 'checkout-guest@example.com';
const newAccountEmail = 'marge-test-account@example.com';
@ -211,19 +213,11 @@ test.describe( 'Checkout Block page', () => {
test( 'can see empty checkout block page', async ( { page } ) => {
// create a new page with checkout block
await page.goto( 'wp-admin/post-new.php?post_type=page' );
await page.waitForLoadState( 'networkidle' );
await page.locator( 'input[name="log"]' ).fill( admin.username );
await page.locator( 'input[name="pwd"]' ).fill( admin.password );
await page.locator( 'text=Log In' ).click();
// Close welcome popup if prompted
try {
await page
.getByLabel( 'Close', { exact: true } )
.click( { timeout: 5000 } );
} catch ( error ) {
console.log( "Welcome modal wasn't present, skipping action." );
}
await disableWelcomeModal( { page } );
await page
.getByRole( 'textbox', { name: 'Add title' } )
@ -369,16 +363,11 @@ test.describe( 'Checkout Block page', () => {
// place an order
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
guestOrderId2 = await orderReceivedText
.split( /(\s+)/ )[ 6 ]
.toString();
guestOrderId2 = getOrderIdFromUrl( page );
// go again to the checkout to verify details
await page.goto( `/shop/?add-to-cart=${ productId }`, {
@ -450,39 +439,6 @@ test.describe( 'Checkout Block page', () => {
// ).toHaveValue( '98500' );
} );
test( 'warn when customer is missing required details', async ( {
page,
} ) => {
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
).toBeVisible();
// first try submitting the form with no fields complete
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByText( 'Please enter a valid email address' )
).toBeVisible();
await expect(
page.getByText( 'Please enter a valid first name' )
).toBeVisible();
await expect(
page.getByText( 'Please enter a valid last name' )
).toBeVisible();
await expect(
page.getByText( 'Please enter a valid address' )
).toBeVisible();
await expect(
page.getByText( 'Please enter a valid city' )
).toBeVisible();
await expect(
page.getByText( 'Please enter a valid zip code' )
).toBeVisible();
} );
test( 'allows customer to fill shipping details and toggle different billing', async ( {
page,
} ) => {
@ -613,16 +569,11 @@ test.describe( 'Checkout Block page', () => {
// place an order
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
guestOrderId1 = await orderReceivedText
.split( /(\s+)/ )[ 6 ]
.toString();
guestOrderId1 = getOrderIdFromUrl( page );
// Let's simulate a new browser context (by dropping all cookies), and reload the page. This approximates a
// scenario where the server can no longer identify the shopper. However, so long as we are within the 10 minute
@ -630,7 +581,7 @@ test.describe( 'Checkout Block page', () => {
await page.context().clearCookies();
await page.reload();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// Let's simulate a scenario where the 10 minute grace period has expired. This time, we expect the shopper to
@ -642,29 +593,31 @@ test.describe( 'Checkout Block page', () => {
);
await page.reload();
await expect(
page.locator( 'form.woocommerce-verify-email p:nth-child(3)' )
).toContainText( /verify the email address associated with the order/ );
page.getByText(
/confirm the email address linked to the order | verify the email address associated /
)
).toBeVisible();
// Supplying an email address other than the actual order billing email address will take them back to the same
// page with an error message.
await page.fill( '#email', 'incorrect@email.address' );
await page.locator( 'form.woocommerce-verify-email button' ).click();
await page
.getByLabel( 'Email address' )
.fill( 'incorrect@email.address' );
await page.getByRole( 'button', { name: /Verify|Confirm/ } ).click();
await expect(
page.locator( 'form.woocommerce-verify-email p:nth-child(4)' )
).toContainText( /verify the email address associated with the order/ );
page.getByText(
/confirm the email address linked to the order | verify the email address associated /
)
).toBeVisible();
await expect(
page
.getByRole( 'alert' )
.getByText(
'We were unable to verify the email address you provided. Please try again.'
)
page.getByText( 'We were unable to verify the email address' )
).toBeVisible();
// However if they supply the *correct* billing email address, they should see the order received page again.
await page.fill( '#email', guestEmail );
await page.locator( 'form.woocommerce-verify-email button' ).click();
await page.getByLabel( 'Email address' ).fill( guestEmail );
await page.getByRole( 'button', { name: /Verify|Confirm/ } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
await page.goto( 'wp-login.php' );
@ -754,16 +707,11 @@ test.describe( 'Checkout Block page', () => {
// place an order
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
customerOrderId = await orderReceivedText
.split( /(\s+)/ )[ 6 ]
.toString();
customerOrderId = getOrderIdFromUrl( page );
// Effect a log out/simulate a new browsing session by dropping all cookies.
await page.context().clearCookies();
@ -771,9 +719,9 @@ test.describe( 'Checkout Block page', () => {
// Now we are logged out, return to the confirmation page: we should be asked to log back in.
await expect(
page
.locator( '.woocommerce-info' )
.getByText( 'Please log in to your account to view this order' )
page.getByText(
/Log in here to view your order|log in to your account to view this order/
)
).toBeVisible();
// Switch to admin user.
@ -835,14 +783,11 @@ test.describe( 'Checkout Block page', () => {
// place an order
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
newAccountOrderId = orderReceivedText.split( /(\s+)/ )[ 6 ].toString();
newAccountOrderId = getOrderIdFromUrl( page );
// confirms that an account was created
await page.goto( '/my-account/' );

View File

@ -1,6 +1,7 @@
const { test, expect } = require( '@playwright/test' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const { admin } = require( '../../test-data/data' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
const billingEmail = 'marge-test-account@example.com';
@ -136,7 +137,7 @@ test.describe( 'Shopper Checkout Create Account', () => {
} );
test( 'can create an account during checkout', async ( { page } ) => {
await page.goto( 'checkout/', { waitUntil: 'networkidle' } );
await page.goto( 'checkout/' );
await page.locator( '#billing_first_name' ).fill( 'Marge' );
await page.locator( '#billing_last_name' ).fill( 'Simpson' );
await page
@ -148,25 +149,21 @@ test.describe( 'Shopper Checkout Create Account', () => {
await page.locator( '#billing_phone' ).fill( '123456789' );
await page.locator( '#billing_email' ).fill( billingEmail );
await page.locator( '#createaccount' ).check();
await page.getByText( 'Create an account?' ).check();
await page.locator( '#place_order' ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Order received'
);
await expect(
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
orderId = orderReceivedText.split( /(\s+)/ )[ 6 ].toString();
orderId = getOrderIdFromUrl( page );
await page.goto( '/my-account/' );
// confirms that an account was created
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'My account'
);
await expect(
page.getByRole( 'heading', { name: 'My account' } )
).toBeVisible();
await page
.getByRole( 'navigation' )
.getByRole( 'link', { name: 'Log out' } )

View File

@ -1,4 +1,5 @@
const { test, expect } = require( '@playwright/test' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const customer = {
@ -154,20 +155,13 @@ test.describe( 'Shopper Checkout Login Account', () => {
// place an order
await page.locator( 'text=Place order' ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Order received'
);
await expect(
page.getByText( 'Your order has been received' )
).toBeVisible();
await page.waitForLoadState( 'networkidle' );
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
orderId = orderReceivedText.split( /(\s+)/ )[ 6 ].toString();
orderId = getOrderIdFromUrl( page );
await expect( page.locator( 'ul > li.email' ) ).toContainText(
customer.email
);
await expect( page.getByText( customer.email ) ).toBeVisible();
// check my account page
await page.goto( '/my-account/' );

View File

@ -3,6 +3,7 @@ const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const { admin, customer } = require( '../../test-data/data' );
const { setFilterValue, clearFilters } = require( '../../utils/filters' );
const { addProductsToCart } = require( '../../utils/pdp' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
const guestEmail = 'checkout-guest@example.com';
@ -248,7 +249,6 @@ test.describe( 'Checkout page', () => {
await page.locator( '#billing_email' ).fill( customer.email );
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect( page.locator( 'ul.woocommerce-error' ) ).toBeVisible();
await expect(
page.getByText( 'Shipping First name is a required field.' )
).toBeVisible();
@ -345,16 +345,10 @@ test.describe( 'Checkout page', () => {
await test.step( 'Load the order confirmation page, extract order number', async () => {
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
guestOrderId = await orderReceivedText
.split( /(\s+)/ )[ 6 ]
.toString();
guestOrderId = getOrderIdFromUrl( page );
} );
await test.step( 'Simulate cookies cleared, but within 10 minute grace period', async () => {
@ -364,7 +358,7 @@ test.describe( 'Checkout page', () => {
await page.context().clearCookies();
await page.reload();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
} );
@ -379,39 +373,39 @@ test.describe( 'Checkout page', () => {
await page.waitForTimeout( 2000 ); // needs some time before reload for change to take effect.
await page.reload( { waitForLoadState: 'networkidle' } );
await expect(
page.getByRole( 'button', { name: 'Verify' } )
page.getByText(
/confirm the email address linked to the order | verify the email address associated /
)
).toBeVisible();
await expect( page.getByLabel( 'Email address *' ) ).toBeVisible();
await expect(
page.locator( 'form.woocommerce-verify-email p:nth-child(3)' )
).toContainText(
/verify the email address associated with the order/
);
} );
await test.step( 'Supply incorrect email address for the order, error', async () => {
// Supplying an email address other than the actual order billing email address will take them back to the same
// page with an error message.
await page
.getByLabel( 'Email address *' )
.getByLabel( 'Email address' )
.fill( 'incorrect@email.address' );
await page.getByRole( 'button', { name: 'Verify' } ).click();
await page
.getByRole( 'button', { name: /Verify|Confirm/ } )
.click();
await expect(
page.locator( 'form.woocommerce-verify-email p:nth-child(4)' )
).toContainText(
/verify the email address associated with the order/
);
await expect( page.getByRole( 'alert' ) ).toContainText(
/We were unable to verify the email address you provided/
);
page.getByText(
/confirm the email address linked to the order | verify the email address associated /
)
).toBeVisible();
await expect(
page.getByText( 'We were unable to verify the email address' )
).toBeVisible();
} );
await test.step( 'Supply the correct email address for the order, display order confirmation', async () => {
// However if they supply the *correct* billing email address, they should see the order received page again.
await page.getByLabel( 'Email address *' ).fill( guestEmail );
await page.getByRole( 'button', { name: 'Verify' } ).click();
await page.getByLabel( 'Email address' ).fill( guestEmail );
await page
.getByRole( 'button', { name: /Verify|Confirm/ } )
.click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
} );
@ -491,25 +485,21 @@ test.describe( 'Checkout page', () => {
await page.locator( 'text=Place order' ).click();
await expect(
page.getByRole( 'heading', { name: 'Order received' } )
page.getByText( 'Your order has been received' )
).toBeVisible();
// get order ID from the page
const orderReceivedText = await page
.locator( '.woocommerce-order-overview__order.order' )
.textContent();
customerOrderId = await orderReceivedText
.split( /(\s+)/ )[ 6 ]
.toString();
customerOrderId = getOrderIdFromUrl( page );
// Effect a log out/simulate a new browsing session by dropping all cookies.
await page.context().clearCookies();
await page.reload();
// Now we are logged out, return to the confirmation page: we should be asked to log back in.
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
/Please log in to your account to view this order/
);
await expect(
page.getByText(
/Log in here to view your order|log in to your account to view this order/
)
).toBeVisible();
// Switch to admin user.
await page.goto( 'wp-login.php?loggedout=true' );

View File

@ -4,8 +4,8 @@ const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const miniCartPageTitle = `Mini Cart ${ Date.now() }`;
const miniCartPageSlug = miniCartPageTitle.replace( / /gi, '-' ).toLowerCase();
const miniCartButton = '.wc-block-mini-cart__button';
const miniCartBadge = '.wc-block-mini-cart__badge';
const miniCartButton = 'main .wc-block-mini-cart__button';
const miniCartBadge = 'main .wc-block-mini-cart__badge';
const simpleProductName = 'Single Hundred Product';
const simpleProductDesc = 'Lorem ipsum dolor sit amet.';
@ -119,7 +119,7 @@ test.describe.skip( 'Mini Cart block page', () => {
context,
} ) => {
const colorField = '.components-input-control__input';
const miniCartBlock = '.wp-block-woocommerce-mini-cart';
const miniCartBlock = 'main .wp-block-woocommerce-mini-cart';
const redColor = 'ff0000';
const blueColor = '002eff';
const greenColor = '00cc09';
@ -175,7 +175,9 @@ test.describe.skip( 'Mini Cart block page', () => {
// customize font size and weight
await page.getByLabel( 'Large', { exact: true } ).click();
await page.getByRole( 'button', { name: 'Font weight' } ).click();
await page.getByRole( 'option' ).filter( { hasText: 'Black' } ).click();
await page
.getByRole( 'option', { name: 'Black', exact: true } )
.click();
// publish created mini cart page
await page
@ -216,8 +218,8 @@ test.describe.skip( 'Mini Cart block page', () => {
);
await page.locator( miniCartButton ).click();
await expect(
page.getByText( 'Your cart is currently empty!' )
).toBeVisible();
await page.getByText( 'Your cart is currently empty!' ).count()
).toBeGreaterThan( 0 );
await page.getByRole( 'link', { name: 'Start shopping' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
@ -307,9 +309,9 @@ test.describe.skip( 'Mini Cart block page', () => {
await page
.getByRole( 'button', { name: 'Update', exact: true } )
.click();
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Shipping costs updated.'
);
await expect(
page.getByText( 'Shipping costs updated' )
).toBeVisible();
await page.goto( miniCartPageSlug );
await expect(

View File

@ -40,16 +40,18 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Log in' ).click();
// verify that the page exists and that there are no added addresses
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Addresses'
);
await expect(
page.getByRole( 'heading', { name: 'Addresses' } )
).toBeVisible();
await expect(
page.locator( '.woocommerce-Address' ).first()
).toContainText( 'You have not set up this type of address yet.' );
// go to add billing address
await page.goto( 'my-account/edit-address/billing' );
await expect( page.locator( 'h3' ) ).toContainText( 'Billing address' );
await expect(
page.getByRole( 'heading', { name: 'Billing address' } )
).toBeVisible();
await page.locator( '#billing_first_name' ).fill( 'John' );
await page.locator( '#billing_last_name' ).fill( 'Doe Billing' );
await page
@ -63,9 +65,9 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Save address' ).click();
// verify billing address has been applied
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'Address changed successfully.'
);
await expect(
page.getByText( 'Address changed successfully.' )
).toBeVisible();
await expect(
page.locator( `:text("John Doe Billing")` )
).toBeVisible();
@ -85,18 +87,18 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Log in' ).click();
// verify that the page exists and that there are no added addresses
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Addresses'
);
await expect(
page.getByRole( 'heading', { name: 'Addresses' } )
).toBeVisible();
await expect(
page.locator( '.woocommerce-Address' ).nth( 1 )
).toContainText( 'You have not set up this type of address yet.' );
// go to add shipping address
await page.goto( 'my-account/edit-address/shipping' );
await expect( page.locator( 'h3' ) ).toContainText(
'Shipping address'
);
await expect(
page.getByRole( 'heading', { name: 'Shipping address' } )
).toBeVisible();
await page.locator( '#shipping_first_name' ).fill( 'John' );
await page.locator( '#shipping_last_name' ).fill( 'Doe Shipping' );
await page
@ -109,9 +111,9 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Save address' ).click();
// verify shipping address has been applied
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'Address changed successfully.'
);
await expect(
page.getByText( 'Address changed successfully.' )
).toBeVisible();
await expect(
page.locator( `:text("John Doe Shipping")` )
).toBeVisible();

View File

@ -75,9 +75,9 @@ test.describe( 'Shopper My Account Create Account', () => {
await page.locator( 'input#reg_email' ).fill( customerEmailAddress );
await page.locator( 'button[name="register"]' ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'My account'
);
await expect(
page.getByRole( 'heading', { name: 'My account' } )
).toBeVisible();
await expect( page.locator( 'text=Log out' ).first() ).toBeVisible();
await page.goto( 'my-account/edit-account/' );

View File

@ -94,9 +94,9 @@ test.describe( 'Customer can manage downloadable file in My Account > Downloads
await page.locator( 'text=Log in' ).click();
// verify that the downloadable product exist in downloads
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Downloads'
);
await expect(
page.getByRole( 'heading', { name: 'Downloads' } )
).toBeVisible();
await expect( page.locator( 'td.download-product' ) ).toContainText(
product.name
);
@ -110,14 +110,16 @@ test.describe( 'Customer can manage downloadable file in My Account > Downloads
// click to simulate downloading and verify the file doesn't exist anymore in downloads
await page.locator( '.woocommerce-MyAccount-downloads-file' ).click();
await page.goto( 'my-account/downloads/' );
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'No downloads available yet.'
);
await expect( page.locator( '.wc-forward' ) ).toContainText(
'Browse products'
);
await expect(
page.getByText( 'No downloads available yet.' )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: 'Browse products' } )
).toBeVisible();
await page.locator( '.wc-forward' ).click();
await expect( page.locator( 'h1.page-title' ) ).toContainText( 'Shop' );
await page.getByRole( 'link', { name: 'Browse products' } ).click();
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
} );
} );

View File

@ -89,13 +89,13 @@ test.describe( 'Customer can pay for their order through My Account', () => {
await page.locator( 'a.pay' ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Pay for order'
);
await expect(
page.getByRole( 'heading', { name: 'Checkout' } )
).toBeVisible();
await page.locator( '#place_order' ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'Order received'
);
await expect(
page.getByText( 'Your order has been received' )
).toBeVisible();
} );
} );

View File

@ -1,61 +1,36 @@
const { test, expect } = require( '@playwright/test' );
const { customer } = require( '../../test-data/data' );
const pages = [
[ 'Orders', 'my-account/orders' ],
[ 'Downloads', 'my-account/downloads' ],
[ 'Addresses', 'my-account/edit-address' ],
[ 'Account details', 'my-account/edit-account' ],
];
const pages = [ 'Orders', 'Downloads', 'Addresses', 'Account details' ];
test.describe( 'My account page', () => {
test.use( { storageState: process.env.CUSTOMERSTATE } );
test( 'allows customer to login', async ( { page } ) => {
test( 'allows customer to login and navigate', async ( { page } ) => {
await page.goto( 'my-account/' );
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
'My account'
);
await expect(
page.locator( 'div.woocommerce-MyAccount-content > p >> nth=0' )
).toContainText( `${ customer.first_name } ${ customer.last_name }` );
page.getByRole( 'heading', { name: 'My account' } )
).toBeVisible();
await expect(
page.getByText(
`Hello ${ customer.first_name } ${ customer.last_name }`
)
).toBeVisible();
for ( const accountPage of pages ) {
await test.step( `customer can navigate to ${ accountPage } page`, async () => {
await page
.getByRole( 'link', { name: accountPage, exact: true } )
.click();
await expect(
page.getByRole( 'heading', { name: accountPage } )
).toBeVisible();
} );
}
// assert that navigation is visible
await expect(
page.locator( '.woocommerce-MyAccount-navigation-link--dashboard' )
).toContainText( 'Dashboard' );
await expect(
page.locator( '.woocommerce-MyAccount-navigation-link--orders' )
).toContainText( 'Orders' );
await expect(
page.locator( '.woocommerce-MyAccount-navigation-link--downloads' )
).toContainText( 'Downloads' );
await expect(
page.locator(
'.woocommerce-MyAccount-navigation-link--edit-address'
)
).toContainText( 'Addresses' );
await expect(
page.locator(
'.woocommerce-MyAccount-navigation-link--edit-account'
)
).toContainText( 'Account details' );
await expect(
page.locator(
'.woocommerce-MyAccount-navigation-link--customer-logout'
)
).toContainText( 'Log out' );
page.getByRole( 'link', { name: 'Log out', exact: true } )
).toBeVisible();
} );
for ( let i = 0; i < pages.length; i++ ) {
test( `allows customer to see ${ pages[ i ][ 0 ] } page`, async ( {
page,
} ) => {
await page.goto( pages[ i ][ 1 ] );
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
pages[ i ][ 0 ]
);
} );
}
} );

View File

@ -1,6 +1,7 @@
const { test, expect } = require( '@playwright/test' );
const { customer, storeDetails } = require( '../../test-data/data' );
const { api } = require( '../../utils' );
const { getOrderIdFromUrl } = require( '../../utils/order' );
let productId, orderId, zoneId;
@ -101,11 +102,9 @@ test.describe( 'Shopper Order Email Receiving', () => {
await page.locator( 'text=Place order' ).click();
await expect(
page.locator( 'li.woocommerce-order-overview__order > strong' )
page.getByText( 'Your order has been received' )
).toBeVisible();
orderId = await page
.locator( 'li.woocommerce-order-overview__order > strong' )
.textContent();
orderId = getOrderIdFromUrl( page );
// search to narrow it down to just the messages we want
await page.goto(
@ -113,7 +112,6 @@ test.describe( 'Shopper Order Email Receiving', () => {
customer.email
) }`
);
await page.waitForLoadState( 'networkidle' );
await expect(
page.locator( 'td.column-receiver >> nth=0' )
).toContainText( customer.email );

View File

@ -77,18 +77,25 @@ test.describe( 'Grouped Product Page', () => {
} ) => {
await page.goto( `product/${ slug }` );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.woocommerce-error' ) ).toContainText(
'Please choose the quantity of items you wish to add to your cart…'
);
await page
.getByRole( 'button', { name: 'Add to cart', exact: true } )
.click();
await expect(
page.getByText(
'Please choose the quantity of items you wish to add to your cart'
)
).toBeVisible();
await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '5' );
await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '5' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
`${ simpleProduct1 }” and “${ simpleProduct2 }” have been added to your cart.`
);
await page
.getByRole( 'button', { name: 'Add to cart', exact: true } )
.click();
await expect(
page.getByText(
`${ simpleProduct1 }” and “${ simpleProduct2 }” have been added to your cart`
)
).toBeVisible();
await page.goto( 'cart/' );
await expect(
page.locator( 'td.product-name >> nth=0' )
@ -110,14 +117,16 @@ test.describe( 'Grouped Product Page', () => {
await page.goto( `product/${ slug }` );
await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '1' );
await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '1' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page
.getByRole( 'button', { name: 'Add to cart', exact: true } )
.click();
await page.goto( 'cart/' );
await page.locator( 'a.remove >> nth=1' ).click();
await page.locator( 'a.remove >> nth=0' ).click();
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
await expect(
page.getByText( 'Your cart is currently empty.' )
).toBeVisible();
} );
} );

View File

@ -7,15 +7,9 @@ const productPrice = '18.16';
const simpleProductName = 'Simple single product';
const simpleProductSlug = simpleProductName.replace( / /gi, '-' ).toLowerCase();
let simpleProductId,
crossSellProductId,
upSellProductId,
productCategory1Id,
productCategory2Id;
let simpleProductId, productCategory1Id, productCategory2Id;
test.describe( 'Single Product Page', () => {
const crossSellProduct = simpleProductName + ' Related';
const upSellProduct = simpleProductName + ' Upsell';
const productCategoryName1 = 'Hoodies';
const productCategoryName2 = 'Jumpers';
const productDescription =
@ -52,36 +46,6 @@ test.describe( 'Single Product Page', () => {
} );
// add products
await api
.post( 'products', {
name: crossSellProduct,
type: 'simple',
categories: [
{
id: productCategory1Id,
name: productCategoryName1,
},
],
regular_price: productPrice,
} )
.then( ( response ) => {
crossSellProductId = response.data.id;
} );
await api
.post( 'products', {
name: upSellProduct,
type: 'simple',
categories: [
{
id: productCategory2Id,
name: productCategoryName2,
},
],
regular_price: productPrice,
} )
.then( ( response ) => {
upSellProductId = response.data.id;
} );
await api
.post( 'products', {
name: simpleProductName,
@ -105,8 +69,6 @@ test.describe( 'Single Product Page', () => {
},
],
regular_price: productPrice,
related_ids: crossSellProductId,
upsell_ids: upSellProductId,
} )
.then( ( response ) => {
simpleProductId = response.data.id;
@ -126,36 +88,13 @@ test.describe( 'Single Product Page', () => {
version: 'wc/v3',
} );
await api.post( 'products/batch', {
delete: [ simpleProductId, crossSellProductId, upSellProductId ],
delete: [ simpleProductId ],
} );
await api.post( 'products/categories/batch', {
delete: [ productCategory1Id, productCategory2Id ],
} );
} );
test( 'should be able to see upsell and related products', async ( {
page,
} ) => {
await page.goto( `product/${ simpleProductSlug }` );
await expect( page.locator( '.upsells > h2' ) ).toContainText(
'You may also like…'
);
await expect( page.locator( '.related > h2' ) ).toContainText(
'Related products'
);
await expect(
page.locator(
'.upsells > .products > li > a > .woocommerce-loop-product__title'
)
).toContainText( upSellProduct );
await expect(
page.locator(
'.related > .products > li > a > .woocommerce-loop-product__title'
)
).toContainText( crossSellProduct );
} );
test( 'should be able to post a review and see it after', async ( {
page,
} ) => {
@ -181,11 +120,7 @@ test.describe( 'Single Product Page', () => {
);
} );
test( 'should be able to see product description and image', async ( {
page,
} ) => {
const images = [ 'image-02', 'image-03' ];
test( 'should be able to see product description', async ( { page } ) => {
await page.goto( `product/${ simpleProductSlug }` );
await page.getByRole( 'tab', { name: 'Description' } ).click();
@ -224,47 +159,5 @@ test.describe( 'Single Product Page', () => {
.getByRole( 'tabpanel' )
.filter( 'listitem', { name: 'Test numbered item' } )
).toBeVisible();
await expect(
page
.locator( `#product-${ simpleProductId } ol img` )
.nth( images.length ),
'all gallery images should be visible'
).toBeVisible(); // +1 for the featured image
} );
test( 'should be able to add simple products to the cart', async ( {
page,
} ) => {
await page.goto( `product/${ simpleProductSlug }` );
await page.locator( 'input.qty' ).fill( '5' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'have been added to your cart.'
);
await page.goto( 'cart/' );
await expect( page.locator( 'td.product-name' ) ).toContainText(
simpleProductName
);
await expect( page.locator( 'input.qty' ) ).toHaveValue( '5' );
await expect( page.locator( 'td.product-subtotal' ) ).toContainText(
( 5 * +productPrice ).toString()
);
} );
test( 'should be able to remove simple products from the cart', async ( {
page,
} ) => {
await page.goto( `/shop/?add-to-cart=${ simpleProductId }` );
await page.waitForLoadState( 'networkidle' );
await page.goto( 'cart/' );
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
} );
} );

View File

@ -196,7 +196,9 @@ test.describe( 'Browse product tags and attributes from the product page', () =>
page,
} ) => {
await page.goto( 'shop/' );
await expect( page.locator( 'h1.page-title' ) ).toContainText( 'Shop' );
await expect(
page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible();
await expect( page.locator( '.woocommerce-ordering' ) ).toBeVisible();
const addToCart = page.getByRole( 'add_to_cart_button' );
@ -223,18 +225,14 @@ test.describe( 'Browse product tags and attributes from the product page', () =>
} ) => {
await page.goto( 'shop/' );
await page.locator( `text=${ simpleProductName } 1` ).click();
await page
.locator( 'span.tagged_as > a', { hasText: productTagName1 } )
.click();
await expect( page.locator( 'h1.page-title' ) ).toContainText(
productTagName1
);
await expect( page.locator( '.woocommerce-breadcrumb' ) ).toContainText(
` / Products tagged “${ productTagName1 }`
);
await page.getByRole( 'link', { name: productTagName1 } ).click();
await expect(
page.locator( '.woocommerce-result-count' )
).toContainText( 'Showing all 3 results' );
page.getByRole( 'heading', { name: productTagName1 } )
).toBeVisible();
await expect(
page.getByText( `Products tagged “${ productTagName1 }` )
).toBeVisible();
await expect( page.getByText( 'Showing all 3 results' ) ).toBeVisible();
} );
test( 'should see and sort attributes page with all its products', async ( {
@ -253,15 +251,13 @@ test.describe( 'Browse product tags and attributes from the product page', () =>
hasText: productAttributeTerm,
} )
.click();
await expect( page.locator( 'h1.page-title' ) ).toContainText(
productAttributeTerm
);
await expect(
page.getByRole( 'heading', { name: productAttributeTerm } )
).toBeVisible();
await expect( page.locator( '.woocommerce-breadcrumb' ) ).toContainText(
` / Product ${ productAttributeName } / ${ productAttributeTerm }`
);
await expect(
page.locator( '.woocommerce-result-count' )
).toContainText( 'Showing all 3 results' );
await expect( page.getByText( 'Showing all 3 results' ) ).toBeVisible();
} );
test( 'can see products showcase', async ( { page } ) => {
@ -291,29 +287,27 @@ test.describe( 'Browse product tags and attributes from the product page', () =>
.click();
await expect(
page.getByText( `${ pageTitle } is now live.` )
page.getByRole( 'button', { name: 'Update', exact: true } )
).toBeVisible();
// go to created page with products showcase
await page.goto( 'product-showcase' );
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
pageTitle
);
const addToCart = page.getByRole( 'add_to_cart_button' );
for ( let i = 0; i < addToCart.count(); ++i )
await expect( addToCart.nth( i ) ).toBeVisible();
await expect(
page.getByRole( 'heading', { name: pageTitle } )
).toBeVisible();
await expect(
await page.getByRole( 'button', { name: 'Add to cart' } ).count()
).toBeGreaterThan( 0 );
const productPrice = page.getByRole( 'woocommerce-Price-amount' );
const productPrice = page.locator( '.woocommerce-Price-amount' );
for ( let i = 0; i < productPrice.count(); ++i )
await expect( productPrice.nth( i ) ).toBeVisible();
const productTitle = page.getByRole(
'woocommerce-loop-product__title'
);
const productTitle = page.locator( '.woocommerce-loop-product__title' );
for ( let i = 0; i < productTitle.count(); ++i )
await expect( productTitle.nth( i ) ).toBeVisible();
const productImage = page.getByRole( 'wp-post-image' );
const productImage = page.locator( '.wp-post-image' );
for ( let i = 0; i < productImage.count(); ++i )
await expect( productImage.nth( i ) ).toBeVisible();
} );

View File

@ -193,10 +193,12 @@ test.describe( 'Variable Product Page', () => {
await page
.locator( '#size' )
.selectOption( attr.attributes[ 0 ].option );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'has been added to your cart.'
);
await page
.getByRole( 'button', { name: 'Add to cart', exact: true } )
.click();
await expect(
page.getByText( 'has been added to your cart' )
).toBeVisible();
}
await page.goto( 'cart/' );
@ -223,14 +225,16 @@ test.describe( 'Variable Product Page', () => {
} ) => {
await page.goto( `product/${ slug }` );
await page.locator( '#size' ).selectOption( 'Large' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page
.getByRole( 'button', { name: 'Add to cart', exact: true } )
.click();
await page.goto( 'cart/' );
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
await expect(
page.getByText( 'Your cart is currently empty' )
).toBeVisible();
} );
} );

View File

@ -92,7 +92,7 @@ test.describe( 'Search, browse by categories and sort items in the shop', () =>
} );
} );
test( 'should let user search the store', async ( { page } ) => {
test.skip( 'should let user search the store', async ( { page } ) => {
await page.goto( 'shop/' );
await page
@ -115,20 +115,21 @@ test.describe( 'Search, browse by categories and sort items in the shop', () =>
await page.goto( 'shop/' );
await page.locator( `text=${ simpleProductName } 2` ).click();
await page
.locator( 'span.posted_in > a', { hasText: categoryB } )
.getByLabel( 'Breadcrumb' )
.getByRole( 'link', { name: categoryB } )
.click();
// verify the Audio category page
await expect( page.locator( 'h1.page-title' ) ).toContainText(
categoryB
);
await expect(
page.locator( 'h2.woocommerce-loop-product__title' )
).toContainText( simpleProductName + ' 2' );
page.getByRole( 'heading', { name: categoryB } )
).toBeVisible();
await expect(
page.getByRole( 'heading', { name: simpleProductName + ' 2' } )
).toBeVisible();
await page.locator( `text=${ simpleProductName } 2` ).click();
await expect( page.locator( 'h1.entry-title' ) ).toContainText(
simpleProductName + ' 2'
);
await expect(
page.getByRole( 'heading', { name: simpleProductName + ' 2' } )
).toBeVisible();
} );
test( 'should let user sort the products in the shop', async ( {

View File

@ -1,19 +1,24 @@
const { test, expect } = require( '@playwright/test' );
const { test: baseTest, expect } = require( '../../fixtures/fixtures' );
test.describe( 'WordPress', async () => {
test.use( { storageState: process.env.CUSTOMERSTATE } );
test.beforeEach( async ( { page } ) => {
await page.goto( 'hello-world/' );
await expect(
page.getByRole( 'heading', { name: 'Hello world!' } )
).toBeVisible();
} );
test( 'logged-in customer can comment on a post', async ( { page } ) => {
const comment = `This is a test comment ${ Date.now() }`;
await page.getByRole( 'textbox', { name: 'comment' } ).fill( comment );
await page.getByRole( 'button', { name: 'Post Comment' } ).click();
await expect( page.getByText( comment ) ).toBeVisible();
} );
const test = baseTest.extend( {
storageState: process.env.CUSTOMERSTATE,
} );
test( 'logged-in customer can comment on a post', async ( { page } ) => {
await page.goto( 'hello-world/' );
await expect(
page.getByRole( 'heading', { name: 'Hello world!', exact: true } )
).toBeVisible();
await expect( page.getByText( `Logged in as` ) ).toBeVisible();
const comment = `This is a test comment ${ Date.now() }`;
await page.getByRole( 'textbox', { name: 'comment' } ).fill( comment );
await expect(
page.getByRole( 'textbox', { name: 'comment' } )
).toHaveValue( comment );
await page.getByRole( 'button', { name: 'Post Comment' } ).click();
await expect( page.getByText( comment ) ).toBeVisible();
} );

View File

@ -1,7 +1,7 @@
const { expect } = require( '../fixtures/fixtures' );
const logIn = async ( page, username, password, assertSuccess = true ) => {
await page.getByLabel( 'Username or Email Address' ).fill( username );
await page.getByLabel( 'Password', { exact: true } ).fill( password );
await page.getByRole( 'textbox', { name: 'Password' } ).fill( password );
await page.getByRole( 'button', { name: 'Log In' } ).click();
if ( assertSuccess ) {

View File

@ -0,0 +1,4 @@
export function getOrderIdFromUrl( page ) {
const regex = /order-received\/(\d+)/;
return page.url().match( regex )[ 1 ];
}

View File

@ -11,16 +11,14 @@ export async function addProductsToCart( page, productName, quantityCount ) {
await page.goto(
`product/${ productName.replace( / /gi, '-' ).toLowerCase() }`
);
await expect( page.locator( '.product_title' ) ).toContainText(
productName
);
await page.getByLabel( 'Product quantity' ).fill( quantityCount );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect(
page
.getByRole( 'alert' )
.getByText(
`${ quantityCount } ×${ productName }” have been added to your cart.`
)
await page.getByRole( 'heading', { name: productName } ).count()
).toBeGreaterThan( 0 );
await page.getByLabel( 'Product quantity' ).fill( quantityCount );
await page.locator( 'button[name="add-to-cart"]' ).click();
await expect(
page.getByText(
`${ quantityCount } ×${ productName }” have been added to your cart.`
)
).toBeVisible();
}