Skip to content

Commit

Permalink
Merge pull request woocommerce#33139 from woocommerce/e2e/rep-playwri…
Browse files Browse the repository at this point in the history
…ght-feature-flag

Run Playwright tests behind feature flag
  • Loading branch information
lanej0 authored May 25, 2022
2 parents 4c22d92 + cb36fe8 commit f70afcc
Show file tree
Hide file tree
Showing 41 changed files with 4,126 additions and 27 deletions.
73 changes: 67 additions & 6 deletions .github/workflows/pr-build-and-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ on:
pull_request:
workflow_dispatch:

concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
E2E_PLAYWRIGHT: ${{ false }}

jobs:
e2e-tests-run:
name: Runs E2E tests.
Expand All @@ -31,13 +34,51 @@ jobs:
run: pnpm exec wc-e2e docker:up

- name: Run tests command.
if: env.E2E_PLAYWRIGHT != 'true'
working-directory: plugins/woocommerce
env:
WC_E2E_SCREENSHOTS: 1
E2E_SLACK_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }}
E2E_SLACK_CHANNEL: ${{ secrets.E2E_SLACK_CHANNEL }}
run: pnpm exec wc-e2e test:e2e

- name: Download and install Chromium browser.
if: env.E2E_PLAYWRIGHT == 'true'
working-directory: plugins/woocommerce
run: pnpx playwright install chromium

- name: Run (Playwright) tests command.
id: run_playwright_e2e_tests
if: env.E2E_PLAYWRIGHT == 'true'
working-directory: plugins/woocommerce
run: pnpx playwright test --config=e2e/playwright.config.js

- name: Generate (Playwright) E2E Test report.
id: generate_e2e_report
if: |
always() &&
( env.E2E_PLAYWRIGHT == 'true' ) &&
(
steps.run_playwright_e2e_tests.conclusion != 'cancelled' ||
steps.run_playwright_e2e_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpx allure generate --clean e2e/allure-results --output e2e/allure-report

- name: Archive (Playwright) E2E test report
if: |
always() &&
env.E2E_PLAYWRIGHT == 'true' &&
steps.generate_e2e_report.conclusion == 'success'
uses: actions/upload-artifact@v3
with:
name: e2e-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
if-no-files-found: ignore
retention-days: 5

- name: Archive E2E test screenshots
uses: actions/upload-artifact@v3
if: always()
Expand All @@ -62,7 +103,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '7.4'

- name: Install and Build
uses: ./.github/actions/install-build
Expand All @@ -87,7 +128,7 @@ jobs:
path: |
${{ env.API_TEST_REPORT_DIR }}/allure-results
${{ env.API_TEST_REPORT_DIR }}/allure-report
retention-days: 7
retention-days: 5

k6-tests-run:
name: Runs k6 Performance tests
Expand All @@ -102,7 +143,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '7.4'

- name: Install and Build
uses: ./.github/actions/install-build
Expand All @@ -126,8 +167,13 @@ jobs:
publish-test-reports:
name: Publish test reports
if: always() && (contains( needs.*.result, 'success' ) || contains( needs.*.result, 'failure' ))
runs-on: ubuntu-18.04
if: |
always() &&
(
contains( needs.*.result, 'success' ) ||
contains( needs.*.result, 'failure' )
)
runs-on: ubuntu-20.04
needs: [api-tests-run, e2e-tests-run, k6-tests-run]
env:
GITHUB_TOKEN: ${{ secrets.REPORTS_TOKEN }}
Expand All @@ -136,6 +182,7 @@ jobs:
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
steps:
- name: Publish API test report
if: env.E2E_PLAYWRIGHT != 'true'
env:
ARTIFACT_NAME: api-test-report---pr-${{ github.event.number }}
run: |
Expand All @@ -148,3 +195,17 @@ jobs:
-f commit_sha=$COMMIT_SHA \
--repo woocommerce/woocommerce-test-reports
- name: Publish API and (Playwright) E2E test reports
if: env.E2E_PLAYWRIGHT == 'true'
env:
API_ARTIFACT: api-test-report---pr-${{ github.event.number }}
E2E_ARTIFACT: e2e-test-report---pr-${{ github.event.number }}
run: |
gh workflow run publish-reports.yml \
-f test_workflow=pr \
-f run_id=$RUN_ID \
-f api_artifact=$API_ARTIFACT \
-f e2e_artifact=$E2E_ARTIFACT \
-f pr_number=$PR_NUMBER \
-f commit_sha=$COMMIT_SHA \
--repo woocommerce/woocommerce-test-reports
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ plugins/woocommerce/includes/react-admin/feature-config.php

# PHP lint
phpcs-report.xml

# Allure directories
allure-report
allure-results

# Playwright output & working files
/plugins/woocommerce/e2e/output
/plugins/woocommerce/e2e/report
/plugins/woocommerce/e2e/storage
4 changes: 0 additions & 4 deletions packages/js/api-core-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# Collection output
collection.json

# Allure directories
allure-report
allure-results
13 changes: 11 additions & 2 deletions plugins/woocommerce/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
es6: true,
node: true,
},
extends: [ 'plugin:@woocommerce/eslint-plugin/recommended' ],
globals: {
wp: true,
wpApiSettings: true,
Expand All @@ -16,7 +15,6 @@ module.exports = {
rules: {
camelcase: 0,
indent: 0,
'max-len': [ 2, { code: 140 } ],
'no-console': 1,
},
parser: 'babel-eslint',
Expand All @@ -28,4 +26,15 @@ module.exports = {
jsx: true,
},
},
overrides: [
{
files: ["e2e/tests/**/*.spec.js", "e2e/*.js"],
rules: {
"jest/no-test-callback": "off",
"@wordpress/no-unsafe-wp-apis": "off",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off"
}
}
]
};
4 changes: 0 additions & 4 deletions plugins/woocommerce/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@ tests/cli/vendor
# Language files
i18n/languages/woocommerce.pot

# Allure directories
allure-report
allure-results

# Environment files
.wp-env.override.json
2 changes: 2 additions & 0 deletions plugins/woocommerce/changelog/e2e-rep-playwright-feature-flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Significance: patch
Type: dev
58 changes: 58 additions & 0 deletions plugins/woocommerce/e2e/global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { chromium } = require( '@playwright/test' );
const fs = require( 'fs' );

module.exports = async ( config ) => {
// Clear out the previous save states
const adminState = 'e2e/storage/adminState.json';
const customerState = 'e2e/storage/customerState.json';
fs.unlink( adminState, function ( err ) {
if ( err ) {
// File doesn't exist yet, so will just create it.
} else {
// File exists. Delete it so it can be re-created.
}
} );
fs.unlink( customerState, function ( err ) {
if ( err ) {
// File doesn't exist yet, so will just create it.
} else {
// File exists. Delete it so it can be re-created.
}
} );

const { baseURL } = config.projects[ 0 ].use;
// Sign in as admin user and save state
const browser = await chromium.launch();
const adminPage = await browser.newPage();
await adminPage.goto( `${ baseURL }/wp-admin` );
await adminPage.fill( 'input[name="log"]', 'admin' );
await adminPage.fill( 'input[name="pwd"]', 'password' );
await adminPage.click( 'text=Log In' );
await adminPage
.context()
.storageState( { path: 'e2e/storage/adminState.json' } );
// While we're here, let's add a consumer token for API access
await adminPage.goto(
`${ baseURL }/wp-admin/admin.php?page=wc-settings&tab=advanced&section=keys&create-key=1`
);
await adminPage.fill( '#key_description', 'Key for API access' );
await adminPage.selectOption( '#key_permissions', 'read_write' );
await adminPage.click( 'text=Generate API key' );
process.env.CONSUMER_KEY = await adminPage.inputValue(
'#key_consumer_key'
);
process.env.CONSUMER_SECRET = await adminPage.inputValue(
'#key_consumer_secret'
);

// Sign in as customer user and save state
const customerPage = await browser.newPage();
await customerPage.goto( `${ baseURL }/wp-admin` );
await customerPage.fill( 'input[name="log"]', 'customer' );
await customerPage.fill( 'input[name="pwd"]', 'password' );
await customerPage.click( 'text=Log In' );
await customerPage
.context()
.storageState( { path: 'e2e/storage/customerState.json' } );
await browser.close();
};
16 changes: 16 additions & 0 deletions plugins/woocommerce/e2e/global-teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { chromium } = require( '@playwright/test' );

module.exports = async ( config ) => {
const { baseURL } = config.projects[ 0 ].use;
// Clean up the consumer keys
const browser = await chromium.launch();
const adminPage = await browser.newPage();
await adminPage.goto( `${ baseURL }/wp-admin` );
await adminPage.fill( 'input[name="log"]', 'admin' );
await adminPage.fill( 'input[name="pwd"]', 'password' );
await adminPage.click( 'text=Log In' );
await adminPage.goto(
`${ baseURL }/wp-admin/admin.php?page=wc-settings&tab=advanced&section=keys`
);
await adminPage.dispatchEvent( 'a.submitdelete', 'click' );
};
38 changes: 38 additions & 0 deletions plugins/woocommerce/e2e/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { devices } = require( '@playwright/test' );

const config = {
timeout: 20000,
outputDir: './report',
globalSetup: require.resolve( './global-setup' ),
globalTeardown: require.resolve( './global-teardown' ),
testDir: 'tests',
retries: 1,
reporter: [
[ 'list' ],
[ 'html', { outputFolder: 'output' } ],
[ 'allure-playwright', { outputFolder: 'e2e/allure-results' } ],
],
use: {
screenshot: 'only-on-failure',
video: 'on-first-retry',
trace: 'retain-on-failure',
viewport: { width: 1280, height: 720 },
baseURL: 'http://localhost:8086',
},
projects: [
{
name: 'Chrome',
use: { ...devices[ 'Desktop Chrome' ] },
},
// {
// name: 'Firefox',
// use: { ...devices['Desktop Firefox'] },
// },
// {
// name: 'Webkit',
// use: { ...devices['Desktop Webkit'] },
// },
],
};

module.exports = config;
Loading

0 comments on commit f70afcc

Please sign in to comment.