Skip to content

Commit 623b57d

Browse files
tpaksuismaeldcom
andauthored
Port admin analytics E2E tests from Puppeteer to Playwright (#10127)
Co-authored-by: Ismael Martín Alabarce <[email protected]>
1 parent 9bdf4e7 commit 623b57d

File tree

8 files changed

+154
-74
lines changed

8 files changed

+154
-74
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: add
3+
4+
Admin analytics page E2E tests for Playwright
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { test, expect } from '@playwright/test';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import * as shopper from '../../utils/shopper';
10+
import { getMerchant, getShopper, useMerchant } from '../../utils/helpers';
11+
import {
12+
activateMulticurrency,
13+
ensureOrderIsProcessed,
14+
isMulticurrencyEnabled,
15+
tableDataHasLoaded,
16+
waitAndSkipTourComponent,
17+
} from '../../utils/merchant';
18+
import { goToOrderAnalytics } from '../../utils/merchant-navigation';
19+
20+
test.describe( 'Admin order analytics', () => {
21+
let orderId: string;
22+
23+
// Use the merchant user for this test suite.
24+
useMerchant();
25+
26+
test.beforeAll( async ( { browser } ) => {
27+
const { shopperPage } = await getShopper( browser );
28+
const { merchantPage } = await getMerchant( browser );
29+
30+
if ( false === ( await isMulticurrencyEnabled( merchantPage ) ) ) {
31+
await activateMulticurrency( merchantPage );
32+
}
33+
34+
// Place an order to ensure the analytics data is correct.
35+
orderId = await shopper.placeOrderWithCurrency( shopperPage, 'USD' );
36+
await ensureOrderIsProcessed( merchantPage, orderId );
37+
} );
38+
39+
test( 'should load without any errors', async ( { browser } ) => {
40+
const { merchantPage } = await getMerchant( browser );
41+
await goToOrderAnalytics( merchantPage );
42+
await tableDataHasLoaded( merchantPage );
43+
await waitAndSkipTourComponent(
44+
merchantPage,
45+
'.woocommerce-revenue-report-date-tour'
46+
);
47+
48+
const ordersTitle = merchantPage.getByRole( 'heading', {
49+
name: 'Orders',
50+
level: 1,
51+
exact: true,
52+
} );
53+
await expect( ordersTitle ).toBeVisible();
54+
await expect( merchantPage ).toHaveScreenshot();
55+
} );
56+
57+
test( 'orders table should have the customer currency column', async ( {
58+
browser,
59+
} ) => {
60+
const { merchantPage } = await getMerchant( browser );
61+
await goToOrderAnalytics( merchantPage );
62+
await tableDataHasLoaded( merchantPage );
63+
await waitAndSkipTourComponent(
64+
merchantPage,
65+
'.woocommerce-revenue-report-date-tour'
66+
);
67+
68+
const columnToggle = merchantPage.getByTitle(
69+
'Choose which values to display'
70+
);
71+
await columnToggle.click();
72+
const customerCurrencyToggle = merchantPage.getByRole(
73+
'menuitemcheckbox',
74+
{
75+
name: 'Customer Currency',
76+
}
77+
);
78+
await expect( customerCurrencyToggle ).toBeVisible();
79+
await customerCurrencyToggle.click();
80+
const customerCurrencyColumn = merchantPage.getByRole( 'columnheader', {
81+
name: 'Customer Currency',
82+
} );
83+
await expect( customerCurrencyColumn ).toBeVisible();
84+
} );
85+
} );

tests/e2e-pw/utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const customerStorageFile = path.resolve(
2020
export const wpAdminLogin = async (
2121
page: Page,
2222
user: { username: string; password: string }
23-
): void => {
23+
): Promise< void > => {
2424
await page.goto( `/wp-admin` );
2525
await page.getByLabel( 'Username or Email Address' ).fill( user.username );
2626
await page.getByLabel( 'Password', { exact: true } ).fill( user.password ); // Need exact match to avoid resolving "Show password" button.

tests/e2e-pw/utils/merchant-navigation.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ export const goToWooPaymentsSettings = async ( page: Page ) => {
2323
);
2424
};
2525

26+
export const goToOptionsPage = async ( page: Page ) => {
27+
await page.goto( '/wp-admin/options.php', {
28+
waitUntil: 'load',
29+
} );
30+
};
31+
32+
export const goToActionScheduler = async (
33+
page: Page,
34+
status?: string,
35+
search?: string
36+
) => {
37+
let pageUrl = '/wp-admin/tools.php?page=action-scheduler';
38+
if ( status ) {
39+
pageUrl += `&status=${ status }`;
40+
}
41+
if ( search ) {
42+
pageUrl += `&s=${ search }`;
43+
}
44+
await page.goto( pageUrl, {
45+
waitUntil: 'load',
46+
} );
47+
};
48+
49+
export const goToOrderAnalytics = async ( page: Page ) => {
50+
await page.goto(
51+
'/wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Forders',
52+
{ waitUntil: 'load' }
53+
);
54+
await dataHasLoaded( page );
55+
};
56+
2657
export const goToMultiCurrencySettings = async ( page: Page ) => {
2758
await page.goto(
2859
'/wp-admin/admin.php?page=wc-settings&tab=wcpay_multi_currency',

tests/e2e-pw/utils/merchant.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ export const dataHasLoaded = async ( page: Page ) => {
1414
await expect( page.locator( '.is-loadable-placeholder' ) ).toHaveCount( 0 );
1515
};
1616

17+
export const tableDataHasLoaded = async ( page: Page ) => {
18+
await page
19+
.locator( '.woocommerce-table__table.is-loading' )
20+
.waitFor( { state: 'hidden' } );
21+
};
22+
23+
export const waitAndSkipTourComponent = async (
24+
page: Page,
25+
containerClass: string
26+
) => {
27+
try {
28+
await page.waitForSelector( `${ containerClass }`, { timeout: 3000 } );
29+
if ( await page.isVisible( `${ containerClass }` ) ) {
30+
await page.click(
31+
`${ containerClass } button.woocommerce-tour-kit-step-controls__close-btn`
32+
);
33+
}
34+
} catch ( error ) {
35+
// Do nothing. The tour component being not present shouldn't cause the test to fail.
36+
}
37+
};
38+
1739
export const saveWooPaymentsSettings = async ( page: Page ) => {
1840
await page.getByRole( 'button', { name: 'Save changes' } ).click();
1941
await expect( page.getByLabel( 'Dismiss this notice' ) ).toBeVisible( {
@@ -251,6 +273,14 @@ export const disablePaymentMethods = async (
251273
await saveWooPaymentsSettings( page );
252274
};
253275

276+
export const ensureOrderIsProcessed = async ( page: Page, orderId: string ) => {
277+
await navigation.goToActionScheduler( page, 'pending', orderId );
278+
await page.$eval(
279+
'td:has-text("wc-admin_import_orders") a:has-text("Run")',
280+
( el: HTMLLinkElement ) => el.click()
281+
);
282+
};
283+
254284
export const isWooPayEnabled = async ( page: Page ) => {
255285
await navigation.goToWooPaymentsSettings( page );
256286

tests/e2e/env/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ cli wp db query "DELETE p, m FROM wp_posts p LEFT JOIN wp_postmeta m ON p.ID = m
345345
echo "Setting up a coupon for E2E tests"
346346
cli wp wc --user=admin shop_coupon create --code=free --amount=100 --discount_type=percent --individual_use=true --free_shipping=true
347347

348+
echo "Syncing COT data"
349+
cli wp wc cot sync
350+
348351
# Log test configuration for visibility
349352
echo
350353
echo "*******************************************************"

tests/e2e/specs/wcpay/merchant/merchant-admin-analytics.spec.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)