Merge branch 'trunk' into e2e/update-command-for-e2e

This commit is contained in:
Jonathan Lane 2022-10-25 11:18:37 -07:00 committed by GitHub
commit 433357c3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 469 additions and 212 deletions

View File

@ -42,6 +42,7 @@ runs:
with:
php-version: ${{ inputs.php-version }}
coverage: none
tools: cs2pr, phpcs
- name: Cache Composer Dependencies
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77

View File

@ -1,20 +1,23 @@
name: Run daily tests in an environment with COT enabled
on:
schedule:
- cron: "30 2 * * *"
workflow_dispatch:
schedule:
- cron: '30 2 * * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
cot-e2e-tests-run:
name: Runs E2E tests with COT enabled.
runs-on: ubuntu-20.04
env:
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-report
steps:
- uses: actions/checkout@v3
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
@ -30,7 +33,7 @@ jobs:
timeout-minutes: 60
id: run_playwright_e2e_tests
env:
USE_WP_ENV: 1
USE_WP_ENV: 1
working-directory: plugins/woocommerce
run: pnpm exec playwright test --config=tests/e2e-pw/playwright.config.js
@ -43,7 +46,7 @@ jobs:
steps.run_playwright_e2e_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean e2e/allure-results --output e2e/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright E2E test report
if: |
@ -53,8 +56,8 @@ jobs:
with:
name: e2e-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5
@ -62,10 +65,11 @@ jobs:
name: Runs API tests with COT enabled.
runs-on: ubuntu-20.04
env:
API_TEST_REPORT_DIR: ${{ github.workspace }}/api-test-report
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-report
steps:
- uses: actions/checkout@v3
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
@ -81,6 +85,7 @@ jobs:
USER_KEY: admin
USER_SECRET: password
run: pnpm exec playwright test --config=tests/api-core-tests/playwright.config.js
- name: Generate Playwright API Test report.
id: generate_api_report
if: |
@ -90,7 +95,8 @@ jobs:
steps.run_playwright_api_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean api-test-report/allure-results --output api-test-report/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright API test report
if: |
always() &&
@ -99,8 +105,8 @@ jobs:
with:
name: api-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/api-test-report/allure-results
plugins/woocommerce/api-test-report/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5

View File

@ -13,9 +13,12 @@ jobs:
name: Runs E2E tests with COT enabled.
if: "${{ github.event_name == 'workflow_dispatch' || github.event.label.name == 'focus: custom order tables' }}"
runs-on: ubuntu-20.04
env:
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-report
steps:
- uses: actions/checkout@v3
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
@ -31,7 +34,7 @@ jobs:
timeout-minutes: 60
id: run_playwright_e2e_tests
env:
USE_WP_ENV: 1
USE_WP_ENV: 1
working-directory: plugins/woocommerce
run: pnpm exec playwright test --config=tests/e2e-pw/playwright.config.js
@ -44,7 +47,7 @@ jobs:
steps.run_playwright_e2e_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean e2e/allure-results --output e2e/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright E2E test report
if: |
@ -54,8 +57,8 @@ jobs:
with:
name: e2e-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5
@ -64,10 +67,11 @@ jobs:
if: "${{ github.event_name == 'workflow_dispatch' || github.event.label.name == 'focus: custom order tables' }}"
runs-on: ubuntu-20.04
env:
API_TEST_REPORT_DIR: ${{ github.workspace }}/api-test-report
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-report
steps:
- uses: actions/checkout@v3
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
@ -93,8 +97,8 @@ jobs:
steps.run_playwright_api_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean api-test-report/allure-results --output api-test-report/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright API test report
if: |
always() &&
@ -103,8 +107,8 @@ jobs:
with:
name: api-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/api-test-report/allure-results
plugins/woocommerce/api-test-report/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5

View File

@ -11,6 +11,9 @@ jobs:
e2e-tests-run:
name: Runs E2E tests.
runs-on: ubuntu-20.04
env:
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-report
outputs:
E2E_GRAND_TOTAL: ${{ steps.count_e2e_total.outputs.E2E_GRAND_TOTAL }}
steps:
@ -40,9 +43,9 @@ jobs:
timeout-minutes: 60
id: run_playwright_e2e_tests
env:
USE_WP_ENV: 1
E2E_MAX_FAILURES: 15
FORCE_COLOR: 1
USE_WP_ENV: 1
E2E_MAX_FAILURES: 15
FORCE_COLOR: 1
working-directory: plugins/woocommerce
run: pnpm exec playwright test --config=tests/e2e-pw/playwright.config.js
@ -55,7 +58,7 @@ jobs:
steps.run_playwright_e2e_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean e2e/allure-results --output e2e/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright E2E test report
if: |
@ -65,8 +68,8 @@ jobs:
with:
name: e2e-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5
@ -74,7 +77,8 @@ jobs:
name: Runs API tests.
runs-on: ubuntu-20.04
env:
API_TEST_REPORT_DIR: ${{ github.workspace }}/api-test-report
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-report
steps:
- uses: actions/checkout@v3
@ -103,7 +107,7 @@ jobs:
steps.run_playwright_api_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean api-test-report/allure-results --output api-test-report/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive Playwright API test report
if: |
always() &&
@ -112,8 +116,8 @@ jobs:
with:
name: api-test-report---pr-${{ github.event.number }}
path: |
plugins/woocommerce/api-test-report/allure-results
plugins/woocommerce/api-test-report/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5

View File

@ -16,20 +16,26 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v32
with:
files: |
**/*.php
- name: Setup WooCommerce Monorepo
if: steps.changed-files.outputs.any_changed == 'true'
uses: ./.github/actions/setup-woocommerce-monorepo
with:
build: false
- name: Tool versions
if: steps.changed-files.outputs.any_changed == 'true'
run: |
php --version
composer --version
- name: Run code sniffer
uses: thenabeel/action-phpcs@v8
with:
files: "**.php"
phpcs_path: plugins/woocommerce/vendor/bin/phpcs
standard: phpcs.xml
- name: Run PHPCS
if: steps.changed-files.outputs.any_changed == 'true'
run: ./plugins/woocommerce/vendor/bin/phpcs -n -q --report=checkstyle ${{ steps.changed-files.outputs.all_changed_files }} | cs2pr

View File

@ -68,7 +68,7 @@ jobs:
steps.e2e.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean e2e/allure-results --output e2e/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive E2E test report
if: |
@ -78,8 +78,8 @@ jobs:
with:
name: ${{ env.E2E_ARTIFACT }}
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5
@ -88,6 +88,9 @@ jobs:
runs-on: ubuntu-20.04
needs: [e2e-tests]
if: always()
env:
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-report
steps:
- uses: actions/checkout@v3
with:
@ -119,7 +122,7 @@ jobs:
steps.run_playwright_api_tests.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean api-test-report/allure-results --output api-test-report/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive API test report
if: |
@ -129,8 +132,8 @@ jobs:
with:
name: ${{ env.API_ARTIFACT }}
path: |
plugins/woocommerce/api-test-report/allure-results
plugins/woocommerce/api-test-report/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5
@ -194,6 +197,8 @@ jobs:
if: always()
env:
USE_WP_ENV: 1
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-results
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/e2e-pw/allure-report
strategy:
fail-fast: false
matrix:
@ -254,7 +259,7 @@ jobs:
steps.e2e.conclusion != 'skipped'
)
working-directory: plugins/woocommerce
run: pnpm exec allure generate --clean e2e/allure-results --output e2e/allure-report
run: pnpm exec allure generate --clean ${{ env.ALLURE_RESULTS_DIR }} --output ${{ env.ALLURE_REPORT_DIR }}
- name: Archive E2E test report
if: |
@ -264,8 +269,8 @@ jobs:
with:
name: Smoke tests with ${{ matrix.plugin }} plugin installed (run ${{ github.run_number }})
path: |
plugins/woocommerce/e2e/allure-results
plugins/woocommerce/e2e/allure-report
${{ env.ALLURE_RESULTS_DIR }}
${{ env.ALLURE_REPORT_DIR }}
if-no-files-found: ignore
retention-days: 5

View File

@ -139,7 +139,6 @@ export const PricingSection: React.FC = () => {
<InputControl
{ ...regularPriceProps }
label={ __( 'List price', 'woocommerce' ) }
placeholder={ __( '10.59', 'woocommerce' ) }
value={ formatCurrencyDisplayValue(
String( regularPriceProps?.value ),
currencyConfig,
@ -161,7 +160,6 @@ export const PricingSection: React.FC = () => {
<InputControl
{ ...salePriceProps }
label={ salePriceTitle }
placeholder={ __( '8.59', 'woocommerce' ) }
value={ formatCurrencyDisplayValue(
String( salePriceProps?.value ),
currencyConfig,

View File

@ -70,10 +70,6 @@ export const ProductInventorySection: React.FC = () => {
'SKU (Stock Keeping Unit)',
'woocommerce'
) }
placeholder={ __(
'washed-oxford-button-down-shirt',
'woocommerce'
) }
{ ...getInputProps( 'sku' ) }
/>
<div className="woocommerce-product-form__field">

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Add playwright api-core-tests for webhooks crud operations

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Added npm script for Playwright API Core Tests

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Uses the globa-setup.js to setup permalinks structure

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Use plugins/woocommerce/tests/e2e-pw folder for saving test outputs

View File

@ -0,0 +1,4 @@
Significance: patch
Type: enhancement
Remove some placeholder values

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Added states for Senegal.

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
typo fix

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Update api-core-tests readme for consistency with new command and updates to other commands too.

View File

@ -1543,6 +1543,22 @@ return array(
'VS' => __( 'Vaslui', 'woocommerce' ),
'VN' => __( 'Vrancea', 'woocommerce' ),
),
'SN' => array( // Regions of Senegal. Ref: https://github.com/unicode-org/cldr/blob/release-42/common/subdivisions/en.xml#L4801.
'SNDB' => __( 'Diourbel', 'woocommerce' ),
'SNDK' => __( 'Dakar', 'woocommerce' ),
'SNFK' => __( 'Fatick', 'woocommerce' ),
'SNKA' => __( 'Kaffrine', 'woocommerce' ),
'SNKD' => __( 'Kolda', 'woocommerce' ),
'SNKE' => __( 'Kédougou', 'woocommerce' ),
'SNKL' => __( 'Kaolack', 'woocommerce' ),
'SNLG' => __( 'Louga', 'woocommerce' ),
'SNMT' => __( 'Matam', 'woocommerce' ),
'SNSE' => __( 'Sédhiou', 'woocommerce' ),
'SNSL' => __( 'Saint-Louis', 'woocommerce' ),
'SNTC' => __( 'Tambacounda', 'woocommerce' ),
'SNTH' => __( 'Thiès', 'woocommerce' ),
'SNZG' => __( 'Ziguinchor', 'woocommerce' ),
),
'SG' => array(),
'SK' => array(),
'SI' => array(),

View File

@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* Main Command for WooCommere CLI.
* Main Command for WooCommerce CLI.
*
* Since a lot of WC operations can be handled via the REST API, we base our CLI
* off of Restful to generate commands for each WooCommerce REST API endpoint

View File

@ -32,6 +32,7 @@
"env:dev": "pnpm wp-env start",
"env:test": "pnpm run env:dev && ./tests/e2e-pw/bin/test-env-setup.sh",
"test:e2e-pw": "USE_WP_ENV=1 pnpm playwright test --config=tests/e2e-pw/playwright.config.js",
"test:api-pw": "USE_WP_ENV=1 pnpm playwright test --config=tests/api-core-tests/playwright.config.js",
"env:test:cot": "pnpm run env:dev && ./tests/e2e-pw/bin/test-env-setup.sh --cot",
"env:performance-init": "./tests/performance/bin/init-sample-products.sh",
"env:down": "pnpm wp-env stop",

View File

@ -1,6 +1,6 @@
<?php
/**
* Loads WooCommece packages from the /packages directory. These are packages developed outside of core.
* Loads WooCommerce packages from the /packages directory. These are packages developed outside of core.
*/
namespace Automattic\WooCommerce;

View File

@ -1,6 +1,6 @@
# WooCommerce Playwright End to End Tests
# WooCommerce Core API Test Suite
This is the documentation for the new api-core-tests setup based on Playwright and wp-env. It superseedes the Puppeteer and e2e-environment [setup](../tests/e2e), which we will gradually deprecate.
This package contains automated API tests for WooCommerce, based on Playwright and `wp-env`. It supersedes the SuperTest based [api-core-tests package](https://www.npmjs.com/package/@woocommerce/api-core-tests) and e2e-environment [setup](../tests/e2e), which we will gradually deprecate.
## Table of contents
@ -21,36 +21,33 @@ This is the documentation for the new api-core-tests setup based on Playwright a
- PNPM ([Installation instructions](https://pnpm.io/installation))
- Docker and Docker Compose ([Installation instructions](https://docs.docker.com/engine/install/))
Note, that if you are on Mac and you install docker through other methods such as homebrew, for example, your steps to set it up might be different. The commands listed in steps below may also vary.
Note, that if you are on Mac and you install Docker through other methods such as homebrew, for example, your steps to set it up might be different. The commands listed in steps below may also vary.
If you are using Windows, we recommend using [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/) for running E2E tests. Follow the [WSL Setup Instructions](../tests/e2e/WSL_SETUP_INSTRUCTIONS.md) first before proceeding with the steps below.
If you are using Windows, we recommend using [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/) for running tests. Follow the [WSL Setup Instructions](../tests/e2e/WSL_SETUP_INSTRUCTIONS.md) first before proceeding with the steps below.
### Introduction
api-core-tests are powered by Playwright. The test site is spinned up using `wp-env` (recommended), but we will continue to support `e2e-environment` in the meantime.
WooCommerce's `api-core-tests` are powered by Playwright. The test site is spun up using `wp-env` (recommended), but we will continue to support `e2e-environment` in the meantime.
**Running tests for the first time:**
Note: the commands may need to be executed in `plugins/woocommerce` (or a subdirectory thereof)
- `nvm use`
- `pnpm install`
- `pnpm run build --filter=woocommerce`
- `pnpm env:test --filter=woocommerce`
Then execute the tests with the following command:
- `cd plugins/woocommerce && USE_WP_ENV=1 pnpm playwright test --config=tests/api-core-tests/playwright.config.js` (headless)
- `cd plugins/woocommerce`
- `pnpm env:test`
- `pnpm test:api-pw`
To run the test again, re-create the environment to start with a fresh state
- `pnpm env:destroy --filter=woocommerce`
- `pnpm env:test --filter=woocommerce`
- `pnpm env:destroy`
- `pnpm env:test`
- `pnpm test:api-pw`
Other ways of running tests:
- `cd plugins/woocommerce && USE_WP_ENV=1 pnpm playwright test --config=tests/api-core-tests/playwright.config.js --headed` (headed)
- `cd plugins/woocommerce && USE_WP_ENV=1 pnpm playwright test --config=tests/api-core-tests/playwright.config.js --debug` (debug)
- `cd plugins/woocommerce && USE_WP_ENV=1 pnpm playwright test --config=tests/api-core-tests/playwright.config.js ./tests/api-core-tests/tests/hello/hello.test.js` (running a single test)
- `pnpm test:api-pw --debug` (debug)
- `pnpm test:api-pw ./tests/api-core-tests/tests/hello/hello.test.js` (running a single test)
To see all options, run `cd plugins/woocommerce && pnpm playwright test --help`
@ -69,8 +66,7 @@ USER_KEY=""
USER_SECRET=""
```
For local setup, create a `.env` file in the `woocommerce/plugins/woocommerce` folder with the three required values described above.
If any of these variables are configured they will override the values automatically set in the `playwright.config.js`
For local setup, create a `.env` file in the `woocommerce/plugins/woocommerce` folder with the three required values described above. If any of these variables are configured they will override the values automatically set in the `playwright.config.js`
When using a username and password combination instead of a consumer secret and consumer key, make sure to have the [JSON Basic Authentication plugin](https://github.com/WP-API/Basic-Auth) installed and activated on the test site.
@ -113,11 +109,11 @@ The test environment uses the following test variables:
If you need to modify the port for your local test environment (eg. port is already in use) or use, edit [playwright.config.js](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/tests/e2e/playwright.config.js). Depending on what environment tool you are using, you will need to also edit the respective `.json` file.
**Modiify the port wp-env**
**Modify the port wp-env**
Edit [.wp-env.json](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/.wp-env.json) and [playwright.config.js](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/tests/e2e/playwright.config.js).
**Modiify port for e2e-environment**
**Modify port for e2e-environment**
Edit [tests/e2e/config/default.json](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/tests/e2e/config/default.json).****
@ -125,9 +121,9 @@ Edit [tests/e2e/config/default.json](https://github.com/woocommerce/woocommerce/
After you run a test, it's best to restart the environment to start from a fresh state. We are currently working to reset the state more efficiently to avoid the restart being needed, but this is a work-in-progress.
- `pnpm env:down --filter=woocommerce` to stop the environment
- `pnpm env:destroy --filter=woocommerce` when you make changes to `.wp-env.json`
- `pnpm env:test --filter=woocommerce` to spin up the test environment
- `pnpm env:down` to stop the environment
- `pnpm env:destroy` when you make changes to `.wp-env.json`
- `pnpm env:test` to spin up the test environment
## Guide for writing tests
@ -142,17 +138,11 @@ Based on our example, the test skeleton would look as follows:
```js
test.describe( 'Merchant can create virtual product', () => {
test( 'merchant can log in', async () => {
test( 'merchant can log in', async () => { } );
} );
test( 'merchant can create virtual product', async () => { } );
test( 'merchant can create virtual product', async () => {
} );
test( 'merchant can verify that virtual product was created', async () => {
} );
test( 'merchant can verify that virtual product was created', async () => { } );
} );
```

View File

@ -34,9 +34,19 @@ const config = {
],
[
'allure-playwright',
{ outputFolder: 'api-test-report/allure-results' },
{
outputFolder:
process.env.ALLURE_RESULTS_DIR ??
'tests/api-core-tests/api-test-report/allure-results',
},
],
[
'json',
{
outputFile:
'tests/api-core-tests/api-test-report/test-results.json',
},
],
[ 'json', { outputFile: 'api-test-report/test-results.json' } ],
],
use: {
screenshot: 'only-on-failure',

View File

@ -0,0 +1,254 @@
const {
test,
expect
} = require('@playwright/test');
const exp = require('constants');
const {
refund
} = require('../../data');
/**
* Tests for the WooCommerce Refunds API.
*
* @group api
* @group webhooks
*
*/
test.describe('Webhooks API tests', () => {
let webhookId;
test.describe('Create a webhook', () => {
test('can create a webhook', async ({
request,
}) => {
// call API to create a webhook
const response = await request.post(
'/wp-json/wc/v3/webhooks', {
data: {
name: "Order updated",
topic: "order.updated",
delivery_url: "http://requestb.in/1g0sxmo1"
},
}
);
const responseJSON = await response.json();
expect(response.status()).toEqual(201);
expect(typeof responseJSON.id).toEqual('number');
expect(responseJSON.name).toEqual("Order updated");
expect(responseJSON.status).toEqual("active");
expect(responseJSON.topic).toEqual("order.updated");
expect(responseJSON.delivery_url).toEqual("http://requestb.in/1g0sxmo1");
expect(responseJSON.hooks).toEqual(
expect.arrayContaining([
"woocommerce_update_order",
"woocommerce_order_refunded"
])
);
webhookId = responseJSON.id;
});
});
test.describe('Retrieve after create', () => {
test('can retrieve a webhook', async ({
request
}) => {
// call API to retrieve the previously saved webhook
const response = await request.get(
`/wp-json/wc/v3/webhooks/${webhookId}`
);
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect(Array.isArray(responseJSON)).toBe(false);
expect(typeof responseJSON.id).toEqual('number');
expect(responseJSON.name).toEqual("Order updated");
expect(responseJSON.status).toEqual("active");
expect(responseJSON.topic).toEqual("order.updated");
expect(responseJSON.delivery_url).toEqual("http://requestb.in/1g0sxmo1");
expect(responseJSON.hooks).toEqual(
expect.arrayContaining([
"woocommerce_update_order",
"woocommerce_order_refunded"
])
);
});
test('can retrieve all webhooks', async ({
request
}) => {
// call API to retrieve all webhooks
const response = await request.get('/wp-json/wc/v3/webhooks');
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect(Array.isArray(responseJSON));
expect(responseJSON.length).toBeGreaterThan(0);
});
});
test.describe('Update a webhook', () => {
test(`can update a web hook`, async ({
request,
}) => {
// update webhook
const response = await request.put(
`/wp-json/wc/v3/webhooks/${ webhookId }`, {
data: {
status: "paused"
}
}
);
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect(responseJSON.status).toEqual("paused");
});
});
test.describe('Delete a webhook', () => {
test('can permanently delete a webhook', async ({
request
}) => {
// Delete the webhook
const response = await request.delete(`/wp-json/wc/v3/webhooks/${ webhookId }`, {
data: {
force: true
}
});
expect(response.status()).toEqual(200);
// Verify that the webhook can no longer be retrieved
const getDeletedWebhookResponse = await request.get(
`/wp-json/wc/v3/webhooks/${ webhookId }`
);
/**
* Issue raised as we would expect this to return a 400 to be
* consistent with the other API calls
* Issue: https://github.com/woocommerce/woocommerce/issues/35290
*/
expect(getDeletedWebhookResponse.status()).toEqual(400);
});
});
test.describe('Batch webhook operations', () => {
let webhookId1;
let webhookId2;
let webhookId3;
test('can batch create webhooks', async ({
request
}) => {
// Batch create webhooks
// call API to batch create a webhook
const response = await request.post('wp-json/wc/v3/webhooks/batch', {
data: {
create: [{
name: "Round toe",
topic: "coupon.created",
delivery_url: "http://requestb.in/1g0sxmo1"
},
{
name: "Customer deleted",
topic: "customer.deleted",
delivery_url: "http://requestb.in/1g0sxmo1"
}
]
},
});
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
// Verify that the new webhooks were created
const webhooks = responseJSON.create;
expect(webhooks).toHaveLength(2);
webhookId1 = webhooks[0].id;
webhookId2 = webhooks[1].id;
expect(webhookId1).toBeDefined();
expect(webhookId2).toBeDefined();
expect(webhooks[0].name).toEqual('Round toe');
expect(webhooks[1].name).toEqual('Customer deleted');
});
test('can batch update webhooks', async ({
request
}) => {
// set payload to create, update and delete webhooks
const batchUpdatePayload = {
create: [{
name: "Order Created",
topic: "order.created",
delivery_url: "http://requestb.in/1g0sxmo1"
}, ],
update: [{
id: webhookId1,
name: 'Square toe',
}, ],
delete: [webhookId2]
};
// Call API to batch update the webhooks
const response = await request.post(
'wp-json/wc/v3/webhooks/batch', {
data: batchUpdatePayload,
}
);
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect(responseJSON.create).toHaveLength(1);
webhookId3 = responseJSON.create[0].id;
expect(webhookId3).toBeDefined();
expect(responseJSON.create[0].name).toEqual('Order Created');
expect(responseJSON.create[0].topic).toEqual('order.created');
expect(responseJSON.create[0].delivery_url).toEqual('http://requestb.in/1g0sxmo1');
expect(responseJSON.update).toHaveLength(1);
expect(responseJSON.update[0].id).toEqual(webhookId1);
expect(responseJSON.update[0].name).toEqual('Square toe');
// Verify that the deleted webhook can no longer be retrieved
const getDeletedWebhookResponse = await request.get(
`/wp-json/wc/v3/webhooks/${ webhookId2 }`
);
/**
* Issue raised as we would expect this to return a 400 to be
* consistent with the other API calls
* Issue: https://github.com/woocommerce/woocommerce/issues/35290
*/
expect(getDeletedWebhookResponse.status()).toEqual(400);
});
test('can batch delete webhooks', async ({
request
}) => {
// Batch delete the created webhooks
const response = await request.post(
'wp-json/wc/v3/webhooks/batch', {
data: {
delete: [webhookId1, webhookId3]
},
}
);
const responseJSON = await response.json();
//Call the API to attempte to retrieve the deleted webhooks
const deletedResponse1 = await request.get(
`wp-json/wc/v3/webhooks/${ webhookId1 }`
);
const deletedResponse3 = await request.get(
`wp-json/wc/v3/webhooks/${ webhookId3 }`
);
/**
* Issue raised as we would expect this to return a 400 to be
* consistent with the other API calls
* Issue: https://github.com/woocommerce/woocommerce/issues/35290
*/
expect(deletedResponse1.status()).toEqual(400);
expect(deletedResponse3.status()).toEqual(400);
});
});
});

View File

@ -11,6 +11,19 @@ const adminPassword = ADMIN_PASSWORD ?? 'password';
const customerUsername = CUSTOMER_USER ?? 'customer';
const customerPassword = CUSTOMER_PASSWORD ?? 'password';
const setupPermalinks = async ( adminPage, baseURL ) => {
console.log( 'Trying to setup permalinks!' );
await adminPage.goto( baseURL + '/wp-admin/options-permalink.php' );
await expect( adminPage.locator( 'div.wrap > h1' ) ).toHaveText(
'Permalink Settings'
);
await adminPage.click( '#custom_selection' );
await adminPage.fill( '#permalink_structure', '/%postname%/' );
await adminPage.click( '#submit' );
console.log( 'Permalinks Set!' );
}
module.exports = async ( config ) => {
const { stateDir, baseURL, userAgent } = config.projects[ 0 ].use;
@ -129,6 +142,30 @@ module.exports = async ( config ) => {
process.exit( 1 );
}
// Ensure that permalinks are correctly setup since we can't set it up using wp-env when not using the default WP version.
// More info here: https://github.com/WordPress/gutenberg/issues/28201
let permalinkConfigured = false;
const permalinkRetries = 5;
for ( let i = 0; i < permalinkRetries; i++ ) {
try {
await setupPermalinks( adminPage, baseURL );
permalinkConfigured = true;
break;
} catch ( e ) {
console.log(
`Setting permalink failed, Retrying... ${ i }/${ permalinkRetries }`
);
console.log( e );
}
}
if ( ! permalinkConfigured ) {
console.error(
'Cannot proceed e2e test, as we could not setup permalinks. Please check if the test site has been setup correctly.'
);
process.exit( 1 );
}
// Sign in as customer user and save state
const customerRetries = 5;
for ( let i = 0; i < customerRetries; i++ ) {

View File

@ -1,9 +1,10 @@
const { devices } = require( '@playwright/test' );
const {
CI,
E2E_MAX_FAILURES,
ALLURE_RESULTS_DIR,
BASE_URL,
CI,
DEFAULT_TIMEOUT_OVERRIDE,
E2E_MAX_FAILURES,
} = process.env;
const config = {
@ -26,17 +27,23 @@ const config = {
open: CI ? 'never' : 'always',
},
],
[ 'allure-playwright', { outputFolder: 'e2e/allure-results' } ],
[ 'json', { outputFile: 'e2e/test-results.json' } ],
[
'allure-playwright',
{
outputFolder:
ALLURE_RESULTS_DIR ?? 'tests/e2e-pw/allure-results',
},
],
[ 'json', { outputFile: 'tests/e2e-pw/test-results.json' } ],
],
maxFailures: E2E_MAX_FAILURES ? Number( E2E_MAX_FAILURES ) : 0,
use: {
screenshot: 'only-on-failure',
video: 'on-first-retry',
trace: 'retain-on-failure',
viewport: { width: 1280, height: 720 },
baseURL: BASE_URL ?? 'http://localhost:8086',
stateDir: 'e2e/storage/',
screenshot: 'only-on-failure',
stateDir: 'tests/e2e-pw/storage/',
trace: 'retain-on-failure',
video: 'on-first-retry',
viewport: { width: 1280, height: 720 },
},
projects: [
{

View File

@ -1,65 +0,0 @@
{
"cookies": [
{
"sameSite": "Lax",
"name": "wordpress_dc5025de8b60c0a511df7c07d81ead97",
"value": "admin%7C1660405922%7CjsNIRwmbjFh7KIGlSHy50rSs6X0L0zISppmBqgh0u0u%7C8ac4ff905331544a3cbcf0c58840ebfc3f492d4511dd17f48dbed18f5662a2c6",
"domain": "localhost",
"path": "/wp-content/plugins",
"expires": -1,
"httpOnly": true,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_dc5025de8b60c0a511df7c07d81ead97",
"value": "admin%7C1660405922%7CjsNIRwmbjFh7KIGlSHy50rSs6X0L0zISppmBqgh0u0u%7C8ac4ff905331544a3cbcf0c58840ebfc3f492d4511dd17f48dbed18f5662a2c6",
"domain": "localhost",
"path": "/wp-admin",
"expires": -1,
"httpOnly": true,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_test_cookie",
"value": "WP%20Cookie%20check",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": false,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_logged_in_dc5025de8b60c0a511df7c07d81ead97",
"value": "admin%7C1660405922%7CjsNIRwmbjFh7KIGlSHy50rSs6X0L0zISppmBqgh0u0u%7C6de27e0d8393de7715c07e144424d90733d53e65b8665c8a7db1ad94798c369c",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": true,
"secure": false
},
{
"sameSite": "Lax",
"name": "tk_ai",
"value": "woo%3AT9QFbJmpuSGWcjApaONaBtSB",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": false,
"secure": false
},
{
"sameSite": "Lax",
"name": "wp-settings-time-1",
"value": "1660233126",
"domain": "localhost",
"path": "/",
"expires": 1691769126.937059,
"httpOnly": false,
"secure": false
}
],
"origins": []
}

View File

@ -1,45 +0,0 @@
{
"cookies": [
{
"sameSite": "Lax",
"name": "wordpress_dc5025de8b60c0a511df7c07d81ead97",
"value": "customer%7C1660405929%7CL0OCLRBBMubq8iKqOeQU1NqOzTWFd7ppECd1n100GKG%7Cccb6b6b9e1190e94ef751360fded6ec026c89350f9f4695e9bf900ca09d72a84",
"domain": "localhost",
"path": "/wp-content/plugins",
"expires": -1,
"httpOnly": true,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_dc5025de8b60c0a511df7c07d81ead97",
"value": "customer%7C1660405929%7CL0OCLRBBMubq8iKqOeQU1NqOzTWFd7ppECd1n100GKG%7Cccb6b6b9e1190e94ef751360fded6ec026c89350f9f4695e9bf900ca09d72a84",
"domain": "localhost",
"path": "/wp-admin",
"expires": -1,
"httpOnly": true,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_test_cookie",
"value": "WP%20Cookie%20check",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": false,
"secure": false
},
{
"sameSite": "Lax",
"name": "wordpress_logged_in_dc5025de8b60c0a511df7c07d81ead97",
"value": "customer%7C1660405929%7CL0OCLRBBMubq8iKqOeQU1NqOzTWFd7ppECd1n100GKG%7C869a28fa8ef17799b6d097d84c8155c7d0dd18cd9967f7a18e3f49f41dd71226",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": true,
"secure": false
}
],
"origins": []
}