packages/js/email-editor/writing-e2e-tests.md
Environment Setup:
# From repository root
nvm use
pnpm install
pnpm --filter='@woocommerce/plugin-woocommerce' build
cd plugins/woocommerce
pnpm env:start
or
# From anywhere
pnpm --filter='@woocommerce/plugin-woocommerce' build
pnpm --filter='@woocommerce/plugin-woocommerce' wp-env start
Required Dependencies:
const { test, expect } = require('@playwright/test');
const { ADMIN_STATE_PATH } = require('../../playwright.config');
const {
enableEmailEditor,
disableEmailEditor
} = require('./helpers/enable-email-editor-feature');
const {
accessTheEmailEditor,
ensureEmailEditorSettingsPanelIsOpened
} = require('../../utils/email');
test.describe('WooCommerce Email Editor', () => {
test.use({ storageState: ADMIN_STATE_PATH });
test.beforeAll(async ({ baseURL }) => {
await enableEmailEditor(baseURL);
});
test.afterAll(async ({ baseURL }) => {
await disableEmailEditor(baseURL);
});
test('Your test name', async ({ page }) => {
// Test implementation
});
});
tests/e2e-pw/tests/email-editor/.spec.js extensiontest.describe()test('Can perform specific action', async ({ page }) => {
// Setup
await accessTheEmailEditor(page, 'New order');
// Action
await page.getByRole('button', { name: 'Settings' }).click();
// Assertion
await expect(page.locator('.editor-post-status__toggle'))
.toContainText('Enabled');
});
test('Can access the email editor', async ({ page }) => {
await accessTheEmailEditor(page, 'New order');
await page.getByRole('tab', { name: 'Email' }).click();
await expect(page.locator('.editor-post-card-panel__title'))
.toContainText('New order');
});
test('Can update email settings', async ({ page }) => {
await accessTheEmailEditor(page, 'Customer note');
await page.getByLabel('Email')
.getByRole('button', { name: 'Settings' })
.click();
await ensureEmailEditorSettingsPanelIsOpened(page);
// Update settings
await page.locator('[data-automation-id="email_subject"]')
.fill('New Subject');
// Save changes
await page.getByRole('button', { name: 'Save' }).click();
// Verify changes
await expect(page.locator('[data-automation-id="email_subject"]'))
.toContainText('New Subject');
});
Note: If updating the WC_Email options, remember to reset to default. This can be done with
test.afterAll( async ( { baseURL } ) => {
await resetWCTransactionalEmail( baseURL, EMAIL_ID );
} );
Test Isolation:
beforeAll and afterAll for setup/teardownSelectors:
getByRole()[data-automation-id="..."] or page.getByTestId(...)Assertions:
Error Handling:
Running Tests in Debug Mode:
pnpm test:e2e --debug
Running tests with browser window visible:
pnpm test:e2e --headed
Taking Screenshots:
await page.screenshot({ path: 'debug-screenshot.png' });
Viewing Test Reports:
pnpm test:e2e --ui
Running a single file test:
pnpm test:e2e email-editor-loads.spec
Running a specific folder:
pnpm test:e2e email-editor