Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate multi-currency e2e tests to Playwright #9175

Merged
merged 41 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3848338
Create merchant navigation helper
cesarcosta99 Jul 25, 2024
22e9b6a
Refactor goToOrder helper import
cesarcosta99 Jul 25, 2024
5d27804
Add new multi-currency helpers
cesarcosta99 Jul 25, 2024
66b7ef0
Migrate admin multi-currency spec to Playwright
cesarcosta99 Jul 25, 2024
3f4077a
Update comment
cesarcosta99 Jul 25, 2024
32b03fe
Add more multi-currency helpers
cesarcosta99 Jul 26, 2024
d30f772
Add data has loaded helper
cesarcosta99 Jul 26, 2024
5fb35c1
Add more navigation helpers
cesarcosta99 Jul 26, 2024
bd9115b
Update snapshot
cesarcosta99 Jul 26, 2024
075fb3e
Start migrating multi-currency onboarding spec
cesarcosta99 Jul 26, 2024
18f8193
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Jul 29, 2024
c402fdf
Add changelog entry
cesarcosta99 Jul 29, 2024
fb7165e
Replace snackbar selector
cesarcosta99 Jul 29, 2024
b100495
Refactor disable all currencies helper
cesarcosta99 Jul 29, 2024
07acd7c
Fix activate theme helper
cesarcosta99 Jul 29, 2024
4306474
Finish migrating multi-currency onboarding spec
cesarcosta99 Jul 29, 2024
ebe6d0a
Make sure spec starts with right state
cesarcosta99 Jul 29, 2024
c97aa05
Create shopper navigation helper
cesarcosta99 Aug 1, 2024
43af716
Add get price from product helper
cesarcosta99 Aug 1, 2024
3abb4d1
Add more merchant helpers
cesarcosta99 Aug 1, 2024
e339897
Migrate multi-currency setup spec to Playwright
cesarcosta99 Aug 1, 2024
f2056df
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Aug 1, 2024
c4aa764
Add more shopper navigation helpers
cesarcosta99 Aug 2, 2024
acbb10f
Add more shopper helpers
cesarcosta99 Aug 2, 2024
e30e78c
Migrate multi-currency checkout spec to Playwright
cesarcosta99 Aug 2, 2024
f5b49d9
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Aug 2, 2024
0d0909f
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Aug 5, 2024
12078a5
Remove old specs
cesarcosta99 Aug 6, 2024
35431b3
Rename multi-currency specs under the merchant domain
cesarcosta99 Aug 6, 2024
4d46620
Rename multi-currency specs under the shopper domain
cesarcosta99 Aug 6, 2024
aaa03e8
Make sure onboarding screenshot is captured correctly
cesarcosta99 Aug 8, 2024
91628d4
Update comment
cesarcosta99 Aug 9, 2024
83713cc
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Aug 15, 2024
15559af
Add empty cart shopper helper
cesarcosta99 Aug 15, 2024
e749c65
Apply small changes to make the tests more stable
cesarcosta99 Aug 15, 2024
2083568
Remove explicit return types to let TS infer
cesarcosta99 Aug 15, 2024
898bd3c
Make sure Place Order button is ready before clicking on it
cesarcosta99 Aug 15, 2024
ca1e6c1
Unify checkout tests and turn them into steps
cesarcosta99 Aug 18, 2024
b5746ff
Add extra assertion before taking screenshot
cesarcosta99 Aug 18, 2024
0845c7e
Change selector to be compatible with older versions of WC
cesarcosta99 Aug 20, 2024
2fed4d8
Merge branch 'develop' into dev/8750-migrate-mccy-e2e-tests-to-playwr…
cesarcosta99 Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/dev-8750-migrate-mccy-e2e-tests-to-playwright
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Migrate multi-currency e2e tests to Playwright.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import * as shopper from '../../utils/shopper';
import { config } from '../../config/default';
import { getMerchant, getShopper } from '../../utils/helpers';
import * as merchant from '../../utils/merchant';
import { goToOrder } from '../../utils/merchant-navigation';

test.describe(
'Disputes > View dispute details via disputed order notice',
() => {
let orderId: string;

test.beforeEach( async ( { browser } ) => {

Check failure on line 19 in tests/e2e-pw/specs/merchant/merchant-disputes-view-details-via-order-notice.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-disputes-view-details-via-order-notice.spec.ts:43:7 › Disputes > View dispute details via disputed order notice › should navigate to dispute details when disputed order notice button clicked

1) [merchant] › merchant/merchant-disputes-view-details-via-order-notice.spec.ts:43:7 › Disputes > View dispute details via disputed order notice › should navigate to dispute details when disputed order notice button clicked Test timeout of 120000ms exceeded while running "beforeEach" hook. 17 | let orderId: string; 18 | > 19 | test.beforeEach( async ( { browser } ) => { | ^ 20 | const { shopperPage } = await getShopper( browser ); 21 | // Place an order to dispute later 22 | await shopperPage.goto( '/cart/' ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-disputes-view-details-via-order-notice.spec.ts:19:8
const { shopperPage } = await getShopper( browser );
// Place an order to dispute later
await shopperPage.goto( '/cart/' );
Expand All @@ -37,14 +37,14 @@
const orderIdField = shopperPage.locator(
'.woocommerce-order-overview__order.order > strong'
);
orderId = await orderIdField.innerText();

Check failure on line 40 in tests/e2e-pw/specs/merchant/merchant-disputes-view-details-via-order-notice.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-disputes-view-details-via-order-notice.spec.ts:43:7 › Disputes > View dispute details via disputed order notice › should navigate to dispute details when disputed order notice button clicked

1) [merchant] › merchant/merchant-disputes-view-details-via-order-notice.spec.ts:43:7 › Disputes > View dispute details via disputed order notice › should navigate to dispute details when disputed order notice button clicked Error: locator.innerText: Test ended. Call log: - waiting for locator('.woocommerce-order-overview__order.order > strong') 38 | '.woocommerce-order-overview__order.order > strong' 39 | ); > 40 | orderId = await orderIdField.innerText(); | ^ 41 | } ); 42 | 43 | test( 'should navigate to dispute details when disputed order notice button clicked', async ( { at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-disputes-view-details-via-order-notice.spec.ts:40:33
} );

test( 'should navigate to dispute details when disputed order notice button clicked', async ( {
browser,
} ) => {
const { merchantPage } = await getMerchant( browser );
await merchant.goToOrder( merchantPage, orderId );
await goToOrder( merchantPage, orderId );

// If WC < 7.9, return early since the order dispute notice is not present.
const orderPaymentDetailsContainerVisible = await merchantPage
Expand Down
223 changes: 223 additions & 0 deletions tests/e2e-pw/specs/merchant/multi-currency-on-boarding.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/**
* External dependencies
*/
import { test, expect, Page } from '@playwright/test';
/**
* Internal dependencies
*/
import { useMerchant } from '../../utils/helpers';
import {
activateMulticurrency,
activateTheme,
addCurrency,
deactivateMulticurrency,
disableAllEnabledCurrencies,
getActiveThemeSlug,
removeCurrency,
} from '../../utils/merchant';
import * as navigation from '../../utils/merchant-navigation';

test.describe( 'Multi-currency on-boarding', () => {
let page: Page;
let wasMulticurrencyEnabled: boolean;
let activeThemeSlug: string;
const goToNextOnboardingStep = async ( currentPage: Page ) => {
await currentPage
.locator( '.wcpay-wizard-task.is-active button.is-primary' )
.click();
};

useMerchant();

test.beforeAll( async ( { browser } ) => {
page = await browser.newPage();
wasMulticurrencyEnabled = await activateMulticurrency( page );
activeThemeSlug = await getActiveThemeSlug( page );
} );

test.afterAll( async () => {
// Restore original theme.
await activateTheme( page, activeThemeSlug );

if ( ! wasMulticurrencyEnabled ) {
await deactivateMulticurrency( page );
}

await page.close();
} );

test.describe( 'Currency selection and management', () => {
test.beforeAll( async () => {
await disableAllEnabledCurrencies( page );
} );

test.beforeEach( async () => {
await navigation.goToMultiCurrencyOnboarding( page );
} );

test( 'should disable the submit button when no currencies are selected', async () => {
// To take a better screenshot of the component.
await page.setViewportSize( { width: 1280, height: 2000 } );
await expect(
page.locator(
'.multi-currency-setup-wizard > div > .components-card-body'
)
).toHaveScreenshot();
// Set the viewport back to the default size.
await page.setViewportSize( { width: 1280, height: 720 } );

const checkboxes = await page
.locator(
'li.enabled-currency-checkbox .components-checkbox-control__input'
)
.all();

for ( const checkbox of checkboxes ) {
await checkbox.uncheck();
}

await expect(
page.getByRole( 'button', { name: 'Add currencies' } )
).toBeDisabled();
} );

test( 'should allow multiple currencies to be selected', async () => {
const currenciesNotInRecommendedList = await page
.locator(
'li.enabled-currency-checkbox:not([data-testid="recommended-currency"]) input[type="checkbox"]'
)
.all();

// We don't need to check them all.
const maximumCurrencies =
currenciesNotInRecommendedList.length > 3
? 3
: currenciesNotInRecommendedList.length;

for ( let i = 0; i < maximumCurrencies; i++ ) {
await expect(
currenciesNotInRecommendedList[ i ]
).toBeEnabled();
await currenciesNotInRecommendedList[ i ].check();
await expect(
currenciesNotInRecommendedList[ i ]
).toBeChecked();
}
} );

test( 'should exclude already enabled currencies from the onboarding', async () => {
await addCurrency( page, 'GBP' );
await navigation.goToMultiCurrencyOnboarding( page );

const recommendedCurrencies = await page
.getByTestId( 'recommended-currency' )
.allTextContents();

for ( const currency of recommendedCurrencies ) {
expect( currency ).not.toMatch( /GBP/ );
}

await removeCurrency( page, 'GBP' );
} );

test( 'should display suggested currencies at the beginning of the list', async () => {
await expect(
( await page.getByTestId( 'recommended-currency' ).all() )
.length
).toBeGreaterThan( 0 );
} );

test( 'selected currencies are enabled after onboarding', async () => {
const currencyCodes = [ 'GBP', 'EUR', 'CAD', 'AUD' ];

for ( const currencyCode of currencyCodes ) {
await page
.locator(
`input[type="checkbox"][code="${ currencyCode }"]`
)
.check();
}

await goToNextOnboardingStep( page );
await navigation.goToMultiCurrencySettings( page );

// Ensure the currencies are enabled.
for ( const currencyCode of currencyCodes ) {
await expect(
page.locator(
`li.enabled-currency.${ currencyCode.toLowerCase() }`
)
).toBeVisible();
}
} );
} );

test.describe( 'Geolocation features', () => {
test( 'should offer currency switch by geolocation', async () => {
await navigation.goToMultiCurrencyOnboarding( page );
await goToNextOnboardingStep( page );
await page.getByTestId( 'enable_auto_currency' ).check();
await expect(
page.getByTestId( 'enable_auto_currency' )
).toBeChecked();
} );

test( 'should preview currency switch by geolocation correctly with USD and GBP', async () => {
await addCurrency( page, 'GBP' );
await navigation.goToMultiCurrencyOnboarding( page );
// To take a better screenshot of the iframe preview.
await page.setViewportSize( { width: 1280, height: 1280 } );
await goToNextOnboardingStep( page );
await expect(
page.locator( '.wcpay-wizard-task.is-active' )
).toHaveScreenshot();
await page.getByTestId( 'enable_auto_currency' ).check();
await page.getByRole( 'button', { name: 'Preview' } ).click();

const previewIframe = await page.locator(
'.multi-currency-store-settings-preview-iframe'
);

await expect( previewIframe ).toBeVisible();

const previewPage = previewIframe.contentFrame();

await expect(
await previewPage.locator( '.woocommerce-store-notice' )
).toBeVisible();
await expect(
page.locator( '.multi-currency-store-settings-preview-iframe' )
).toHaveScreenshot();

const noticeText = await previewPage
.locator( '.woocommerce-store-notice' )
.innerText();

expect( noticeText ).toContain(
"We noticed you're visiting from United Kingdom (UK). We've updated our prices to Pound sterling for your shopping convenience."
);
} );
} );

test.describe( 'Currency Switcher widget', () => {
test( 'should offer the currency switcher widget while Storefront theme is active', async () => {
await activateTheme( page, 'storefront' );
await navigation.goToMultiCurrencyOnboarding( page );
await goToNextOnboardingStep( page );
await page.getByTestId( 'enable_storefront_switcher' ).check();
await expect(
page.getByTestId( 'enable_storefront_switcher' )
).toBeChecked();
} );

test( 'should not offer the currency switcher widget when an unsupported theme is active', async () => {
await activateTheme( page, 'twentytwentyfour' );
await navigation.goToMultiCurrencyOnboarding( page );
await goToNextOnboardingStep( page );
await expect(
page.getByTestId( 'enable_storefront_switcher' )
).toBeHidden();
await activateTheme( page, 'storefront' );
} );
} );
} );
Loading
Loading