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 #17791

Closed
wants to merge 10 commits into from
Closed

E2E tests migration to Playwright #17791

wants to merge 10 commits into from

Conversation

adimoldovan
Copy link
Member

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

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
  • Added command to clean the output dir before tests run
  • Other small tweaks like locators changes to make tests pass or more resilient

Left to do

  • Change user agent
  • Make all tests pass. I'm assuming that current failures are not related to the migration, but still, a confirmation is needed.
  • There is a lot of room for code cleanup. E.g. some logging may be obsolete now as Playwright has really good debugging logging with DEBUG=pw:api option. Possibly some methods in page-helper are also obsolete.

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

Functional pre-connection tests
- Grouped test output under a single output path
- Replaced 'networkidle0' and 'networkidle2' to 'networkidle
- Replaced page.waitFor to page.waitForTimeout
- Save screenshots on failure
@jetpackbot
Copy link

jetpackbot commented Nov 12, 2020

Scheduled Jetpack release: December 1, 2020.
Scheduled code freeze: November 23, 2020

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

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 3230cd4

@@ -61,5 +60,5 @@ module.exports = async function ( globalConfig ) {
if ( process.env.CI ) {
await processSlackLog();
}
await teardown( globalConfig );
// await teardown( globalConfig );
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: Is this left here for anything in particular or missed in the cleanup?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I actually forgot about this one, tests not complaining about it...
This was a call to a jest-puppeteer function and I was not sure what to replace it with, or now, even if it should be replaced at all.
Maybe @brbrr can help.

Copy link
Contributor

Choose a reason for hiding this comment

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

it coming from jest-puppeteer dependency that we using: https://github.com/smooth-code/jest-puppeteer#create-your-own-globalsetup-and-globalteardown

I guess we playwright counterpart does not need that (I'm not sure why tho)

@@ -53,10 +53,10 @@ You can run the e2e tests locally using this command:
yarn test-e2e
```

Puppeteer runs headless by default (i.e. browser is not visible). However, sometimes it's useful to observe the browser while running tests. To see the browser window and the running tests you can pass `PUPPETEER_HEADLESS=false` as follows:
Puppeteer runs headless by default (i.e. browser is not visible). However, sometimes it's useful to observe the browser while running tests. To see the browser window and the running tests you can pass `HEADLESS=false` as follows:
Copy link
Contributor

Choose a reason for hiding this comment

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

There are various references to Puppeteer still in the codebase and documentation.

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, I left a lot of those in documentation blocks mostly. I pushed a change which replaced all except one for a piece o code that still needs to be evaluated if it should stay or go.

],
testRunner: 'jasmine2',
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that this line was added basically to make tests work. But I wonder if this is an optimal solution.

From what I gathered, with playwright we have a few options for the test runner:

  • jasmine2 (which is used in the current configuration)
  • jest-circus
  • playwright-test

Could you talk about the pros and cons of these as well? I know that circus supports test re-run which I find really appealing. Also I wonder what benefits playwright-test could provide.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was a fix for an error thrown by jest-allure library. I don't really understand how come it wasn't failing before, with the Puppeteer suite of dependencies.
This was the only working solution I could find, based on this: zaqqaz/jest-allure#8
It's not ideal, it was the way to move forward while keeping the Allure reports.
I will look into other options.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I got it. I thought the source of this error was our own usage of jasmine. I guess we would need to move away from jest-allure if we'd like to switch to circus runner.

I wonder if there are alternatives to jest-allure that would work with circus runner.

@ebinnion
Copy link
Contributor

Leaving a note that we closed this PR in favor of #17814 since this PR was created from a forked repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants