-
Notifications
You must be signed in to change notification settings - Fork 553
Add a Playwright e2e test #460
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
base: main
Are you sure you want to change the base?
Conversation
Related PR (which has perhaps fallen into some disrepair): #354 |
Thanks for setting this up. My draft PR I'd opened for feedback has been getting pretty moldy. A couple questions about this e2e setup:
Thanks again for working on this, it should help bridge some gaps with testing basic stuff efficiently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test ran successfully, but only after
- I downloaded the browsers (additional step required beyond just
npm install
) - Launching the inspector (you can't just run
test:e2e
, you have to runstart
thentest:e2e
)
Just thinking about how to handle this in CI. We'd need to use caching to install playwright and browsers only if they aren't cached. And start the server, then wait for it to be up before running the tests.
name: Playwright Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
# Cache Playwright browsers
- name: Cache Playwright browsers
id: cache-playwright
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright # The default Playwright cache path
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }} # Cache key based on OS and package-lock.json
restore-keys: |
${{ runner.os }}-playwright-
- name: Install dependencies
run: npm ci
- name: Install Playwright and browsers unless cached
run: npx playwright install --with-deps
if: steps.cache-playwright.outputs.cache-hit != 'true'
- name: Start Server
run: npm run start
- name: Wait for server to start
run: npx wait-on http://localhost:6274
- name: Run Playwright tests
run: npm run test:e2e
@olaservo: I had been thinking that this would mainly be run in CI but I like to do things in baby steps so that I don't get overwhelmed and so reviewing is easier. My plan was to do the CI in a separate PR. Though now I'm wondering if we should just go for it since @cliffhall points out that it's not trivial to set up the tests locally and a lot of people will simply not bother, so maybe it's not of much use if it's not also run in CI. I probably should look at your PR and see what good stuff I can borrow re: config, timeouts, etc. |
Added |
@msabramo I tried but it failed on format check. Need to run |
so that the CI job can proceed
I added support for https://github.com/daun/playwright-report-summary in cdb9180. As a result, at https://github.com/modelcontextprotocol/inspector/actions/runs/15509171521?pr=460 you can see a nice Playwright test report: |
@msabramo Failures when I run the tests locally with ![]() |
@msabramo Also, I noticed that running these tests created a lot of files locally in the project. Can these not be created in the system tmp folder? I realize the CLI tests do such a thing as well, and I'd like to make that go away too, but that's for another PR. |
since now we are doing that in `playwright.config.ts`
Well, it could probably be a few things, but one possibility is that perhaps the dev server wasn't running. Regardless of whether that's the problem you're hitting, it seems like an easy problem to hit. I discovered that Playwright can start the server for us with a Give it another try with the new commits and see if it works any better. If it still doesn't work, you might try opening a browser to http://localhost:6274 while the Playwright tests are running and opening a JavaScript console and looking for errors. I actually ran into another problem that confused me for a while where the server was starting but the web page was blank and it was because of a |
You mean these: $ git status
On branch playwright-test
Your branch is up to date with 'msabramo/playwright-test'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
client/playwright-report/
client/results.json
client/test-results/ The first two are reports that are explicitly specified in 0b31ce7 - .gitignore: Add playwright artifacts b783b50 - Make "npm run clean" remove Playwright files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msabramo Failures when I run the tests locally with
/usr/local/bin/npm run test:e2e
. What am I missing?
Well, it could probably be a few things, but one possibility is that perhaps the dev server wasn't running.
Regardless of whether that's the problem you're hitting, it seems like an easy problem to hit. I discovered that Playwright can start the server for us with a
webServer
config inplaywright.config.ts
which I added in 8b1faf1. And then I removed a similar thing in thee2e_tests.yml
GH Actions workflow, because Playwright should take care of it inside and outside of CI, which seems better.
Thanks so much for getting it to auto start the server. There were no instructions to start the server, and for a local test run, it shouldn't really have to be a requirement anyhow.
@msabramo Also, I noticed that running these tests created a lot of files locally in the project. Can these not be created in the system tmp folder?
I realize the CLI tests do such a thing as well, and I'd like to make that go away too, but that's for another PR.You mean these:
$ git status On branch playwright-test Your branch is up to date with 'msabramo/playwright-test'. Untracked files: (use "git add <file>..." to include in what will be committed) client/playwright-report/ client/results.json client/test-results/The first two are reports that are explicitly specified in
playwright.config.ts
, so they seem potentially useful and I'm not sure whatclient/test-results
is for, but probably something Playwright uses, so I'd be nervous about moving them. How about if I add them to.gitignore
? Does that help with your concern?
Please forgive the bluntness, but in an already crowded project, these folders and files are just litter to me. IMO, adding them to .gitignore
and the clean
script are not an acceptable solution. The former means they remain in my project, visual clutter that I do not need to see. The latter means I need to run another command, which also removes all the node modules and does another npm install
, time I do not need to waste.
When running tests, I only care about whether they failed or passed, period. The following is all I need to see:

If you could simply make the test:e2e script delete these files after the run, it would be perfect.
16763de
to
1807542
Compare
@cliffhall: Thanks for the detailed comments! I think it should be better now. With the latest commits, I don't even generate So I think things should be clean but let me know if I missed anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @msabramo for cleaning up the unnecessary remnants. One more new side effect just showed up (not your fault in the least). Working fix suggested below.
Since merging the latest changes from `main` that put auto-open back in when running the start or dev scripts, the `test:e2e` run results in the Inspector being opened in the browser. This change suppresses that (tested locally). Thanks, @cliffhall! Co-authored-by: Cliff Hall <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's streamline this action to just run the tests and make a comment on the PR with the results.
.github/workflows/e2e_tests.yml
Outdated
client/playwright-report/ | ||
client/test-results/ | ||
client/results.json | ||
retention-days: 30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is done on every push to main, we don't need to retain these files for 30 days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduced from 30 to 2 in eb89e01.
- name: Publish Playwright Test Summary | ||
uses: daun/playwright-report-summary@v3 | ||
if: always() | ||
with: | ||
report-file: client/results.json | ||
comment-title: "🎭 Playwright E2E Test Results" | ||
job-summary: true | ||
icon-style: "emojis" | ||
custom-info: | | ||
**Test Environment:** Ubuntu Latest, Node.js 18 | ||
**Browsers:** Chromium, Firefox | ||
|
||
📊 [View Detailed HTML Report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) (download artifacts) | ||
test-command: "npm run test:e2e" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what the intention of all this is, it seems like its running the tests twice. We've already run it above in Run Playwright tests
and here we're running it to generate the report again...?
I think what we really want is the simple report with comment setup. There's no need to upload the reports and save/publish them. Just the results in a PR comment will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what the intention of all this is, it seems like its running the tests twice. We've already run it above in
Run Playwright tests
and here we're running it to generate the report again...?
I could be wrong, but my assumption is that it's not running the tests again. I think maybe:
test-command: "npm run test:e2e"
might be creating that impression? And it might be misleading because the docs for this action say:
# Command used to run tests. If provided, a command to re-run failed or
# flaky tests will be printed for each section.
# Default: ''
test-command: 'npm run test --'
so it sounds like it be more informative and not actually a way to run the tests, as it kind of seems it could be?
But maybe this needs a comment to clarify, since that is confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what we really want is the simple report with comment setup. There's no need to upload the reports and save/publish them. Just the results in a PR comment will do.
So I think this is set up to do that but it's failing to post the comment because of permissions problems:
Commenting test report on PR
Creating new comment
Error creating comment: Resource not accessible by integration
Submitting PR review comment instead...
Error creating PR review: Resource not accessible by integration
Warning: Unable to comment on your PR —
this can happen for PR's originating from a fork without write permissions.
You can copy the test results directly into a comment using the markdown summary below:
Maybe you can have a look and see if you are able to grant permissions so that this can work and you can see if you like the way it does comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try the below suggestion.
Co-authored-by: Cliff Hall <[email protected]>
Still got the following after applying d5b4a6e: |
Here's the markdown summary from the GH Actions log, manually pasted here so we can see how it looks: 🎭 Playwright E2E Test Results✅ 12 passed Details12 tests across 1 suite 📊 View Detailed HTML Report (download artifacts) |
Write a Playwright test that tests the app end-to-end (e2e).
Motivation and Context
Ensure things don't get broken
How Has This Been Tested?
Breaking Changes
No
Types of changes
Checklist
Additional context