Skip to content

Commit 6c98912

Browse files
Update e2e tests all and atomic workflows (#10277)
Co-authored-by: Eduardo Umpierre <[email protected]>
1 parent 891d50e commit 6c98912

File tree

64 files changed

+392
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+392
-248
lines changed

.github/actions/e2e/run-log-tests/action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ runs:
99
# Use +e to trap errors when running E2E tests.
1010
shell: /bin/bash +e {0}
1111
run: |
12-
npm run test:e2e -- --json --outputFile="$E2E_RESULT_FILEPATH" --NODE_ENV="$NODE_ENV"
12+
npm run test:e2e-ci
1313
1414
if [[ -f "$E2E_RESULT_FILEPATH" ]]; then
15-
E2E_NUM_FAILED_TEST_SUITES=$(cat "$E2E_RESULT_FILEPATH" | jq '.numFailedTestSuites')
15+
E2E_NUM_FAILED_TEST_SUITES=$(cat "$E2E_RESULT_FILEPATH" | jq '.stats["unexpected"]')
1616
echo "FIRST_RUN_FAILED_TEST_SUITES=$(echo $E2E_NUM_FAILED_TEST_SUITES)" >> $GITHUB_OUTPUT
1717
if [[ ${E2E_NUM_FAILED_TEST_SUITES} -gt 0 ]]; then
1818
echo "::notice::${E2E_NUM_FAILED_TEST_SUITES} test suite(s) failed in the first run but we will try (it) them again in the second run."
@@ -30,18 +30,19 @@ runs:
3030
shell: bash
3131
# Filter failed E2E files from the result JSON file, and re-run them.
3232
run: |
33-
cat "$E2E_RESULT_FILEPATH" | jq '.testResults[] | select(.status == "failed") | .name' | xargs npm run test:e2e -- --NODE_ENV="$NODE_ENV"
33+
npm run test:e2e-ci $(cat $E2E_RESULT_FILEPATH | jq -r '[.suites[] | (if has("suites") then .suites[] | .specs[] else .specs[] end) | select(.tests[].status == "unexpected") | .file] | unique | .[]')
3434
3535
# Archive screenshots if any
3636
- name: Archive e2e test screenshots & logs
37-
if: ${{ failure() }}
37+
if: ${{ always() }}
3838
uses: actions/upload-artifact@v4
3939
with:
4040
name: wp(${{ env.E2E_WP_VERSION }})-wc(${{ env.E2E_WC_VERSION }})-${{ env.E2E_GROUP }}-${{ env.E2E_BRANCH }}
4141
path: |
4242
screenshots
4343
tests/e2e/screenshots
4444
tests/e2e/docker/wordpress/wp-content/debug.log
45+
tests/e2e-pw/test-results
4546
${{ env.E2E_RESULT_FILEPATH }}
4647
if-no-files-found: ignore
4748
retention-days: 14

.github/workflows/e2e-pull-request.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ env:
3030
E2E_SLACK_CHANNEL: ${{ secrets.E2E_SLACK_CHANNEL }}
3131
E2E_SLACK_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }}
3232
E2E_USE_LOCAL_SERVER: false
33-
E2E_RESULT_FILEPATH: 'tests/e2e/results.json'
33+
E2E_RESULT_FILEPATH: 'tests/e2e-pw/results.json'
3434
WCPAY_USE_BUILD_ARTIFACT: ${{ inputs.wcpay-use-build-artifact }}
3535
WCPAY_ARTIFACT_DIRECTORY: 'zipfile'
3636
NODE_ENV: 'test'
@@ -74,5 +74,9 @@ jobs:
7474
- name: Setup E2E environment
7575
uses: ./.github/actions/e2e/env-setup
7676

77+
- name: Install Playwright
78+
shell: bash
79+
run: npx playwright install chromium
80+
7781
- name: Run tests, upload screenshots & logs
7882
uses: ./.github/actions/e2e/run-log-tests

.github/workflows/e2e-test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
E2E_SLACK_CHANNEL: ${{ secrets.E2E_SLACK_CHANNEL }}
2323
E2E_SLACK_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }}
2424
E2E_USE_LOCAL_SERVER: false
25-
E2E_RESULT_FILEPATH: 'tests/e2e/results.json'
25+
E2E_RESULT_FILEPATH: 'tests/e2e-pw/results.json'
2626
WC_MIN_SUPPORTED_VERSION: '7.6.0'
2727
NODE_ENV: 'test'
2828
FORCE_E2E_DEPS_SETUP: true
@@ -64,6 +64,10 @@ jobs:
6464
- name: Setup E2E environment
6565
uses: ./.github/actions/e2e/env-setup
6666

67+
- name: Install Playwright
68+
shell: bash
69+
run: npx playwright install chromium
70+
6771
- name: Run tests, upload screenshots & logs
6872
uses: ./.github/actions/e2e/run-log-tests
6973

@@ -116,5 +120,9 @@ jobs:
116120
- name: Setup E2E environment
117121
uses: ./.github/actions/e2e/env-setup
118122

123+
- name: Install Playwright
124+
shell: bash
125+
run: npx playwright install chromium
126+
119127
- name: Run tests, upload screenshots & logs
120128
uses: ./.github/actions/e2e/run-log-tests
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: dev
3+
4+
Update Github actions and workflows. Change e2e tests directory structure.

tests/e2e-pw/playwright.config.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,30 @@ import path from 'path';
99
config( { path: path.resolve( __dirname, '../e2e/config', '.env' ) } );
1010
config( { path: path.resolve( __dirname, '../e2e/config', 'local.env' ) } );
1111

12-
const { BASE_URL } = process.env;
12+
const { BASE_URL, E2E_GROUP, E2E_BRANCH } = process.env;
13+
14+
const validGroups = [ 'wcpay', 'subscriptions' ];
15+
const validBranches = [ 'merchant', 'shopper' ];
16+
17+
const buildTestDir = ( group: string, branch: string ) => {
18+
const baseDir = `\/specs`;
19+
20+
if ( ! group || ! validGroups.includes( group ) ) {
21+
return baseDir;
22+
}
23+
24+
if ( ! branch || ! validBranches.includes( branch ) ) {
25+
return `${ baseDir }\/${ group }`;
26+
}
27+
28+
return `${ baseDir }\/${ group }\/${ branch }`;
29+
};
30+
31+
const getTestMatch = ( group: string, branch: string ) => {
32+
const testDir = buildTestDir( group, branch );
33+
34+
return new RegExp( `${ testDir }\/.*\.spec\.ts` );
35+
};
1336

1437
/**
1538
* See https://playwright.dev/docs/test-configuration.
@@ -29,6 +52,7 @@ export default defineConfig( {
2952
? [
3053
// If running on CI, also use the GitHub Actions reporter
3154
[ 'github' ],
55+
[ 'json', { outputFile: 'results.json' } ],
3256
[ 'html' ],
3357
]
3458
: [ [ 'html', { open: 'never' } ] ],
@@ -43,12 +67,17 @@ export default defineConfig( {
4367
},
4468
timeout: 120 * 1000, // Default is 30s, somteimes it is not enough for local tests due to long setup.
4569
expect: {
46-
toHaveScreenshot: { maxDiffPixelRatio: 0.025 },
70+
toHaveScreenshot: {
71+
maxDiffPixelRatio:
72+
process.env.E2E_WC_VERSION === '7.7.0' ? 0.035 : 0.025,
73+
},
4774
//=* Increase expect timeout to 10 seconds. See https://playwright.dev/docs/test-timeouts#set-expect-timeout-in-the-config.*/
4875
timeout: 20 * 1000,
4976
},
5077
snapshotPathTemplate: '{testDir}/__snapshots__/{testFilePath}/{arg}{ext}',
5178

79+
testMatch: getTestMatch( E2E_GROUP, E2E_BRANCH ),
80+
5281
/* Configure projects for major browsers */
5382
projects: [
5483
{
@@ -58,15 +87,8 @@ export default defineConfig( {
5887
dependencies: [ 'setup' ],
5988
},
6089
{
61-
name: 'merchant',
62-
use: { ...devices[ 'Desktop Chrome' ] },
63-
testDir: './specs/merchant',
64-
dependencies: [ 'setup' ],
65-
},
66-
{
67-
name: 'shopper',
90+
name: 'chromium',
6891
use: { ...devices[ 'Desktop Chrome' ] },
69-
testDir: './specs/shopper',
7092
dependencies: [ 'setup' ],
7193
},
7294
// Setup project

tests/e2e-pw/specs/merchant/merchant-subscriptions-renew-action-scheduler.spec.ts renamed to tests/e2e-pw/specs/subscriptions/merchant/merchant-subscriptions-renew-action-scheduler.spec.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { test, expect } from '@playwright/test';
66
/**
77
* Internal dependencies
88
*/
9-
import { describeif, getMerchant, getShopper } from '../../utils/helpers';
10-
import * as shopper from '../../utils/shopper';
11-
import { config } from '../../config/default';
9+
import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
10+
import * as shopper from '../../../utils/shopper';
11+
import { config } from '../../../config/default';
1212
import {
1313
products,
1414
shouldRunActionSchedulerTests,
1515
shouldRunSubscriptionsTests,
16-
} from '../../utils/constants';
16+
} from '../../../utils/constants';
1717
import {
1818
goToActionScheduler,
1919
goToSubscriptions,
20-
} from '../../utils/merchant-navigation';
20+
} from '../../../utils/merchant-navigation';
2121

2222
// Run the tests if the two 'skip' environment variables are not set.
2323
describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
@@ -29,8 +29,6 @@ describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
2929
const customerBillingConfig =
3030
config.addresses[ 'subscriptions-customer' ].billing;
3131

32-
let subscriptionId: string;
33-
3432
test.beforeAll( async ( { browser }, { project } ) => {
3533
const { shopperPage } = await getShopper(
3634
browser,
@@ -48,10 +46,6 @@ describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
4846
await expect(
4947
shopperPage.getByRole( 'heading', { name: 'Order received' } )
5048
).toBeVisible();
51-
52-
subscriptionId = await shopperPage
53-
.getByLabel( 'View subscription number' )
54-
.innerText();
5549
} );
5650

5751
test( 'should renew a subscription with action scheduler', async ( {
@@ -81,12 +75,8 @@ describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
8175
// Go to Subscriptions and verify the subscription renewal
8276
await goToSubscriptions( merchantPage );
8377

84-
const numericSubscriptionId = subscriptionId.substring( 1 );
85-
8678
await expect(
87-
merchantPage
88-
.locator( `#order-${ numericSubscriptionId }` )
89-
.getByRole( 'cell', { name: '2', exact: true } )
79+
merchantPage.getByRole( 'cell', { name: '2', exact: true } )
9080
).toBeVisible();
9181
} );
9282
}

tests/e2e-pw/specs/merchant/merchant-subscriptions-renew.spec.ts renamed to tests/e2e-pw/specs/subscriptions/merchant/merchant-subscriptions-renew.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { test, expect } from '@playwright/test';
66
/**
77
* Internal dependencies
88
*/
9-
import RestAPI from '../../utils/rest-api';
10-
import { config } from '../../config/default';
11-
import { describeif, getMerchant, getShopper } from '../../utils/helpers';
9+
import RestAPI from '../../../utils/rest-api';
10+
import { config } from '../../../config/default';
11+
import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
1212
import {
1313
emptyCart,
1414
fillCardDetails,
1515
focusPlaceOrderButton,
1616
placeOrder,
1717
setupProductCheckout,
18-
} from '../../utils/shopper';
19-
import { goToShop } from '../../utils/shopper-navigation';
20-
import { goToSubscriptionPage } from '../../utils/merchant-navigation';
21-
import { shouldRunSubscriptionsTests } from '../../utils/constants';
18+
} from '../../../utils/shopper';
19+
import { goToShop } from '../../../utils/shopper-navigation';
20+
import { goToSubscriptionPage } from '../../../utils/merchant-navigation';
21+
import { shouldRunSubscriptionsTests } from '../../../utils/constants';
2222

2323
const productName = 'Subscription signup fee product';
2424
const customerBillingConfig =

tests/e2e-pw/specs/merchant/merchant-subscriptions-settings.spec.ts renamed to tests/e2e-pw/specs/subscriptions/merchant/merchant-subscriptions-settings.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* External dependencies
33
*/
44
import test, { expect } from 'playwright/test';
5-
import { describeif, useMerchant } from '../../utils/helpers';
6-
import { shouldRunSubscriptionsTests } from '../../utils/constants';
7-
import { goToWooCommerceSettings } from '../../utils/merchant-navigation';
5+
import { describeif, useMerchant } from '../../../utils/helpers';
6+
import { shouldRunSubscriptionsTests } from '../../../utils/constants';
7+
import { goToWooCommerceSettings } from '../../../utils/merchant-navigation';
88

99
describeif( shouldRunSubscriptionsTests )(
1010
'WooCommerce > Settings > Subscriptions',
@@ -21,9 +21,11 @@ describeif( shouldRunSubscriptionsTests )(
2121
await expect( menuItem ).toBeVisible();
2222

2323
// An alternative way to verify the subscriptions menu page is active, avoiding the active tab classname.
24-
const heading = await page.getByRole( 'heading', {
25-
name: 'Subscriptions',
26-
} );
24+
const heading = await page
25+
.getByRole( 'heading', {
26+
name: 'Subscriptions',
27+
} )
28+
.first();
2729
await expect( heading ).toBeVisible();
2830
} );
2931
}

tests/e2e-pw/specs/shopper/shopper-subscriptions-manage-payments.spec.ts renamed to tests/e2e-pw/specs/subscriptions/shopper/shopper-subscriptions-manage-payments.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import test, { expect, Page } from '@playwright/test';
66
/**
77
* Internal dependencies
88
*/
9-
import { config } from '../../config/default';
10-
import { products, shouldRunSubscriptionsTests } from '../../utils/constants';
11-
import { describeif, getShopper } from '../../utils/helpers';
12-
import * as shopper from '../../utils/shopper';
13-
import * as navigation from '../../utils/shopper-navigation';
9+
import { config } from '../../../config/default';
10+
import {
11+
products,
12+
shouldRunSubscriptionsTests,
13+
} from '../../../utils/constants';
14+
import { describeif, getShopper } from '../../../utils/helpers';
15+
import * as shopper from '../../../utils/shopper';
16+
import * as navigation from '../../../utils/shopper-navigation';
1417

1518
const navigateToSubscriptionDetails = async (
1619
page: Page,

tests/e2e-pw/specs/shopper/shopper-subscriptions-purchase-free-trial.spec.ts renamed to tests/e2e-pw/specs/subscriptions/shopper/shopper-subscriptions-purchase-free-trial.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ import test, { Page, expect } from '@playwright/test';
66
/**
77
* Internal dependencies
88
*/
9-
import { shouldRunSubscriptionsTests } from '../../utils/constants';
10-
import { describeif, getMerchant, getShopper } from '../../utils/helpers';
11-
import { config } from '../../config/default';
9+
import { shouldRunSubscriptionsTests } from '../../../utils/constants';
10+
import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
11+
import { config } from '../../../config/default';
1212
import {
1313
confirmCardAuthentication,
1414
emptyCart,
1515
fillCardDetails,
1616
setupCheckout,
17-
} from '../../utils/shopper';
17+
} from '../../../utils/shopper';
1818
import {
1919
goToCart,
2020
goToProductPageBySlug,
21-
} from '../../utils/shopper-navigation';
22-
import { goToOrder, goToSubscriptions } from '../../utils/merchant-navigation';
21+
} from '../../../utils/shopper-navigation';
22+
import {
23+
goToOrder,
24+
goToSubscriptions,
25+
} from '../../../utils/merchant-navigation';
2326
import {
2427
activateMulticurrency,
2528
deactivateMulticurrency,
2629
isMulticurrencyEnabled,
27-
} from '../../utils/merchant';
30+
} from '../../../utils/merchant';
2831

2932
const nowLocal = new Date();
3033
const nowUTC = new Date(

tests/e2e-pw/specs/shopper/shopper-subscriptions-purchase-multiple-subscriptions.spec.ts renamed to tests/e2e-pw/specs/subscriptions/shopper/shopper-subscriptions-purchase-multiple-subscriptions.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import test, { Page, expect } from '@playwright/test';
66
/**
77
* Internal dependencies
88
*/
9-
import { shouldRunSubscriptionsTests } from '../../utils/constants';
10-
import { describeif, getMerchant, getShopper } from '../../utils/helpers';
11-
import { config } from '../../config/default';
9+
import { shouldRunSubscriptionsTests } from '../../../utils/constants';
10+
import { describeif, getMerchant, getShopper } from '../../../utils/helpers';
11+
import { config } from '../../../config/default';
1212
import {
1313
emptyCart,
1414
fillCardDetails,
1515
placeOrder,
1616
setupProductCheckout,
17-
} from '../../utils/shopper';
17+
} from '../../../utils/shopper';
1818
import {
1919
goToShop,
2020
goToShopWithCurrency,
2121
goToSubscriptions,
22-
} from '../../utils/shopper-navigation';
22+
} from '../../../utils/shopper-navigation';
2323
import {
2424
activateMulticurrency,
2525
deactivateMulticurrency,
2626
restoreCurrencies,
27-
} from '../../utils/merchant';
27+
} from '../../../utils/merchant';
2828

2929
const products = {
3030
'Subscription no signup fee product': 'subscription-no-signup-fee-product',

0 commit comments

Comments
 (0)