-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Merged
cliffhall
merged 41 commits into
modelcontextprotocol:main
from
msabramo:playwright-test
Jun 23, 2025
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
226ad25
Add a Playwright e2e test
msabramo 69da70a
npm run prettier-fix
msabramo 8a13526
Exclude e2e from Jest
msabramo 8babc44
Make `npm run test:e2e` work
msabramo 3a28efe
Mention `npm run test:e2e` in CONTRIBUTING.md
msabramo 89e1efc
Add more Playwright tests
msabramo c803d93
Move test:e2e up with other two test scripts
msabramo 4f6a4ce
Add .github/workflows/e2e_tests.yml
msabramo 66ad85a
npm run prettier-fix
msabramo 1df83d7
Do npm run start in background
msabramo 826bc35
Upload Playwright Report and Screenshots
msabramo a421f32
git add playwright.config.ts
msabramo f06a6e1
npm run prettier-fix
msabramo a2a58c2
Install Playwright dependencies
msabramo 705d7b4
e2e_tests.yml: playwright-report and test-result in client dir
msabramo cdb9180
Generate report with https://github.com/daun/playwright-report-summary
msabramo 2c0af88
Take screenshots on failure
msabramo 6e5ccf6
Remove commented out stuff in playwright.config.ts
msabramo 8b1faf1
playwright.config.ts: Start dev server automatically
msabramo 4ef6bdb
e2e_tests.yml: Remove start dev server
msabramo 0f1cc19
prettier fix playwright.config.ts
msabramo 0b31ce7
.gitignore: Add playwright artifacts
msabramo b783b50
Make "npm run clean" remove Playwright files
msabramo db9ca37
No playwright-report or results.json for non-CI
msabramo 2ca63cb
Merge branch 'main' into playwright-test
msabramo 08e4f6b
outputDir: "./e2e/test-results"
msabramo 8b3613e
prettier fix
msabramo 1807542
Cleanup client/e2e/test-results/ after test:e2e
msabramo b481ed0
Set `MCP_AUTO_OPEN_ENABLED=false` for `test:e2e` script
msabramo d5b4a6e
Update .github/workflows/e2e_tests.yml
msabramo eb89e01
Change retention-days from 30 to 2
msabramo 1ff39f1
Replace pull_request with pull_request_target
msabramo 4b14b96
Both pull_request and pull_request_target
msabramo 9ffe63e
Revert "Both pull_request and pull_request_target"
msabramo 3e28357
Revert "Replace pull_request with pull_request_target"
msabramo 465ee9a
Revert "Update .github/workflows/e2e_tests.yml"
msabramo c747fe8
Only try to comment on PR if the PR is from the canonical repo and no…
msabramo 94a35d0
Only try to comment on PR if the PR is from the canonical repo and no…
msabramo 2cd7b74
Revert
msabramo ebc249b
Always gen test summary but only comment on same repo PRs
msabramo 86eaabe
Merge branch 'main' into playwright-test
cliffhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Playwright Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test: | ||
| timeout-minutes: 5 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libwoff1 | ||
|
|
||
| - 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 dependencies | ||
| run: npx playwright install-deps | ||
|
|
||
| - name: Install Playwright and browsers unless cached | ||
| run: npx playwright install --with-deps | ||
| if: steps.cache-playwright.outputs.cache-hit != 'true' | ||
|
|
||
| - name: Run Playwright tests | ||
| run: npm run test:e2e | ||
|
|
||
| - name: Upload Playwright Report and Screenshots | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: playwright-report | ||
| path: | | ||
| client/playwright-report/ | ||
| client/test-results/ | ||
| client/results.json | ||
| retention-days: 2 | ||
|
|
||
| - name: Publish Playwright Test Summary | ||
| uses: daun/playwright-report-summary@v3 | ||
| if: always() | ||
| with: | ||
| create-comment: ${{ github.event.pull_request.head.repo.full_name == github.repository }} | ||
| 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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { rimraf } from "rimraf"; | ||
|
|
||
| async function globalTeardown() { | ||
| if (!process.env.CI) { | ||
| console.log("Cleaning up test-results directory..."); | ||
| // Add a small delay to ensure all Playwright files are written | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| await rimraf("./e2e/test-results"); | ||
| console.log("Test-results directory cleaned up."); | ||
| } | ||
| } | ||
|
|
||
| export default globalTeardown; | ||
|
|
||
| // Call the function when this script is run directly | ||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||
| globalTeardown().catch(console.error); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
|
|
||
| // Adjust the URL if your dev server runs on a different port | ||
| const APP_URL = "http://localhost:6274/"; | ||
|
|
||
| test.describe("Transport Type Dropdown", () => { | ||
| test("should have options for STDIO, SSE, and Streamable HTTP", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(APP_URL); | ||
|
|
||
| // Wait for the Transport Type dropdown to be visible | ||
| const selectTrigger = page.getByLabel("Transport Type"); | ||
| await expect(selectTrigger).toBeVisible(); | ||
|
|
||
| // Open the dropdown | ||
| await selectTrigger.click(); | ||
|
|
||
| // Check for the three options | ||
| await expect(page.getByRole("option", { name: "STDIO" })).toBeVisible(); | ||
| await expect(page.getByRole("option", { name: "SSE" })).toBeVisible(); | ||
| await expect( | ||
| page.getByRole("option", { name: "Streamable HTTP" }), | ||
| ).toBeVisible(); | ||
| }); | ||
|
|
||
| test("should show Command and Arguments fields and hide URL field when Transport Type is STDIO", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(APP_URL); | ||
|
|
||
| // Wait for the Transport Type dropdown to be visible | ||
| const selectTrigger = page.getByLabel("Transport Type"); | ||
| await expect(selectTrigger).toBeVisible(); | ||
|
|
||
| // Open the dropdown and select STDIO | ||
| await selectTrigger.click(); | ||
| await page.getByRole("option", { name: "STDIO" }).click(); | ||
|
|
||
| // Wait for the form to update | ||
| await page.waitForTimeout(100); | ||
|
|
||
| // Check that Command and Arguments fields are visible | ||
| await expect(page.locator("#command-input")).toBeVisible(); | ||
| await expect(page.locator("#arguments-input")).toBeVisible(); | ||
|
|
||
| // Check that URL field is not visible | ||
| await expect(page.locator("#sse-url-input")).not.toBeVisible(); | ||
|
|
||
| // Also verify the labels are present | ||
| await expect(page.getByText("Command")).toBeVisible(); | ||
| await expect(page.getByText("Arguments")).toBeVisible(); | ||
| await expect(page.getByText("URL")).not.toBeVisible(); | ||
| }); | ||
|
|
||
| test("should show URL field and hide Command and Arguments fields when Transport Type is SSE", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(APP_URL); | ||
|
|
||
| // Wait for the Transport Type dropdown to be visible | ||
| const selectTrigger = page.getByLabel("Transport Type"); | ||
| await expect(selectTrigger).toBeVisible(); | ||
|
|
||
| // Open the dropdown and select SSE | ||
| await selectTrigger.click(); | ||
| await page.getByRole("option", { name: "SSE" }).click(); | ||
|
|
||
| // Wait for the form to update | ||
| await page.waitForTimeout(100); | ||
|
|
||
| // Check that URL field is visible | ||
| await expect(page.locator("#sse-url-input")).toBeVisible(); | ||
|
|
||
| // Check that Command and Arguments fields are not visible | ||
| await expect(page.locator("#command-input")).not.toBeVisible(); | ||
| await expect(page.locator("#arguments-input")).not.toBeVisible(); | ||
|
|
||
| // Also verify the labels are present/absent | ||
| await expect(page.getByText("URL")).toBeVisible(); | ||
| await expect(page.getByText("Command")).not.toBeVisible(); | ||
| await expect(page.getByText("Arguments")).not.toBeVisible(); | ||
| }); | ||
|
|
||
| test("should show URL field and hide Command and Arguments fields when Transport Type is Streamable HTTP", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(APP_URL); | ||
|
|
||
| // Wait for the Transport Type dropdown to be visible | ||
| const selectTrigger = page.getByLabel("Transport Type"); | ||
| await expect(selectTrigger).toBeVisible(); | ||
|
|
||
| // Open the dropdown and select Streamable HTTP | ||
| await selectTrigger.click(); | ||
| await page.getByRole("option", { name: "Streamable HTTP" }).click(); | ||
|
|
||
| // Wait for the form to update | ||
| await page.waitForTimeout(100); | ||
|
|
||
| // Check that URL field is visible | ||
| await expect(page.locator("#sse-url-input")).toBeVisible(); | ||
|
|
||
| // Check that Command and Arguments fields are not visible | ||
| await expect(page.locator("#command-input")).not.toBeVisible(); | ||
| await expect(page.locator("#arguments-input")).not.toBeVisible(); | ||
|
|
||
| // Also verify the labels are present/absent | ||
| await expect(page.getByText("URL")).toBeVisible(); | ||
| await expect(page.getByText("Command")).not.toBeVisible(); | ||
| await expect(page.getByText("Arguments")).not.toBeVisible(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { defineConfig, devices } from "@playwright/test"; | ||
|
|
||
| /** | ||
| * @see https://playwright.dev/docs/test-configuration | ||
| */ | ||
| export default defineConfig({ | ||
| /* Run your local dev server before starting the tests */ | ||
| webServer: { | ||
| cwd: "..", | ||
| command: "npm run dev", | ||
| url: "http://localhost:6274", | ||
| reuseExistingServer: !process.env.CI, | ||
| }, | ||
|
|
||
| testDir: "./e2e", | ||
| outputDir: "./e2e/test-results", | ||
| /* Run tests in files in parallel */ | ||
| fullyParallel: true, | ||
| /* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
| forbidOnly: !!process.env.CI, | ||
| /* Retry on CI only */ | ||
| retries: process.env.CI ? 2 : 0, | ||
| /* Opt out of parallel tests on CI. */ | ||
| workers: process.env.CI ? 1 : undefined, | ||
| /* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
| reporter: process.env.CI | ||
| ? [ | ||
| ["html", { outputFolder: "playwright-report" }], | ||
| ["json", { outputFile: "results.json" }], | ||
| ["line"], | ||
| ] | ||
| : [["line"]], | ||
| /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
| use: { | ||
| /* Base URL to use in actions like `await page.goto('/')`. */ | ||
| baseURL: "http://localhost:6274", | ||
|
|
||
| /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
| trace: "on-first-retry", | ||
|
|
||
| /* Take screenshots on failure */ | ||
| screenshot: "only-on-failure", | ||
|
|
||
| /* Record video on failure */ | ||
| video: "retain-on-failure", | ||
| }, | ||
|
|
||
| /* Configure projects for major browsers */ | ||
| projects: [ | ||
| { | ||
| name: "chromium", | ||
| use: { ...devices["Desktop Chrome"] }, | ||
| }, | ||
|
|
||
| { | ||
| name: "firefox", | ||
| use: { ...devices["Desktop Firefox"] }, | ||
| }, | ||
|
|
||
| // Skip WebKit on macOS due to compatibility issues | ||
| ...(process.platform !== "darwin" | ||
| ? [ | ||
| { | ||
| name: "webkit", | ||
| use: { ...devices["Desktop Safari"] }, | ||
| }, | ||
| ] | ||
| : []), | ||
| ], | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.