2019-12-02 17:54:45 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-12-22 13:59:16 +00:00
|
|
|
const { pressKeyWithModifier } = require( '@wordpress/e2e-test-utils' );
|
|
|
|
const config = require( 'config' );
|
2019-12-02 17:54:45 +00:00
|
|
|
|
2019-11-24 13:08:48 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-12-22 13:59:16 +00:00
|
|
|
const {
|
|
|
|
getQtyInputExpression,
|
|
|
|
getCartItemExpression,
|
|
|
|
getRemoveExpression
|
|
|
|
} = require( './expressions' );
|
|
|
|
const {
|
|
|
|
MY_ACCOUNT_ADDRESSES,
|
|
|
|
MY_ACCOUNT_ACCOUNT_DETAILS,
|
|
|
|
MY_ACCOUNT_DOWNLOADS,
|
|
|
|
MY_ACCOUNT_ORDERS,
|
|
|
|
SHOP_MY_ACCOUNT_PAGE,
|
|
|
|
SHOP_CART_PAGE,
|
|
|
|
SHOP_CHECKOUT_PAGE,
|
|
|
|
SHOP_PAGE,
|
|
|
|
SHOP_PRODUCT_PAGE
|
|
|
|
} = require( './constants' );
|
|
|
|
|
|
|
|
const gotoMyAccount = async () => {
|
|
|
|
await page.goto( SHOP_MY_ACCOUNT_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
2019-09-24 09:47:47 +00:00
|
|
|
};
|
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
const shopper = {
|
2019-09-24 09:47:47 +00:00
|
|
|
addToCart: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
page.click( '.single_add_to_cart_button' ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
addToCartFromShopPage: async ( productTitle ) => {
|
|
|
|
const addToCartXPath = `//li[contains(@class, "type-product") and a/h2[contains(text(), "${ productTitle }")]]` +
|
|
|
|
'//a[contains(@class, "add_to_cart_button") and contains(@class, "ajax_add_to_cart")';
|
|
|
|
|
|
|
|
const [ addToCartButton ] = await page.$x( addToCartXPath + ']' );
|
|
|
|
addToCartButton.click();
|
|
|
|
|
|
|
|
await page.waitFor( addToCartXPath + ' and contains(@class, "added")]' );
|
|
|
|
},
|
|
|
|
|
|
|
|
goToCheckout: async () => {
|
|
|
|
await page.goto( SHOP_CHECKOUT_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-11-06 22:17:44 +00:00
|
|
|
goToProduct: async ( postID ) => {
|
2019-11-30 22:07:29 +00:00
|
|
|
await page.goto( SHOP_PRODUCT_PAGE + postID, {
|
2019-09-24 09:47:47 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
goToShop: async () => {
|
|
|
|
await page.goto(SHOP_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
placeOrder: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toClick( '#place_order' ),
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
2019-11-22 12:33:08 +00:00
|
|
|
productIsInCheckout: async ( productTitle, quantity, total, cartSubtotal ) => {
|
|
|
|
await expect( page ).toMatchElement( '.product-name', { text: productTitle } );
|
|
|
|
await expect( page ).toMatchElement( '.product-quantity', { text: quantity } );
|
|
|
|
await expect( page ).toMatchElement( '.product-total .amount', { text: total } );
|
|
|
|
await expect( page ).toMatchElement( '.cart-subtotal .amount', { text: cartSubtotal } );
|
2019-09-24 14:44:10 +00:00
|
|
|
},
|
2019-11-21 17:21:58 +00:00
|
|
|
|
2019-09-24 09:47:47 +00:00
|
|
|
goToCart: async () => {
|
|
|
|
await page.goto( SHOP_CART_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
productIsInCart: async ( productTitle, quantity = null ) => {
|
|
|
|
const cartItemArgs = quantity ? { qty: quantity } : {};
|
|
|
|
const cartItemXPath = getCartItemExpression( productTitle, cartItemArgs );
|
|
|
|
|
|
|
|
await expect( page.$x( cartItemXPath ) ).resolves.toHaveLength( 1 );
|
|
|
|
},
|
|
|
|
|
2019-12-06 15:06:48 +00:00
|
|
|
fillBillingDetails: async ( customerBillingDetails ) => {
|
|
|
|
await expect( page ).toFill( '#billing_first_name', customerBillingDetails.firstname );
|
|
|
|
await expect( page ).toFill( '#billing_last_name', customerBillingDetails.lastname );
|
|
|
|
await expect( page ).toFill( '#billing_company', customerBillingDetails.company );
|
|
|
|
await expect( page ).toSelect( '#billing_country', customerBillingDetails.country );
|
|
|
|
await expect( page ).toFill( '#billing_address_1', customerBillingDetails.addressfirstline );
|
|
|
|
await expect( page ).toFill( '#billing_address_2', customerBillingDetails.addresssecondline );
|
|
|
|
await expect( page ).toFill( '#billing_city', customerBillingDetails.city );
|
|
|
|
await expect( page ).toSelect( '#billing_state', customerBillingDetails.state );
|
|
|
|
await expect( page ).toFill( '#billing_postcode', customerBillingDetails.postcode );
|
|
|
|
await expect( page ).toFill( '#billing_phone', customerBillingDetails.phone );
|
|
|
|
await expect( page ).toFill( '#billing_email', customerBillingDetails.email );
|
|
|
|
},
|
|
|
|
|
|
|
|
fillShippingDetails: async ( customerShippingDetails ) => {
|
|
|
|
await expect( page ).toFill( '#shipping_first_name', customerShippingDetails.firstname );
|
|
|
|
await expect( page ).toFill( '#shipping_last_name', customerShippingDetails.lastname );
|
|
|
|
await expect( page ).toFill( '#shipping_company', customerShippingDetails.company );
|
|
|
|
await expect( page ).toSelect( '#shipping_country', customerShippingDetails.country );
|
|
|
|
await expect( page ).toFill( '#shipping_address_1', customerShippingDetails.addressfirstline );
|
|
|
|
await expect( page ).toFill( '#shipping_address_2', customerShippingDetails.addresssecondline );
|
|
|
|
await expect( page ).toFill( '#shipping_city', customerShippingDetails.city );
|
|
|
|
await expect( page ).toSelect( '#shipping_state', customerShippingDetails.state );
|
|
|
|
await expect( page ).toFill( '#shipping_postcode', customerShippingDetails.postcode );
|
2019-11-22 12:33:08 +00:00
|
|
|
},
|
|
|
|
|
2019-11-28 14:25:28 +00:00
|
|
|
removeFromCart: async ( productTitle ) => {
|
2019-12-04 19:03:35 +00:00
|
|
|
const cartItemXPath = getCartItemExpression(productTitle);
|
2019-11-28 14:25:28 +00:00
|
|
|
const removeItemXPath = cartItemXPath + '//' + getRemoveExpression();
|
|
|
|
|
2019-12-04 19:03:35 +00:00
|
|
|
const [removeButton] = await page.$x(removeItemXPath);
|
2019-11-28 14:25:28 +00:00
|
|
|
await removeButton.click();
|
2019-11-21 16:52:29 +00:00
|
|
|
},
|
2019-12-04 19:03:35 +00:00
|
|
|
|
2019-09-24 11:56:02 +00:00
|
|
|
setCartQuantity: async ( productTitle, quantityValue ) => {
|
|
|
|
const cartItemXPath = getCartItemExpression( productTitle );
|
|
|
|
const quantityInputXPath = cartItemXPath + '//' + getQtyInputExpression();
|
|
|
|
|
|
|
|
const [ quantityInput ] = await page.$x( quantityInputXPath );
|
|
|
|
await quantityInput.focus();
|
|
|
|
await pressKeyWithModifier( 'primary', 'a' );
|
|
|
|
await quantityInput.type( quantityValue.toString() );
|
|
|
|
},
|
2019-12-02 17:19:58 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
/*
|
|
|
|
* My Accounts flows.
|
|
|
|
*/
|
|
|
|
goToOrders: async () => {
|
|
|
|
await page.goto( MY_ACCOUNT_ORDERS, {
|
2019-08-29 16:09:42 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
2019-09-24 14:44:10 +00:00
|
|
|
},
|
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
goToDownloads: async () => {
|
|
|
|
await page.goto( MY_ACCOUNT_DOWNLOADS, {
|
2019-08-27 12:22:24 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
goToAddresses: async () => {
|
|
|
|
await page.goto( MY_ACCOUNT_ADDRESSES, {
|
2019-11-23 17:40:29 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
goToAccountDetails: async () => {
|
|
|
|
await page.goto( MY_ACCOUNT_ACCOUNT_DETAILS, {
|
2019-11-24 13:49:39 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
gotoMyAccount: gotoMyAccount,
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
login: async () => {
|
|
|
|
await gotoMyAccount();
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
await expect( page.title() ).resolves.toMatch( 'My account' );
|
2019-11-23 17:40:29 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
await page.type( '#username', config.get('users.customer.username') );
|
|
|
|
await page.type( '#password', config.get('users.customer.password') );
|
2020-12-11 04:27:04 +00:00
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
page.click( 'button[name="login"]' ),
|
|
|
|
] );
|
2020-12-11 04:27:04 +00:00
|
|
|
},
|
2019-08-27 12:22:24 +00:00
|
|
|
};
|
|
|
|
|
2020-12-22 13:59:16 +00:00
|
|
|
module.exports = shopper;
|