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

E2E tests migration to Playwright #17814

Closed
wants to merge 742 commits into from
Closed

Conversation

adimoldovan
Copy link
Member

@adimoldovan adimoldovan commented Nov 16, 2020

Closed in favor of 18762

This is a POC for a migration of E2E tests from Puppeteer to Playwright.

This PR is replacing 17791, which was opened from a forked repo.

Changes proposed in this Pull Request:

Added dependencies:
  • playwright
  • jest-playwright-preset
  • playwright-video
  • @ffmpeg-installer/ffmpeg
Removed dependencies:
  • puppeteer
  • jest-puppeteer
Configuration changes
  • Removed jest-puppeteer.config.js and added jest-playwright.config.js instead
  • Added JEST_PLAYWRIGHT_CONFIG env variable in jest.config.js instead of CLI as it never changes
  • added testRunner: 'jasmine2' in jest.config.js to fix "referenceError: jasmine is not defined"
  • I had an error reading the config files and I could only fix it by changing the format from .js to .json. So default.js and local-tests.js are now default.json and local-tests.json
Code changes due to API differences
  • replaced waitAndClick and waitAndType with Playwright's page.click and page.type. Removed waitAndClick and waitAndType as they are now obsolete
  • replaced page.waitFor with page.waitForTimeout
  • replaced page.setCookie() with page.browserContext().addCookies()
  • replaced page.$x with page.$$(xpath='locator')
  • replaced page.waitForXPath() with page.waitForSelector()
  • replaced visibility options visible: true and hidden: true with state: 'visible' and state: 'hidden'
  • replaced page.setViewport() with page.setViewportSize()
  • replaced networkidle0 and networkidle0 with networkidle
  • updated env variables names, like PUPPETEER_HEADLES to HEADLESS
New features
  • Added video capture support, under a toggle controlled by CAPTURE_VIDEO env variable. Run with CAPTURE_VIDEO=true yarn test-e2e to capture video.
Changes unrelated to migration
  • Grouped test output (logs, videos, screenshots) under a single directory tests/e2e/output. I was not able to move allure-results though
  • Test output folder is stored in Github Actions as build artefacts
  • Added command to clean the output dir before tests run
  • Other small tweaks like locators changes to make tests pass or more resilient

Does this pull request change what data or activity we track or use?

No

Testing instructions:

All E2E tests need to pass

Proposed changelog entry for your changes:

no changelog entry needed

@jetpackbot
Copy link

jetpackbot commented Nov 16, 2020

Warnings
⚠️

pre-commit hook was skipped for one or more commits

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17814

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against d0068b1

tests/e2e/lib/setup-env.js Outdated Show resolved Hide resolved
Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid!

I left a few comments, and questions for changes that I can not understand.

tests/e2e/lib/flows/jetpack-connect.js Outdated Show resolved Hide resolved
tests/e2e/lib/blocks/mailchimp.js Outdated Show resolved Hide resolved
tests/e2e/jest-playwright.config.js Outdated Show resolved Hide resolved
tests/e2e/lib/blocks/simple-payments.js Outdated Show resolved Hide resolved
tests/e2e/lib/pages/wp-admin/plugins.js Outdated Show resolved Hide resolved
tests/e2e/lib/pages/wp-admin/plugins.js Outdated Show resolved Hide resolved
tests/e2e/lib/pages/wpcom/login.js Outdated Show resolved Hide resolved
let filePath;

try {
filePath = await takeScreenshot( currentBlock, name );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to take screenshots on failures locally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? The reports with screenshots are very helpful in debugging issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on how one would debug issues locally.

I prefer running E2E tests in headful mode with E2E_DEBUG=true, which will stop the execution on failure, timeout, or exception, which is quite handy, so I can poke around and see what's happened.

tests/e2e/lib/setup-env.js Outdated Show resolved Hide resolved
tests/e2e/specs/plugin-updater.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are getting there! Would you mind taking a look at the E2E GH actions? They are failing with this TypeError: TypeError [ERR_INVALID_OPT_VALUE_ENCODING]: The value "logs/e2e-slack.log" is invalid for option "encoding"

tests/e2e/jest-playwright.config.js Outdated Show resolved Hide resolved
modules/module-headings.php Outdated Show resolved Hide resolved
tests/e2e/lib/pages/wp-admin/plugins.js Outdated Show resolved Hide resolved
if ( captureVideo ) {
video = await saveVideo(
page,
path.resolve( config.get( 'testOutputDir' ), `video/video_${ new Date().getTime() }.mp4` )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to somehow link these videos to actual tests? I guess at this moment we don't know which specific test would run, but maybe in afterAll hook we can rename the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the video capture logic into jasmine reporter listeners, giving access to test names. All videos now meaningful names. I know that jasmine will be dropped at some point, but a new runner should provide the same functionality and we can move the video logic in there.

const userAgent = await page.evaluate( () => navigator.userAgent );
logger.info( `User agent: ${ userAgent }` );

if ( captureVideo ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't think this belongs to setupBrowser. Also, since setupBrowser is being called in beforeAll and afterEach we end up with 28 video files.

I guess it does not directly related to the goal of this PR, but I'll still share my thoughts.

It would be nice to have a video per test, and save it only if test is failing (I don't think we successful runs as much)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree. But also, calling setupBrowser in an afterEach doesn't sound right to me either.
I guess I already mentioned, the entire setup could do some refactoring, maybe combined with a test runner migration. Currently my feeling is that everything is all over the place. Probably a custom environment would make most sense.
And true, not in the scope of this PR. But I will find a better place for video handling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved now, see #17814 (comment)

By also moving the logic of setting user agent from setupBrowser the method remained empty, so I removed it.

@brbrr
Copy link
Contributor

brbrr commented Nov 24, 2020

I would like to note that in this PR, tests took about 2 minutes more to complete.
For example:
7m 19s in master: https://github.com/Automattic/jetpack/runs/1448461525
9m 30s in this branch: https://github.com/Automattic/jetpack/pull/17814/checks?check_run_id=1448587774

@adimoldovan
Copy link
Member Author

I would like to note that in this PR, tests took about 2 minutes more to complete.
For example:
7m 19s in master: https://github.com/Automattic/jetpack/runs/1448461525
9m 30s in this branch: https://github.com/Automattic/jetpack/pull/17814/checks?check_run_id=1448587774

Other runs took less, but still an average of 1 minute longer:
7m 59s: https://github.com/Automattic/jetpack/runs/1449989038?check_suite_focus=true
8m 10s: https://github.com/Automattic/jetpack/runs/1449487928?check_suite_focus=true
8m 16s: https://github.com/Automattic/jetpack/runs/1448447559?check_suite_focus=true

I wondered if video capture has any significant effect, but it seems it doesn't.

I'll take a quick look, but I think a more in depth analysis is required here and maybe optimisations in tests/setup/teardown code would be required.

/**
* Internal dependencies
*/
import logger from './logger';
import { execSyncShellCommand } from './utils-helper';

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the reasons for these custom methods was to log every test action, to see what's going on. You mentioned that there is DEBUG=pw:api env variable that we can use to achieve similar behavior. I'd like to hear your take on this, and maybe how would you approach it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed those methods were logging actions, if/where they were used. Playwright's auto-wait introduces the risk of not using those methods in a consistent way.
I also believe the logged information was only useful in case you're debugging, otherwise it's polluting the log. In case of failure, the failing action is logged anyway, with element locator if relevant. With Playwright, if you want to debug, running the tests with DEBUG=pw:api will give the same result, but with more information and in a consistent way.

I've added the option under the E2E_DEBUG, so there's a single debug toggle. So now, E2E_DEBUG=true will also trigger pw:api logging.

Also, I'm not very familiar with Winston, but I'm assuming there as way to filter pw:api log entries. Then have a different debug file with only those entries. Or have a file with everything and a clean one without those entries. There are more ideas.

kraftbj and others added 13 commits January 14, 2021 09:10
Co-authored-by: Brandon Kraft <[email protected]>
Co-authored-by: Brad Jorsch <[email protected]>
Co-authored-by: Yaroslav Kukharuk <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brandon Kraft <[email protected]>
Bumps [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) from 2.2.2 to 2.2.4.
- [Release notes](https://github.com/TooTallNate/node-https-proxy-agent/releases)
- [Commits](TooTallNate/proxy-agents@2.2.2...2.2.4)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Lazy Images: do not include js linting config in production

* Update packages/lazy-images/.gitattributes

Co-authored-by: Brad Jorsch <[email protected]>

* Fix wrong auto-merge

* Fix spacing

Co-authored-by: Brad Jorsch <[email protected]>
* store: add media-source store (init)

* extensions: add store

* store: improve registering media source

* store: add readme for media source

* audio-player: move out global var from int. dep.

* store/media-source: Add unit tests

* store/media-source: test: Add jest-environment jsdom comment

* Update extensions/store/media-source/storeDefinition.js

Co-authored-by: Matthew Reishus <[email protected]>

* Revert "store/media-source: test: Add jest-environment jsdom comment"

This reverts commit b0dabf8.

* media-source: add eslint.js file

* media-source: simplify file structure. jsdoc.

* store: move eslint rules to extensions folder

* media-source-state: update to new structure

* media-source: minor doc changes

Co-authored-by: Matthew Reishus <[email protected]>
From February 2021, in order to provide feedback on pull requests, Code Scanning workflows must be configured with both `push` and `pull_request` triggers. This is because Code Scanning compares the results from a pull request against the results for the base branch to tell you only what has changed between the two.

Early in the beta period we supported displaying results on pull requests for workflows with only `push` triggers, but have discontinued support as this proved to be less robust.

See https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#scanning-pull-requests for more information on how best to configure your Code Scanning workflows.
- Removed empty setupBrowser
…nto test/e2e-playwright-migration

# Conflicts:
#	.github/workflows/e2e-tests.yml
#	.gitignore
#	package.json
#	projects/plugins/jetpack/tests/e2e/config/default.json
#	projects/plugins/jetpack/tests/e2e/jest-playwright.config.js
#	tests/e2e/.eslintrc.js
#	tests/e2e/.gitignore
#	tests/e2e/README.md
#	tests/e2e/config/encrypted.enc
#	tests/e2e/jest.config.js
#	tests/e2e/lib/blocks/eventbrite.js
#	tests/e2e/lib/blocks/mailchimp.js
#	tests/e2e/lib/blocks/pinterest.js
#	tests/e2e/lib/blocks/simple-payments.js
#	tests/e2e/lib/blocks/word-ads.js
#	tests/e2e/lib/flows/jetpack-connect.js
#	tests/e2e/lib/global-teardown.js
#	tests/e2e/lib/logger.js
#	tests/e2e/lib/page-helper.js
#	tests/e2e/lib/pages/jetpack-connect/site-topic.js
#	tests/e2e/lib/pages/jetpack-connect/site-type.js
#	tests/e2e/lib/pages/jetpack-connect/user-type.js
#	tests/e2e/lib/pages/page.js
#	tests/e2e/lib/pages/postFrontend.js
#	tests/e2e/lib/pages/wp-admin/block-editor.js
#	tests/e2e/lib/pages/wp-admin/dashboard.js
#	tests/e2e/lib/pages/wp-admin/in-place-authorize.js
#	tests/e2e/lib/pages/wp-admin/in-place-plans.js
#	tests/e2e/lib/pages/wp-admin/jetpack.js
#	tests/e2e/lib/pages/wp-admin/login.js
#	tests/e2e/lib/pages/wp-admin/plugins.js
#	tests/e2e/lib/pages/wp-admin/sidebar.js
#	tests/e2e/lib/pages/wpcom/authorize.js
#	tests/e2e/lib/pages/wpcom/checkout.js
#	tests/e2e/lib/pages/wpcom/connections.js
#	tests/e2e/lib/pages/wpcom/login.js
#	tests/e2e/lib/pages/wpcom/my-plan.js
#	tests/e2e/lib/pages/wpcom/pick-a-plan.js
#	tests/e2e/lib/pages/wpcom/plans.js
#	tests/e2e/lib/pages/wpcom/thank-you.js
#	tests/e2e/lib/plan-helper.js
#	tests/e2e/lib/reporters/screenshot.js
#	tests/e2e/lib/setup-env.js
#	tests/e2e/lib/tunnel-manager.js
#	tests/e2e/lib/utils-helper.js
#	tests/e2e/specs/free-blocks.test.js
#	tests/e2e/specs/plugin-updater.test.js
#	tests/e2e/specs/pro-blocks.test.js
#	yarn.lock
@adimoldovan adimoldovan requested review from gibrown and a team as code owners February 5, 2021 11:22
@matticbot matticbot added the [Status] Needs Tracks Review Added/removed/modified a tracks event. label Feb 5, 2021
@github-actions github-actions bot added the [Status] Needs Package Release This PR made changes to a package. Let's update that package now. label Feb 5, 2021
@brbrr brbrr removed request for a team and gibrown February 5, 2021 13:45
@adimoldovan adimoldovan closed this Feb 9, 2021
@adimoldovan adimoldovan deleted the test/e2e-playwright-migration branch June 21, 2021 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Tests [Status] Needs Package Release This PR made changes to a package. Let's update that package now. [Status] Needs Tracks Review Added/removed/modified a tracks event. Touches WP.com Files Trial Project
Projects
None yet
Development

Successfully merging this pull request may close these issues.