Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW e2e environment using playground cli #810

Open
wants to merge 108 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
de23420
Install needed packages & setup new e2e scripts
carstingaxion Aug 11, 2024
493c9aa
REMOVE special port settings for wp-env (which may be a problem, I'm …
carstingaxion Aug 11, 2024
c38da61
Add configuration files to run Playwright tests
carstingaxion Aug 11, 2024
673e566
Update Github workflow to use wp-env for e2e tests
carstingaxion Aug 11, 2024
e20f215
Rename folder with tests
carstingaxion Aug 11, 2024
1ed3bd1
NEW (WIP) e2e-tests utilising the wordpress/e2e-test-utils-playwright…
carstingaxion Aug 11, 2024
da4fe13
Fix script name to start wp-env
carstingaxion Aug 11, 2024
6a4ea6f
Add basic dev-documentation about e2e-tests
carstingaxion Aug 11, 2024
9477ecc
Run BUILD before Playwright tests
carstingaxion Aug 12, 2024
94d99f6
DO NOT MERGE // FOR DEBUGGING ONLY // simple Gutenberg paragraph bloc…
carstingaxion Aug 12, 2024
eb8dbdc
Remove custom globalSetup & env vars in favor of Gutenbergs defaults
carstingaxion Aug 12, 2024
a888cc2
TRY: Disable blank mappings for themes & plugins in wp-env
carstingaxion Aug 12, 2024
ee9544c
Add caching to the Playwright browser download step
carstingaxion Aug 12, 2024
d1b3b3a
Creating a short lived node_modules cache to be used by multiple accr…
carstingaxion Aug 12, 2024
308ca4e
DISABLED TEMPORARY // REVERT BEFORE MERGE // to make debugging easier
carstingaxion Aug 12, 2024
9cd89ad
Fix the artifacts upload on CI, to get traces and screenshots from fa…
carstingaxion Aug 12, 2024
ea0739d
Update actions/checkout to v4
carstingaxion Aug 12, 2024
6f2c8f5
Run npm install, only when really needed
carstingaxion Aug 12, 2024
f3c6ad4
Remove steps, that are being done via npm pre-script runs
carstingaxion Aug 12, 2024
b7fad4b
Cleanup
carstingaxion Aug 12, 2024
421c3b0
Move doc into contributor folder
carstingaxion Aug 16, 2024
ed4ff96
Rename scripts to align with screenshot-workflow
carstingaxion Aug 16, 2024
cb6e65b
Remove debug stuff
carstingaxion Aug 16, 2024
c7dae87
Clean up
carstingaxion Aug 16, 2024
345fd9e
Re-Enable 'publish event through admin side' (WIP)
carstingaxion Aug 16, 2024
cab2d14
Resolve merge conflicts
carstingaxion Aug 17, 2024
d8e59a0
Re-Add test:e2e scripts
carstingaxion Aug 17, 2024
158a7ef
Merge branch 'main' into feature/e2e-tests-workflow
carstingaxion Aug 17, 2024
082f6c5
Fix indention
carstingaxion Aug 17, 2024
eb7125d
Lint JS
carstingaxion Aug 17, 2024
cff4a82
Enable Firefox & webkit test-browsers
carstingaxion Aug 17, 2024
2a04279
WIP with wp-now
carstingaxion Aug 17, 2024
ded313f
Update URL to settings
carstingaxion Aug 17, 2024
eef93cb
Hide admin notice during tests
carstingaxion Aug 17, 2024
2cb69d4
Update docs
carstingaxion Aug 17, 2024
b751c87
WIP Migrate tests to e2e-test-utils-playwright
carstingaxion Aug 17, 2024
a0d7e0a
WIP Migrate tests to e2e-test-utils-playwright (2/2)
carstingaxion Aug 18, 2024
53e1f80
Restrict workflow run to relevant triggers
carstingaxion Aug 18, 2024
b82dc1c
Fix: missing required deps
carstingaxion Aug 18, 2024
3aab03d
Remove deprecated "virtualize" param
carstingaxion Aug 18, 2024
45fdc50
Lint & Fix CS issues
carstingaxion Aug 18, 2024
1ae3beb
Import demo-data to test use-cases without having to create a bunch o…
carstingaxion Aug 18, 2024
5fb31e2
WIP Migrate tests to e2e-test-utils-playwright (3/3)
carstingaxion Aug 18, 2024
c1482b0
DRY out code & fix CS
carstingaxion Aug 18, 2024
87984da
WIP Migrate tests to e2e-test-utils-playwright (4/4)
carstingaxion Aug 18, 2024
b7a2bcd
Apply to CS
carstingaxion Aug 18, 2024
b5f0bda
Do not delete posts
carstingaxion Aug 18, 2024
024fe15
Do not delete posts (2/2)
carstingaxion Aug 18, 2024
a99cdb6
Remove dated-post-title as not-needed in virtual envs
carstingaxion Aug 18, 2024
08539d8
Update actions/upload-artifact to v4
carstingaxion Aug 18, 2024
0810258
Enable networking to prevent 404 (and hopefully the import errors as …
carstingaxion Aug 18, 2024
86f3b73
Replace importWxr step with 5 (!) steps (Regarding to https://github.…
carstingaxion Aug 18, 2024
ac8c02a
TRY
carstingaxion Aug 18, 2024
13d8c4d
Add login step
carstingaxion Aug 18, 2024
978afa1
DISABLE TEMP // Reduce browser to increase time-to-next-debug-msg
carstingaxion Aug 18, 2024
503b669
Disable superflous atts
carstingaxion Aug 18, 2024
7f4aac6
Remove superflous code
carstingaxion Aug 18, 2024
1ac130d
TRY number 763
carstingaxion Aug 18, 2024
009bc60
Replace wp-now with wp-playground/cli !!!
carstingaxion Aug 20, 2024
24f174b
Add env vars
carstingaxion Aug 20, 2024
9c7afb0
Try reducing timeouts
carstingaxion Aug 20, 2024
3af1d2e
Fix CS
carstingaxion Aug 21, 2024
1717903
Add debuging example to docs
carstingaxion Aug 21, 2024
67cf8db
Update docs with 'Playground CLI'
carstingaxion Aug 21, 2024
907e977
TRY FIX // webkit // Gutenberg: "Headless webkit won't receive dataTr…
carstingaxion Aug 22, 2024
d1ad138
Define a matrix of php versions to test against
carstingaxion Sep 4, 2024
ab1c527
Start the Playground before Playwright
carstingaxion Sep 4, 2024
148b7f9
Cleanup
carstingaxion Sep 4, 2024
8fa2c46
DRY out npm scripts
carstingaxion Sep 4, 2024
d962362
switch from isVisible to toBeVisible
carstingaxion Sep 4, 2024
baaf0c5
Update docs
carstingaxion Sep 5, 2024
75e481b
Prepare preferredVersions for blueprint (until is resolved: https://g…
carstingaxion Sep 5, 2024
cf4f399
Merge branch 'main' into feature/e2e-tests-workflow-wp-now
carstingaxion Sep 18, 2024
3647106
TRYOUT .click({ force: true }) which is ugly, but works :(
carstingaxion Sep 18, 2024
b85315a
TRY same technique like for the screenshots, use sleep to avoid a rac…
carstingaxion Sep 24, 2024
c07b419
Merge branch 'main' into feature/e2e-tests-workflow-wp-now
carstingaxion Sep 24, 2024
b07b065
Fix invalid workflow file
carstingaxion Sep 24, 2024
687a0d1
DRY out WP_BASE_URL definition into package.json
carstingaxion Sep 24, 2024
efdb4e1
Fix for CS
carstingaxion Sep 24, 2024
e405a0f
TRYOUT .click({ force: true }) which is ugly, but works :(
carstingaxion Sep 24, 2024
265cf4e
Merge branch 'main' into feature/e2e-tests-workflow-wp-now
carstingaxion Sep 24, 2024
b8fd761
Fix for CS
carstingaxion Sep 24, 2024
2b4cc31
Add inline-docs & Cleanup
carstingaxion Sep 24, 2024
939eb1a
COPY test-reporting (1/2) from Gutenberg
carstingaxion Sep 24, 2024
9dfd54c
Fix for CS
carstingaxion Sep 24, 2024
5f986d9
Simplify test by relying on Playwrights actionability checks (auto-wa…
carstingaxion Sep 25, 2024
50f84b6
Simplify test because the getByRole locator supports expanded selector
carstingaxion Sep 25, 2024
569c7c8
Replace isVisible() with expect( ... ).toBeVisible(), as per the sugg…
carstingaxion Sep 27, 2024
08d3b13
The "$" method is discouraged, Locator should be used
carstingaxion Sep 27, 2024
9719773
The URL attribute should be asserted via the toHaveAttribute locator …
carstingaxion Sep 27, 2024
442e6cb
Disable "Merge Artifacts" step
carstingaxion Oct 6, 2024
917f485
Update workflow echo
carstingaxion Oct 6, 2024
439a794
Fix test: A logged in user can perform RSVP action (which failed in TT5)
carstingaxion Oct 6, 2024
6bb65de
Clean up
carstingaxion Oct 7, 2024
7574542
Clean up
carstingaxion Oct 7, 2024
d7e8c3f
Fix test: By re-enabling force click
carstingaxion Oct 7, 2024
b087736
WIP event tests
carstingaxion Oct 7, 2024
a1f8574
Run for different WP versions
carstingaxion Oct 7, 2024
d46fc40
Fix for CS
carstingaxion Oct 7, 2024
fd0cd22
Remove comma
carstingaxion Oct 7, 2024
3e4c8de
Reduce WP-version matrix to "minimum required"
carstingaxion Oct 7, 2024
d23bfea
Login step can be removed (because its part of importWxr)
carstingaxion Oct 7, 2024
079cfd2
TRY test for non-logged-in users (FAILED)
carstingaxion Oct 7, 2024
c414abe
Clean up
carstingaxion Oct 7, 2024
602d590
Splitting the problematic test into smaller pieces
carstingaxion Oct 7, 2024
66aa030
wp-scripts package-update
carstingaxion Oct 7, 2024
f8d255c
BUILD
carstingaxion Oct 7, 2024
5a4b97f
Merge branch 'main' into feature/e2e-tests-workflow-wp-now
carstingaxion Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 166 additions & 33 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,176 @@
name: E2E Tests

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
paths:
- '.github/workflows/e2e-tests.yml'
- 'build/**'
- 'includes/**'
- 'src/**'
- 'test/e2e/**'
- '*.php'
- 'package.*'

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true


jobs:
playwright:
name: Playwright Tests
e2e-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1 # Prevent parallel runs to make use of the caching for node_modules and playwright browsers
matrix:
php: [
'7.4',
'8.3'
]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log debug information
run: |
npm --version
node --version
git --version
php --version
composer --version

- name: Install NodeJS
uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4

- uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
# Enable built-in functionality for caching and restoring dependencies, which is disabled by default.
# The actions/setup-node uses actions/cache under the hood.
# https://github.com/actions/setup-node#caching-global-packages-data
cache: 'npm'

# Restoring the short lived node_modules cache
# to be used across all workflows running on the last commit.
# https://github.com/actions/cache/blob/main/caching-strategies.md#creating-a-short-lived-cache
- uses: actions/cache/restore@v4
id: node_modules-cache
with:
path: |
./node_modules
key: ${{ runner.os }}-node_modules-${{ github.sha }}-${{ hashFiles('package-lock.json') }}

- name: NPM install
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps

# Creating a short lived node_modules cache
- uses: actions/cache/save@v4
if: steps.node_modules-cache.outputs.cache-hit != 'true'
with:
path: |
./node_modules
key: ${{ steps.node_modules-cache.outputs.cache-primary-key }}

- name: Install Playwright dependencies
run: npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'

- name: Prepare preferredVersions for blueprint
# playground/cli ignores --php & --wp flags when --blueprint is set
#
# I created an issue at:
# https://github.com/WordPress/playground-tools/issues/352
run: |
preferredVersions='{
"php": "${{ matrix.php }}",
"wp": "latest"
}'
echo "Use jq to prepend the preferred versions to the existing blueprint JSON file."
jq --argjson preferredVersions "$preferredVersions" '{preferredVersions: $preferredVersions} + .' ./test/e2e/blueprint.json > temp.blueprint.json

- name: Starting Playground, staring Playwright & running the tests
# This is kind of a hack PART 1/2,
# to make sure Playwright DOES NOT start the webserver on its own.
#
# Part 2/2 is the "command: undefined," declaration
# in test/e2e/playwright.config.ts
#
# While auto-loading the webserver when needed sounded nice, it introduced a race-condition
# between the setup of Playground and Playwrights own start event.
# Playwright listens for the availability of the webserver relatively simple,
# as soon as there is a status code 200, Playwright starts all engines.
#
# Unfortunately Playground is not ready at this point, it hast started WordPress
# and is going to start stepping through the blueprint, but hasn't loaded GatherPress nor imported any data;
# Resulting in failing tests.
#
# It was not possible (for me) to keep the setup of Playground in a separate step,
# why this "run > sleep > run" became necessary.
# The setup process usually takes about 20sec, so 60 is just a good extra, to not run into errors.
#
# The sleep step, should help making sure Playwright runs only, when this is DONE & READY.
#
# Because it seems to be a problem to "wait on webServer.command" https://github.com/microsoft/playwright/issues/11811
# & "it seems that globalSetup runs before webServer is started." https://github.com/microsoft/playwright/issues/11811#issuecomment-1040732201

run: |
npm run playground:mount -- --blueprint=./temp.blueprint.json & \
sleep 60 && \
echo 'Playground is ready now, lets take some pictures.' && \
# DEBUG=pw:api,pw:webserver \
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- \
npm run test:e2e


- name: Archive debug artifacts (screenshots, traces)
uses: actions/upload-artifact@v4
if: ${{ ! cancelled() }}
with:
name: failures-artifacts--${{ matrix.php }}
path: artifacts/test-results/
if-no-files-found: ignore


- name: Archive flaky tests report
uses: actions/upload-artifact@v4
if: ${{ ! cancelled() }}
with:
name: flaky-tests-report--${{ matrix.php }}
path: flaky-tests
if-no-files-found: ignore


merge-artifacts:
name: Merge Artifacts
if: ${{ ! cancelled() }}
needs: [e2e-tests]
runs-on: ubuntu-latest
outputs:
has-flaky-test-report: ${{ !!steps.merge-flaky-tests-reports.outputs.artifact-id }}
steps:
- name: Merge failures artifacts
uses: actions/upload-artifact/merge@v4
# Don't fail the job if there aren't any artifacts to merge.
continue-on-error: true
with:
name: failures-artifacts
# Retain the merged artifacts in case of a rerun.
pattern: failures-artifacts*
delete-merged: true

- name: Merge flaky tests reports
id: merge-flaky-tests-reports
uses: actions/upload-artifact/merge@v4
continue-on-error: true
with:
node-version-file: '.nvmrc'
# Enable built-in functionality for caching and restoring dependencies, which is disabled by default.
# The actions/setup-node uses actions/cache under the hood.
# https://github.com/actions/setup-node#caching-global-packages-data
cache: 'npm'

- name: NPM install
run: npm ci --legacy-peer-deps

- name: Playwright install
run: npx playwright install --with-deps

- name: Run Playwright
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WP_ADMIN_PASSWORD: ${{ secrets.WP_ADMIN_PASSWORD }}
run: npm run test:e2e
if: ${{ success() || failure() }}
name: flaky-tests-report
pattern: flaky-tests-report*
delete-merged: true
109 changes: 109 additions & 0 deletions docs/contributor/e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# End-to-end Testing using Playwright & Playground

GatherPress allows to run **automated & manual end-to-end tests** (e2e), while sharing the same, [`wp-playground/cli`](https://github.com/WordPress/wordpress-playground/pull/1289) powered, setup. The started playground imports the [`GatherPress/demo-data`](https://github.com/GatherPress/demo-data), that can be used instead of mocks or fixtures.

## Automated tests

Check the results of the [*e2e-tests action workflow*](https://github.com/GatherPress/gatherpress/actions/workflows/e2e-tests.yml) at `https://github.com/GatherPress/gatherpress/actions/workflows/e2e-tests.yml`.

## Manual testing

The e2e-setup can also be used to **manually run the test suite**. In general, only a Playground instance is needed.

### Install dependencies

To run the e2e tests you will have to install playwright using the following command:

```bash
npx playwright install --with-deps
```

> [!NOTE]
> You also need to use Node.js 20 or later

Install the dependencies to create the Playground testing instance, using the following command:

```bash
npm ci --legacy-peer-deps
```

### Start the Playground

A call to `npm run playground:mount` will automatically setup a `wp-playground/cli` powered WordPress instance, already prepared to mount GatherPress from the current directory.


```bash
npm run playground:mount -- --blueprint=./test/e2e/blueprint.json
```

The testing website is reachable at `http://127.0.0.1:9400`, the user is `admin` and the password is `password`.

### Run the e2e tests

Now while Playground is running in the background, it's possible to start the testing.

#### *Choose one of the following options*

1. For the *headless* mode, use the following command:

```bash
npm run test:e2e
```

2. Run Playwright *visually* (to run tests in isolation and change what's happening), use:

```bash
npm run test:e2e:ui
```

![grafik](https://github.com/user-attachments/assets/1627dff7-363e-447e-9981-adac610ac888)


3. For *debug* mode (which will open the browser along with Playwright Editor and allows you to record what's happening), use the following command:

```bash
npm run test:e2e:debug
```

Run all the tests against a specific project.

```bash
npm run test:e2e:debug -- project=webkit
```

Run files that have *events.spec* in the file name.

```bash
npm run test:e2e:debug -- events.spec
```

> [!NOTE]
> When writing a test, using the debug mode is recommended since it will allow you to see the browser and the test in action.

4. Run Tests independently *AND* visually using the [Playwright VSCode extension](https://playwright.dev/docs/getting-started-vscode)


### More about e2e testing

#### Start here

- [Playwright Documentation](https://playwright.dev/docs/intro)
- [End-To-End Playwright test utils for WordPress](https://github.com/WordPress/gutenberg/blob/trunk/packages/e2e-test-utils-playwright/README.md)

#### from the WordPress handbooks

- [End-to-End Testing – Block Editor Handbook | Developer.WordPress.org](https://developer.wordpress.org/block-editor/contributors/code/testing-overview/e2e/)
- [Overusing snapshots – Block Editor Handbook | Developer.WordPress.org](https://developer.wordpress.org/block-editor/contributors/code/testing-overview/e2e/overusing-snapshots/)

### More about `wp-playground/cli`, as the testing environment

Examples with great documentation:

- [Playground CLI · WordPress/wordpress-playground#1289](https://github.com/WordPress/wordpress-playground/pull/1289)
- [PoC: Run e2e tests with WP Playground · WordPress/gutenberg#62692](https://github.com/WordPress/gutenberg/pull/62692)
- [Use WordPress Playground · swissspidy/wp-performance-action#173](https://github.com/swissspidy/wp-performance-action/pull/173)

To see more examples of e2e tests, check the Gutenberg repository: [github.com/WordPress/gutenberg/tree/trunk/test/e2e](https://github.com/WordPress/gutenberg/tree/trunk/test/e2e)

> [!NOTE]
> If you are out of ideas on who to test, check the Gutenberg repository. It has a lot of examples of e2e tests that you can use as a reference.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
"screenshots:wporg": "WP_BASE_URL='http://127.0.0.1:9400/' wp-scripts test-playwright --config .github/scripts/wordpress-org-screenshots/playwright.config.ts",
"screenshots:wporg:debug": "npm run screenshots:wporg -- --debug",
"screenshots:wporg:ui": "npm run screenshots:wporg -- --ui",
"test:e2e": "playwright test --config=playwright.config.js",
"pretest:e2e": "npm run build",
"test:e2e": "WP_BASE_URL='http://127.0.0.1:9400/' wp-scripts test-playwright --config test/e2e/playwright.config.ts",
"test:e2e:debug": "npm run test:e2e -- --debug",
"test:e2e:ui": "npm run test:e2e -- --ui",
"test:unit:js": "wp-scripts test-unit-js --coverage --testResultsProcessor=jest-sonar-reporter",
"pretest:unit:php": "wp-env start --xdebug",
"test:unit:php": "wp-env run tests-wordpress php -dxdebug.mode=coverage /var/www/html/wp-content/plugins/gatherpress/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/gatherpress/phpunit.xml.dist --coverage-clover=coverage.xml --coverage-html=build/coverage-report",
Expand Down
Loading
Loading