Fix recently failing "API on WP Latest" job in release testing workflow (#40453)

* Add changelog

* Add dedicated PW config and global setup files

* Add step to download chromium

* Specify config and env var

* Fix trivial whitespaces

* Disable Slack notif for now

* Re-enable Slack summary

* Simplify getting major, minor version numbers

* Use single line for response wait
This commit is contained in:
rodelgc 2023-10-11 14:46:46 +08:00 committed by GitHub
parent 773baea857
commit c64ae36956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 147 additions and 4 deletions

View File

@ -1,6 +1,5 @@
name: Run API tests
description: Runs the WooCommerce Core API tests and generates Allure report.
permissions: {}
inputs:
report-name:
@ -8,6 +7,9 @@ inputs:
required: true
tests:
description: Specific tests to run, separated by single whitespace. See https://playwright.dev/docs/test-cli
playwright-config:
description: Playwright config file to be used
default: playwright.config.js
outputs:
result:
@ -23,7 +25,7 @@ runs:
shell: bash
run: |
pnpm exec playwright test \
--config=tests/api-core-tests/playwright.config.js \
--config=tests/api-core-tests/${{ inputs.playwright-config }} \
${{ inputs.tests }}
- name: Generate Test report.

View File

@ -155,16 +155,22 @@ jobs:
install-filters: woocommerce
build: false
- name: Download and install Chromium browser.
working-directory: plugins/woocommerce
run: pnpm exec playwright install chromium
- name: Run API tests
id: run-api-composite-action
uses: ./.github/actions/tests/run-api-tests
with:
report-name: ${{ env.API_WP_LATEST_ARTIFACT }}
tests: hello
playwright-config: ci-release.playwright.config.js
env:
API_BASE_URL: ${{ secrets.RELEASE_TEST_URL }}
USER_KEY: ${{ secrets.RELEASE_TEST_ADMIN_USER }}
USER_SECRET: ${{ secrets.RELEASE_TEST_ADMIN_PASSWORD }}
UPDATE_WC: ${{ needs.get-tag.outputs.tag }}
- name: Upload Allure artifacts to bucket
if: success() || ( failure() && steps.run-api-composite-action.conclusion == 'failure' )
@ -331,7 +337,7 @@ jobs:
script: |
const { getVersionWPLatestMinusOne } = require( './plugins/woocommerce/tests/e2e-pw/utils/wordpress' );
await getVersionWPLatestMinusOne( { core, github } );
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
@ -341,7 +347,7 @@ jobs:
working-directory: plugins/woocommerce
run: pnpm run env:test
env:
WP_ENV_CORE: WordPress/WordPress#${{ steps.get-wp-latest-1.outputs.version }}
WP_ENV_CORE: WordPress/WordPress#${{ steps.get-wp-latest-1.outputs.version }}
- name: Download release zip
env:

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Fix "API on WP Latest" job in "Smoke test release" workflow.

View File

@ -0,0 +1,107 @@
const { UPDATE_WC, USER_KEY, USER_SECRET } = process.env;
const { test, expect } = require( '@playwright/test' );
const path = require( 'path' );
const fs = require( 'fs' );
const zipPath = path.resolve( 'tmp', 'woocommerce.zip' );
const downloadURL = `https://github.com/woocommerce/woocommerce/releases/download/${ UPDATE_WC }/woocommerce.zip`;
test( `Setup remote test site`, async ( { page, request } ) => {
await test.step( `Download WooCommerce build zip`, async () => {
const response = await request.get( downloadURL );
expect( response.ok() ).toBeTruthy();
const body = await response.body();
fs.mkdirSync( 'tmp', { recursive: true } );
fs.writeFileSync( zipPath, body );
} );
await test.step( 'Login to wp-admin', async () => {
const Username = 'Username or Email Address';
const Password = 'Password';
const Log_In = 'Log In';
const Dashboard = 'Dashboard';
// Need to wait until network idle. Otherwise, Password field gets auto-cleared after typing password in.
await page.goto( '/wp-admin', { waitUntil: 'networkidle' } );
await page.getByLabel( Username ).fill( USER_KEY );
await page.getByLabel( Password, { exact: true } ).fill( USER_SECRET );
await page.getByRole( 'button', { name: Log_In } ).click();
await expect(
page
.locator( '#menu-dashboard' )
.getByRole( 'link', { name: Dashboard } )
).toBeVisible();
} );
await test.step( `Deactivate currently installed WooCommerce version`, async () => {
const response = await request.put(
'/wp-json/wp/v2/plugins/woocommerce/woocommerce',
{
data: {
status: 'inactive',
},
}
);
expect( response.ok() ).toBeTruthy();
} );
await test.step( `Delete currently installed WooCommerce version`, async () => {
const response = await request.delete(
'/wp-json/wp/v2/plugins/woocommerce/woocommerce'
);
expect( response.ok() ).toBeTruthy();
} );
await test.step( `Install WooCommerce ${ UPDATE_WC }`, async () => {
const Upload_Plugin = 'Upload Plugin';
const Plugin_zip_file = 'Plugin zip file';
const Install_Now = 'Install Now';
const Activate_Plugin = 'Activate Plugin';
await page.goto( '/wp-admin/plugin-install.php' );
await page.getByRole( 'button', { name: Upload_Plugin } ).click();
await page.getByLabel( Plugin_zip_file ).setInputFiles( zipPath );
await page.getByRole( 'button', { name: Install_Now } ).click();
const uploadResponse = await page.waitForResponse(
'**/wp-admin/update.php?action=upload-plugin'
);;
expect( uploadResponse.ok() ).toBeTruthy();
await expect(
page.getByRole( 'link', { name: Activate_Plugin } )
).toBeVisible();
} );
await test.step( `Activate WooCommerce`, async () => {
const response = await request.put(
'/wp-json/wp/v2/plugins/woocommerce/woocommerce',
{
data: {
status: 'active',
},
}
);
expect( response.ok() ).toBeTruthy();
} );
await test.step( `Verify WooCommerce version was installed`, async () => {
const response = await request.get(
'/wp-json/wp/v2/plugins/woocommerce/woocommerce'
);
const { status, version } = await response.json();
expect( status ).toEqual( 'active' );
expect( version ).toEqual( UPDATE_WC );
} );
await test.step( `Verify WooCommerce database version`, async () => {
const response = await request.get( '/wp-json/wc/v3/system_status' );
const { database } = await response.json();
const { wc_database_version } = database;
const [major, minor] = UPDATE_WC.split( '.' );
const pattern = new RegExp( `^${ major }\.${ minor }` );
expect( wc_database_version ).toMatch( pattern );
} );
await test.step( `Delete zip`, async () => {
fs.unlinkSync( zipPath );
} );
} );

View File

@ -0,0 +1,24 @@
const defaultConfig = require( './playwright.config' );
// Global setup will be done through the 'Setup' project, not through the `globalSetup` property
delete defaultConfig[ 'globalSetup' ];
/**
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
const config = {
...defaultConfig,
projects: [
{
name: 'Setup',
testDir: './',
testMatch: 'ci-release.global-setup.js',
},
{
name: 'API tests',
dependencies: [ 'Setup' ],
},
],
};
module.exports = config;