Skip to content

Commit

Permalink
Update tests to add products to cart by name instead of ID
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoumpierre committed Feb 4, 2025
1 parent d5930df commit 5df9643
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
import * as shopper from '../../../utils/shopper';
import { config } from '../../../config/default';
import {
products,
shouldRunActionSchedulerTests,
shouldRunSubscriptionsTests,
} from '../../../utils/constants';
Expand All @@ -36,9 +35,9 @@ describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
project.use.baseURL
);

await shopper.addCartProduct(
await shopper.addToCartFromShopPage(
shopperPage,
products.SUBSCRIPTION_SIGNUP_FEE
config.products.subscription_signup_fee
);
await shopper.setupCheckout( shopperPage, customerBillingConfig );
await shopper.fillCardDetails( shopperPage, config.cards.basic );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import {
placeOrder,
setupProductCheckout,
} from '../../../utils/shopper';
import { goToShop } from '../../../utils/shopper-navigation';
import { goToSubscriptionPage } from '../../../utils/merchant-navigation';
import { shouldRunSubscriptionsTests } from '../../../utils/constants';

const productName = 'Subscription signup fee product';
const customerBillingConfig =
config.addresses[ 'subscriptions-customer' ].billing;
let subscriptionId = null;
Expand All @@ -34,10 +32,9 @@ describeif( shouldRunSubscriptionsTests )(

const { shopperPage } = await getShopper( browser );
await emptyCart( shopperPage );
await goToShop( shopperPage, 2 );
await setupProductCheckout(
shopperPage,
[ [ productName, 1 ] ],
[ [ config.products.subscription_signup_fee, 1 ] ],
customerBillingConfig
);
await fillCardDetails( shopperPage, config.cards.basic );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import test, { expect, Page } from '@playwright/test';
* Internal dependencies
*/
import { config } from '../../../config/default';
import {
products,
shouldRunSubscriptionsTests,
} from '../../../utils/constants';
import { shouldRunSubscriptionsTests } from '../../../utils/constants';
import { describeif, getShopper } from '../../../utils/helpers';
import * as shopper from '../../../utils/shopper';
import * as navigation from '../../../utils/shopper-navigation';
Expand Down Expand Up @@ -50,7 +47,7 @@ describeif( shouldRunSubscriptionsTests )(

// Purchase a subscription.
await shopper.placeOrderWithOptions( page, {
productId: products.SUBSCRIPTION_NO_SIGNUP_FEE,
product: config.products.subscription_no_signup_fee,
billingAddress: customerBillingAddress,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
placeOrder,
setupProductCheckout,
} from '../../../utils/shopper';
import {
goToShop,
goToShopWithCurrency,
goToSubscriptions,
} from '../../../utils/shopper-navigation';
import { goToSubscriptions } from '../../../utils/shopper-navigation';
import {
activateMulticurrency,
deactivateMulticurrency,
Expand Down Expand Up @@ -57,15 +53,14 @@ describeif( shouldRunSubscriptionsTests )(
test( ' should be able to purchase multiple subscriptions', async () => {
// As a Shopper, purchase the subscription products.
await emptyCart( shopperPage );
await goToShopWithCurrency( shopperPage, 'USD' );
await goToShop( shopperPage, 2 );
await setupProductCheckout(
shopperPage,
Object.keys( products ).map( ( productName: string ) => [
productName,
1,
] ),
configBillingAddress
[
[ config.products.subscription_no_signup_fee, 1 ],
[ config.products.subscription_signup_fee, 1 ],
],
configBillingAddress,
'USD'
);
await fillCardDetails( shopperPage, config.cards.basic );
await placeOrder( shopperPage );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { config } from '../../../config/default';
import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
import * as shopper from '../../../utils/shopper';
import * as navigation from '../../../utils/merchant-navigation';
import {
shouldRunSubscriptionsTests,
products,
} from '../../../utils/constants';
import { shouldRunSubscriptionsTests } from '../../../utils/constants';

describeif( shouldRunSubscriptionsTests )(
'Subscriptions > Purchase subscription with signup fee',
Expand All @@ -34,7 +31,7 @@ describeif( shouldRunSubscriptionsTests )(

test( 'should be able to purchase a subscription with signup fee', async () => {
orderId = await shopper.placeOrderWithOptions( shopperPage, {
productId: products.SUBSCRIPTION_SIGNUP_FEE,
product: config.products.subscription_signup_fee,
billingAddress: customerBillingAddress,
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ async function createDisputedOrder( browser: Browser ) {
const orderId = await test.step(
'Place an order as shopper, to be automatically disputed',
async () => {
await shopperPage.goto( '/cart/' );
await shopper.addCartProduct( shopperPage );
await shopper.addToCartFromShopPage( shopperPage );

await shopperPage.goto( '/checkout/' );
await shopper.fillBillingAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ test.describe(
test.beforeEach( async ( { browser } ) => {
const { shopperPage } = await getShopper( browser );
// Place an order to dispute later
await shopperPage.goto( '/cart/' );
await shopper.addCartProduct( shopperPage );
await shopper.addToCartFromShopPage( shopperPage );

await shopperPage.goto( '/checkout/' );
await shopper.fillBillingAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { test, expect, Page } from '@playwright/test';
/**
* Internal dependencies
*/
import { config } from '../../../config/default';
import { config, Product } from '../../../config/default';
import { getMerchant, getShopper } from '../../../utils/helpers';
import {
fillCardDetails,
placeOrder,
setupProductCheckout,
} from '../../../utils/shopper';
import { goToShop } from '../../../utils/shopper-navigation';
import { goToOrder } from '../../../utils/merchant-navigation';
import {
activateMulticurrency,
Expand All @@ -23,9 +22,21 @@ import {

// Needs to be finished.
test.describe( 'Order > Partial refund', () => {
const product1 = config.products.simple.name;
const product2 = 'Belt';
const product3 = 'Hoodie with Logo';
const product1 = config.products.simple;
const product2 = config.products.belt;
const product3 = config.products.hoodie_with_logo;

const lineItems: [ Product, number ][][] = [
[
[ product1, 1 ],
[ product2, 1 ],
],
[
[ product1, 1 ],
[ product2, 2 ],
[ product3, 1 ],
],
];

/**
* Elements:
Expand All @@ -42,21 +53,20 @@ test.describe( 'Order > Partial refund', () => {
[
'Partially refund one product of two product order',
{
lineItems: [
[ product1, 1 ],
[ product2, 1 ],
],
lineItems: lineItems[ 0 ].map( ( [ item, quantity ] ) => [
item.name,
quantity,
] ),
refundInputs: [ { refundQty: 0, refundAmount: 5 } ],
},
],
[
'Refund two products of three product order',
{
lineItems: [
[ product1, 1 ],
[ product2, 2 ],
[ product3, 1 ],
],
lineItems: lineItems[ 1 ].map( ( [ item, quantity ] ) => [
item.name,
quantity,
] ),
refundInputs: [
{ refundQty: 1, refundAmount: 18 },
{ refundQty: 1, refundAmount: 55 },
Expand All @@ -71,9 +81,7 @@ test.describe( 'Order > Partial refund', () => {
let merchantPage: Page, shopperPage: Page;

const orderProducts = async ( dataTableIndex: number ) => {
const lineItems = dataTable[ dataTableIndex ][ 1 ].lineItems;
await goToShop( shopperPage );
await setupProductCheckout( shopperPage, lineItems );
await setupProductCheckout( shopperPage, lineItems[ dataTableIndex ] );
await fillCardDetails( shopperPage );
await placeOrder( shopperPage );
await expect(
Expand Down
18 changes: 8 additions & 10 deletions tests/e2e-pw/specs/wcpay/merchant/multi-currency-setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test.describe( 'Multi-currency setup', () => {

test.beforeAll( async () => {
await disableAllEnabledCurrencies( merchantPage );
await navigation.goToShopWithCurrency( shopperPage, 'USD' );
await navigation.goToShop( shopperPage, { currency: 'USD' } );

beanieRegularPrice = await getPriceFromProduct(
shopperPage,
Expand All @@ -98,10 +98,9 @@ test.describe( 'Multi-currency setup', () => {
testData.currencyCode,
'0'
);
await navigation.goToShopWithCurrency(
shopperPage,
testData.currencyCode
);
await navigation.goToShop( shopperPage, {
currency: testData.currencyCode,
} );

const beaniePriceOnCurrency = await getPriceFromProduct(
shopperPage,
Expand Down Expand Up @@ -136,10 +135,9 @@ test.describe( 'Multi-currency setup', () => {
testData.currencyCode,
testData.charmPricing
);
await navigation.goToShopWithCurrency(
shopperPage,
testData.currencyCode
);
await navigation.goToShop( shopperPage, {
currency: testData.currencyCode,
} );

const beaniePriceOnCurrency = await getPriceFromProduct(
shopperPage,
Expand Down Expand Up @@ -207,7 +205,7 @@ test.describe( 'Multi-currency setup', () => {

Object.keys( currencyDecimalMap ).forEach( ( currency: string ) => {
test( `the decimal points for ${ currency } are displayed correctly`, async () => {
await navigation.goToShopWithCurrency( shopperPage, currency );
await navigation.goToShop( shopperPage, { currency } );

const beaniePriceOnCurrency = await getPriceFromProduct(
shopperPage,
Expand Down
28 changes: 14 additions & 14 deletions tests/e2e-pw/specs/wcpay/shopper/klarna-checkout-purchase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import * as shopper from '../../../utils/shopper';
import { getMerchant, getShopper } from '../../../utils/helpers';
import * as merchant from '../../../utils/merchant';
import { config } from '../../../config/default';
import {
goToProductPageBySlug,
goToShop,
} from '../../../utils/shopper-navigation';
import { goToProductPageBySlug } from '../../../utils/shopper-navigation';

test.describe( 'Klarna Checkout', () => {
let merchantPage: Page;
Expand Down Expand Up @@ -54,16 +51,19 @@ test.describe( 'Klarna Checkout', () => {
} );

test( 'allows to use Klarna as a payment method', async () => {
await goToShop( shopperPage );
await shopper.setupProductCheckout( shopperPage, [ [ 'Belt', 1 ] ], {
...config.addresses.customer.billing,
// these are Klarna-specific values:
// https://docs.klarna.com/resources/test-environment/sample-customer-data/#united-states-of-america
email: '[email protected]',
phone: '+13106683312',
firstname: 'Test',
lastname: 'Person-us',
} );
await shopper.setupProductCheckout(
shopperPage,
[ [ config.products.belt, 1 ] ],
{
...config.addresses.customer.billing,
// these are Klarna-specific values:
// https://docs.klarna.com/resources/test-environment/sample-customer-data/#united-states-of-america
email: '[email protected]',
phone: '+13106683312',
firstname: 'Test',
lastname: 'Person-us',
}
);

await shopperPage
.locator( '.wc_payment_methods' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getMerchant, getShopper } from '../../../utils/helpers';
import * as merchant from '../../../utils/merchant';
import * as shopper from '../../../utils/shopper';
import * as devtools from '../../../utils/devtools';
import { config } from '../../../config/default';

const cardTestingProtectionStates = [ false, true ];
const bnplProviders = [ 'Affirm', 'Afterpay' ];
Expand Down Expand Up @@ -56,7 +57,11 @@ test.describe( 'BNPL checkout', () => {

for ( const provider of bnplProviders ) {
test( `Checkout with ${ provider }`, async () => {
await shopper.addCartProduct( shopperPage, 17 ); // Belt
await shopper.addToCartFromShopPage(
shopperPage,
config.products.belt
);

await shopper.setupCheckout( shopperPage );
await shopper.selectPaymentMethod( shopperPage, provider );
await shopper.expectFraudPreventionToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import test, { expect } from '@playwright/test';
* Internal dependencies
*/
import { config } from '../../../config/default';
import {
goToCart,
goToCheckout,
goToShop,
} from '../../../utils/shopper-navigation';
import { goToCart, goToCheckout } from '../../../utils/shopper-navigation';
import { useShopper } from '../../../utils/helpers';
import {
addToCartFromShopPage,
Expand All @@ -22,17 +18,14 @@ import {
setupCheckout,
} from '../../../utils/shopper';

const productName = config.products.simple.name;

test.describe(
'Checkout with free coupon & after modifying cart on Checkout page',
() => {
// All tests will use the shopper only.
useShopper();

test.beforeEach( async ( { page } ) => {
await goToShop( page );
await addToCartFromShopPage( page, productName );
await addToCartFromShopPage( page );
await goToCart( page );
await page.getByPlaceholder( 'Coupon code' ).fill( 'free' );
await page.getByRole( 'button', { name: 'Apply coupon' } ).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.describe( 'Shopper > Checkout > Failures with various cards', () => {
};

test.beforeEach( async ( { page } ) => {
await shopper.addCartProduct( page );
await shopper.addToCartFromShopPage( page );
await shopper.setupCheckout( page );
await shopper.selectPaymentMethod( page );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import { getMerchant, getShopper } from '../../../utils/helpers';
import { activateTheme } from '../../../utils/merchant';
import { config } from '../../../config/default';
import {
addCartProduct,
addToCartFromShopPage,
confirmCardAuthentication,
emptyCart,
expectFraudPreventionToken,
fillCardDetails,
placeOrder,
setupCheckout,
} from '../../../utils/shopper';
import { goToShop } from '../../../utils/shopper-navigation';

/**
* Tests for successful purchases with both card testing prevention enabled
Expand Down Expand Up @@ -51,8 +50,7 @@ import { goToShop } from '../../../utils/shopper-navigation';

test.beforeEach( async () => {
await emptyCart( shopperPage );
await goToShop( shopperPage );
await addCartProduct( shopperPage );
await addToCartFromShopPage( shopperPage );
await setupCheckout(
shopperPage,
config.addresses.customer.billing
Expand Down
Loading

0 comments on commit 5df9643

Please sign in to comment.