From 9572bf2a120ce4ae0cb22f78fc90ecfeb0f2777e Mon Sep 17 00:00:00 2001 From: Jonathan Lane Date: Wed, 1 Nov 2023 15:44:24 -0700 Subject: [PATCH] Fix e2e and api execution on daily runs (#41113) * Increase a couple of timeouts * Remove duplicate update to nightly * Add changelog * Install Playwright * Handle Playwright setup * Add in build name * Add in check in e2e tests for daily run * Reverse check * Rookie mistake * Use ternary operator instead --------- Co-authored-by: Jon Lane --- .../actions/tests/run-api-tests/action.yml | 5 +++ .github/workflows/smoke-test-daily.yml | 11 ++---- .../changelog/fix-e2e-api-execution-on-daily | 4 +++ .../tests/api-core-tests/global-setup.js | 35 ++++++++++++++----- .../woocommerce/tests/e2e-pw/global-setup.js | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-e2e-api-execution-on-daily diff --git a/.github/actions/tests/run-api-tests/action.yml b/.github/actions/tests/run-api-tests/action.yml index fab3e83cca3..fbab825fb1a 100644 --- a/.github/actions/tests/run-api-tests/action.yml +++ b/.github/actions/tests/run-api-tests/action.yml @@ -19,6 +19,11 @@ outputs: runs: using: composite steps: + - name: Download and install Chromium browser. + working-directory: plugins/woocommerce + shell: bash + run: pnpm exec playwright install chromium + - name: Run API tests. id: run-api-tests working-directory: plugins/woocommerce diff --git a/.github/workflows/smoke-test-daily.yml b/.github/workflows/smoke-test-daily.yml index 35b582393c3..baeb8032525 100644 --- a/.github/workflows/smoke-test-daily.yml +++ b/.github/workflows/smoke-test-daily.yml @@ -45,15 +45,6 @@ jobs: install-filters: woocommerce build: false - - name: Update site to nightly version - uses: ./.github/actions/tests/run-e2e-tests - with: - report-name: ${{ env.API_ARTIFACT }} - tests: update-woocommerce.spec.js - env: - GITHUB_TOKEN: ${{ secrets.E2E_GH_TOKEN }} - UPDATE_WC: nightly - - name: Run API tests id: run-api-composite-action uses: ./.github/actions/tests/run-api-tests @@ -62,6 +53,8 @@ jobs: env: USER_KEY: ${{ secrets.SMOKE_TEST_ADMIN_USER }} USER_SECRET: ${{ secrets.SMOKE_TEST_ADMIN_PASSWORD }} + GITHUB_TOKEN: ${{ secrets.E2E_GH_TOKEN }} + UPDATE_WC: nightly e2e-tests: name: E2E tests on nightly build diff --git a/plugins/woocommerce/changelog/fix-e2e-api-execution-on-daily b/plugins/woocommerce/changelog/fix-e2e-api-execution-on-daily new file mode 100644 index 00000000000..e1ece66f822 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-e2e-api-execution-on-daily @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fixes daily execution workflow for API and e2e tests diff --git a/plugins/woocommerce/tests/api-core-tests/global-setup.js b/plugins/woocommerce/tests/api-core-tests/global-setup.js index dfc5b3cb98d..25e7bc856bc 100644 --- a/plugins/woocommerce/tests/api-core-tests/global-setup.js +++ b/plugins/woocommerce/tests/api-core-tests/global-setup.js @@ -4,7 +4,6 @@ const axios = require( 'axios' ).default; const playwrightConfig = require( './playwright.config' ); const { site } = require( './utils' ); - /** * * @param {import('@playwright/test').FullConfig} config @@ -155,9 +154,15 @@ module.exports = async ( config ) => { await setupPage .locator( '#install-plugin-submit' ) .click( { timeout: 60000 } ); - await setupPage.waitForLoadState( 'networkidle' ); + await setupPage.waitForLoadState( 'networkidle', { + timeout: 60000, + } ); await expect( - setupPage.getByRole( 'link', { name: 'Activate Plugin' } ) + setupPage.getByRole( + 'link', + { name: 'Activate Plugin' }, + { timeout: 60000 } + ) ).toBeVisible(); console.log( 'Activating Plugin...' ); await setupPage @@ -206,18 +211,30 @@ module.exports = async ( config ) => { } } else { // running on localhost using wp-env so ensure HPOS is set if ENABLE_HPOS env variable is passed - if (ENABLE_HPOS) { + if ( ENABLE_HPOS ) { let hposConfigured = false; const value = ENABLE_HPOS === '0' ? 'no' : 'yes'; try { - const auth = { username: playwrightConfig.userKey, password: playwrightConfig.userSecret }; - const hposResponse = await axios.post( playwrightConfig.use.baseURL + '/wp-json/wc/v3/settings/advanced/woocommerce_custom_orders_table_enabled', { value }, { auth } ); + const auth = { + username: playwrightConfig.userKey, + password: playwrightConfig.userSecret, + }; + const hposResponse = await axios.post( + playwrightConfig.use.baseURL + + '/wp-json/wc/v3/settings/advanced/woocommerce_custom_orders_table_enabled', + { value }, + { auth } + ); if ( hposResponse.data.value === value ) { - console.log( `HPOS Switched ${ value === 'yes' ? 'on' : 'off' } successfully` ); + console.log( + `HPOS Switched ${ + value === 'yes' ? 'on' : 'off' + } successfully` + ); hposConfigured = true; } - } catch( error ) { - console.log( 'HPOS setup failed.'); + } catch ( error ) { + console.log( 'HPOS setup failed.' ); console.log( error ); process.exit( 1 ); } diff --git a/plugins/woocommerce/tests/e2e-pw/global-setup.js b/plugins/woocommerce/tests/e2e-pw/global-setup.js index a919e106f46..3003372f419 100644 --- a/plugins/woocommerce/tests/e2e-pw/global-setup.js +++ b/plugins/woocommerce/tests/e2e-pw/global-setup.js @@ -224,7 +224,7 @@ module.exports = async ( config ) => { } } - await site.useCartCheckoutShortcodes( baseURL, userAgent, admin ); + !process.env.BASE_URL || process.env.BASE_URL === 'localhost' && await site.useCartCheckoutShortcodes( baseURL, userAgent, admin ); await adminContext.close(); await customerContext.close();