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

ci(e2e): e2e with playwright #1171

Merged
merged 23 commits into from
Sep 14, 2023
Merged

ci(e2e): e2e with playwright #1171

merged 23 commits into from
Sep 14, 2023

Conversation

subzero10
Copy link
Member

@subzero10 subzero10 commented Aug 25, 2023

Status

Ready

Description

I decided to give playwright a go and see how it performs versus our current integration tests.

  • Run tests on Browserstack from Playwright. Running on minimum and latest versions. Supported browsers: chrome and edge.
  • Run tests on local browser executables (shipped with playwright): Firefox, Chrome, Edge, Safari, Chromium and mobile browsers

Karma vs Playwright

Karma/Jasmine

Pros:

  • runs on Browserstack, supports all browsers and browser versions available on Browserstack

Cons:

  • feels outdated
  • tests are becoming more and more flaky
  • lots of usage of setTimeout (especially since the switch to promises from the callback-based approach)
  • difficult to debug

Playwright

Pros:

  • modern api
  • fast (even faster when not connected to remote browsers on browserstack)
  • support for flaky tests
  • local browser testing (installed through npm)
  • browserstack support (though limited to chrome and edge)

Cons:

  • recommended approach is to test only on latest browser versions, but we also want to test on older versions

Todos

  • Migrate all tests to playwright
  • Browserstack integration
  • Karma/Jasmine vs Playwright comparison
  • README.md - explain the minimal architecture (server.js)

@subzero10 subzero10 self-assigned this Aug 25, 2023
@subzero10 subzero10 force-pushed the e2e-with-playwright branch from 8efa659 to 4ad6263 Compare August 25, 2023 11:39
@subzero10 subzero10 force-pushed the e2e-with-playwright branch from 4ad6263 to c14661a Compare August 25, 2023 14:29
@subzero10 subzero10 force-pushed the e2e-with-playwright branch from 3808b66 to 717755a Compare August 26, 2023 14:18
@subzero10
Copy link
Member Author

Tests are passing, but we now have "2 flaky tests" tagged from playwright.
I will look at them separately.

Copy link
Contributor

@BethanyBerkowitz BethanyBerkowitz left a comment

Choose a reason for hiding this comment

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

This is exciting! I'm not done testing it out, but I wanted to post what I had so far.

I did run into a problem in testing, which is that if you ctrl+C out of running the tests, it leaves bsLocal running, for me it was on port 45690. Then if you try running them again, Browserstack can't start because there's already something running on the port.

packages/js/README.md Show resolved Hide resolved
packages/js/test/e2e/browsers.ts Outdated Show resolved Hide resolved
packages/js/test/e2e/browserstack.config.ts Outdated Show resolved Hide resolved
packages/js/test/e2e/browserstack.config.ts Outdated Show resolved Hide resolved
packages/js/test/e2e/browsers.ts Outdated Show resolved Hide resolved
packages/js/test/e2e/browserstack.config.ts Outdated Show resolved Hide resolved
packages/js/test/e2e/global-setup.ts Show resolved Hide resolved
packages/js/test/e2e/global-setup.ts Outdated Show resolved Hide resolved
@subzero10
Copy link
Member Author

I did run into a problem in testing, which is that if you ctrl+C out of running the tests, it leaves bsLocal running, for me it was on port 45690. Then if you try running them again, Browserstack can't start because there's already something running on the port.

Fixed!

# Conflicts:
#	packages/js/package-lock.json
@subzero10
Copy link
Member Author

@BethanyBerkowitz Thanks for the detailed review. I went through all your comments. Feel free to go for a new review round :)

@subzero10
Copy link
Member Author

subzero10 commented Sep 11, 2023

Also, I added this #1188 to look at the flaky tests after we merge this.

Copy link
Member

@joshuap joshuap left a comment

Choose a reason for hiding this comment

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

Love it! Especially the pros/cons writeup—thanks for that. I'm sold on playwright. :)

tbh, I'd be OK with testing latest browsers if we ever had to compromise, but it's cool that we can also do the minimum versions. 👌

@subzero10
Copy link
Member Author

tbh, I'd be OK with testing latest browsers if we ever had to compromise, but it's cool that we can also do the minimum versions. 👌

💯

@subzero10
Copy link
Member Author

I'll wait for @BethanyBerkowitz's review before merging, since there were more than a few changes since the first review 😄

Copy link
Contributor

@BethanyBerkowitz BethanyBerkowitz left a comment

Choose a reason for hiding this comment

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

Yay, thanks so much @subzero10!

I still get test failures when running locally, but since you've got a separate issue open for flakiness I think this one is ready to go.

@subzero10 subzero10 merged commit fa6a6d4 into master Sep 14, 2023
@subzero10 subzero10 deleted the e2e-with-playwright branch September 14, 2023 22:32
@subzero10
Copy link
Member Author

I still get test failures when running locally, but since you've got a separate issue open for flakiness I think this one is ready to go.

I'm curious, have you tried running the tests only with playwright (i.e. disable the browserstack browsers and unset any browserstack env variables)?

@subzero10 subzero10 mentioned this pull request Sep 15, 2023
3 tasks
@BethanyBerkowitz
Copy link
Contributor

I still get test failures when running locally, but since you've got a separate issue open for flakiness I think this one is ready to go.

I'm curious, have you tried running the tests only with playwright (i.e. disable the browserstack browsers and unset any browserstack env variables)?

Mmm yeah I still get a bunch of failures -- 36 on my most recent run 🤔

36 failed
    [chromium] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [chromium] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
    [firefox] › integration.spec.ts:330:7 › Browser Integration › it shows user feedback form 
    [firefox] › integration.spec.ts:359:7 › Browser Integration › it shows user feedback form with custom labels 
    [firefox] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [firefox] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
    [webkit] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [webkit] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
    [Mobile Chrome] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [Mobile Chrome] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
    [Mobile Safari] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [Microsoft Edge] › integration.spec.ts:52:7 › Browser Integration › it logs browser type and version 
    [Microsoft Edge] › integration.spec.ts:58:7 › Browser Integration › it notifies Honeybadger of unhandled exceptions 
    [Microsoft Edge] › integration.spec.ts:66:7 › Browser Integration › it notifies Honeybadger manually 
    [Microsoft Edge] › integration.spec.ts:76:7 › Browser Integration › it reports multiple errors in the same process 
    [Microsoft Edge] › integration.spec.ts:91:7 › Browser Integration › it sends console breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:105:7 › Browser Integration › it sends string value console breadcrumbs when null 
    [Microsoft Edge] › integration.spec.ts:119:7 › Browser Integration › it sends click breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:136:7 › Browser Integration › it sends XHR breadcrumbs for relative paths 
    [Microsoft Edge] › integration.spec.ts:161:7 › Browser Integration › it sends XHR breadcrumbs for absolute paths 
    [Microsoft Edge] › integration.spec.ts:186:7 › Browser Integration › it sends fetch breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:204:7 › Browser Integration › it sends navigation breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:222:7 › Browser Integration › it sends notify breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:241:7 › Browser Integration › it sends window.onerror breadcrumbs 
    [Microsoft Edge] › integration.spec.ts:260:7 › Browser Integration › it skips onunhandledrejection when already sent 
    [Microsoft Edge] › integration.spec.ts:277:7 › Browser Integration › it sends window.onunhandledrejection breadcrumbs when rejection is an Error 
    [Microsoft Edge] › integration.spec.ts:308:7 › Browser Integration › it skips window.onunhandledrejection breadcrumbs when rejection is not Error 
    [Microsoft Edge] › integration.spec.ts:330:7 › Browser Integration › it shows user feedback form 
    [Microsoft Edge] › integration.spec.ts:359:7 › Browser Integration › it shows user feedback form with custom labels 
    [Microsoft Edge] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [Microsoft Edge] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
    [Microsoft Edge] › integration.spec.ts:470:7 › Web Worker Integration › it creates worker 
    [Google Chrome] › integration.spec.ts:330:7 › Browser Integration › it shows user feedback form 
    [Google Chrome] › integration.spec.ts:359:7 › Browser Integration › it shows user feedback form with custom labels 
    [Google Chrome] › integration.spec.ts:392:7 › Browser Integration › it sends user feedback for notice on submit 
    [Google Chrome] › integration.spec.ts:438:7 › Browser Integration › it closes user feedback form on cancel 
  111 passed (3.9m)

@subzero10
Copy link
Member Author

That's very strange. Which nodejs version are you using?

@BethanyBerkowitz
Copy link
Contributor

That's very strange. Which nodejs version are you using?

Looks like I was on 16.13.0, but I also get a bunch of failures on 20.3.1.

@BethanyBerkowitz
Copy link
Contributor

@subzero10 I tried running the playwright tests just in Firefox using --ui so I could get a better sense of what's going on. It looks like for some reason the user feedback form is added to the DOM twice.

Happy to look further into this, but I figured you have much more knowledge than me in this area and may have a sense of what's wrong?

Screen Shot 2023-09-18 at 11 08 13 AM

@subzero10
Copy link
Member Author

That's very strange. Which nodejs version are you using?

Looks like I was on 16.13.0, but I also get a bunch of failures on 20.3.1.

FYI, I'm running on node 16 as well.

@subzero10
Copy link
Member Author

@subzero10 I tried running the playwright tests just in Firefox using --ui so I could get a better sense of what's going on. It looks like for some reason the user feedback form is added to the DOM twice.

Happy to look further into this, but I figured you have much more knowledge than me in this area and may have a sense of what's wrong?

Screen Shot 2023-09-18 at 11 08 13 AM

Thanks for the insight! Yes, I can look into it! I remember adding a safeguard about this but it may not be working all the time.

@subzero10
Copy link
Member Author

OK, I know why this could happen, but I don't understand why.
For the tests, I had to disable the safeguard (isUserFeedbackScriptUrlAlreadyVisible) because I inject the feedback form script in a different way:

const handle = await page.evaluateHandle(_ => {
      // DISABLE SAFEGUARD AND SCRIPT LOADING FUNCTIONS
      window.Honeybadger.isUserFeedbackScriptUrlAlreadyVisible = () => false
      window.Honeybadger.appendUserFeedbackScriptTag = () => { }
      // ... ...
})
// ... ...

// LOAD SCRIPT USING PLAYWRIGHT
const relativePath = '../../dist/browser/honeybadger-feedback-form.js'
await page.addScriptTag({
      path: resolve(__dirname, relativePath)
})
// ... ...

However, I don't see why the addScriptTag would be called twice, or result in the script being added twice.
The only theory that could come to mind is that the page for the current test is the same as the page from the previous test, that already had the feedback form script loaded. But that can't be true, because each test is isolated with a fresh page. By the way, I can't reproduce this behavior 🤷‍♂️.

@BethanyBerkowitz
Copy link
Contributor

OK, I know why this could happen, but I don't understand why. For the tests, I had to disable the safeguard (isUserFeedbackScriptUrlAlreadyVisible) because I inject the feedback form script in a different way:

const handle = await page.evaluateHandle(_ => {
      // DISABLE SAFEGUARD AND SCRIPT LOADING FUNCTIONS
      window.Honeybadger.isUserFeedbackScriptUrlAlreadyVisible = () => false
      window.Honeybadger.appendUserFeedbackScriptTag = () => { }
      // ... ...
})
// ... ...

// LOAD SCRIPT USING PLAYWRIGHT
const relativePath = '../../dist/browser/honeybadger-feedback-form.js'
await page.addScriptTag({
      path: resolve(__dirname, relativePath)
})
// ... ...

However, I don't see why the addScriptTag would be called twice, or result in the script being added twice. The only theory that could come to mind is that the page for the current test is the same as the page from the previous test, that already had the feedback form script loaded. But that can't be true, because each test is isolated with a fresh page. By the way, I can't reproduce this behavior 🤷‍♂️.

Well, I'm not sure what you did in #1190 that could fix my problem, but the Firefox tests no longer error for me!

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

Successfully merging this pull request may close these issues.

3 participants