All jobs

Migrate Cypress Tests to Playwright in a Node.js App

Yes. An agent ports your Cypress specs, commands and fixtures to Playwright, starts your Node.js app and database for the suite, runs it green, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the existing suite before writing a line. In an app like OWASP/NodeGoat, Cypress is ^3.3.1 with a pre-version-10 cypress.json that points integrationFolder at test/e2e/integration, supportFile at test/e2e/support/index.js, pluginsFile at test/e2e/plugins/index.js, fixturesFolder at test/e2e/fixtures, turns video off and blacklists *:35729, the livereload port. There are 13 spec files, about 730 lines, one per route: login_spec.js, signup_spec.js, allocations_spec.js, benefits_spec.js, profile_spec.js and so on. plugins/index.js reads port and hostName from config/env/all.js, 4000 and localhost by default, and sets baseUrl from them. package.json runs the suite with test:ci, cross-env NODE_ENV=test cypress run, and the app with node server.js, which connects to MongoDB at mongodb://localhost:27017/nodegoat and exits if it cannot.

The support file is where most of the porting work is. test/e2e/support/commands.js defines five commands: signIn(usr, pw) visits /login, types into #userName and #password and clicks [type='submit']; adminSignIn and userSignIn load users/admin.json and users/user.json from fixtures and call it; visitPage wraps cy.visit; and dbReset runs npm run db:seed through cy.exec with a six-second timeout and failOnNonZeroExit: false, which maps to grunt db-reset under NODE_ENV=test. Every spec calls cy.dbReset() in before and visits /logout in afterEach. The assertions are URL and text checks: cy.url().should("include", "benefits") after an admin login, dashboard for a user, .alert-danger containing Invalid password, a signup form with seven inputs, a threshold input on /allocations/1 whose submit must land on ?threshold=2.

The agent maps each of those to Playwright. playwright.config.js sets baseURL from the same config/env/all.js values, uses the webServer option to run NODE_ENV=test node server.js and wait on the port, and keeps traces on first retry. The commands become a fixture file: test.extend provides adminPage and userPage fixtures that perform the login with page.goto('/login'), locator('#userName').fill() and click(), the JSON fixtures are imported directly, and dbReset becomes execSync('npm run db:seed') in a beforeAll per file, keeping the non-fatal behaviour the Cypress command had. Each spec is rewritten one to one: expect(page).toHaveURL(/benefits/), expect(page.locator('.alert-danger')).toContainText('Invalid password'), expect(page.locator("form[role='form'] input")).toHaveCount(7), and afterEach still visits /logout. The 13 files land in test/e2e/playwright/ with the same names and .spec.js.

Running it needs the app and a MongoDB. The sandbox has no Docker, so the agent installs it with sudo apt-get install -y docker.io, starts dockerd, and runs the mongo:4.0 image the existing e2e-test.yml uses, then npm ci, npx playwright install --with-deps chromium and npx playwright test, fixing selectors or waits until the suite passes. The workflow is rewritten in place: the cypress verify step goes, npx playwright install --with-deps chromium and npx playwright test replace npm run test:ci, the Playwright HTML report replaces the screenshots-and-videos artifact, and the Node matrix is reconsidered, since Playwright's current releases need a newer Node than the 10.x, 12.x, 14.x the workflow lists; the agent starts the app under the chosen Node in the sandbox before committing to it. Cypress and its config are removed from package.json and cypress.json is deleted only after the new suite passes.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Migrate this Node.js application's Cypress end-to-end tests to Playwright. Read cypress.json, every file under test/e2e, package.json, config/env/all.js, server.js and the existing CI workflow first. Create a Playwright config that takes the base URL from the app's own config, starts the app with its webServer option under NODE_ENV=test, and records traces on retry. Port the custom Cypress commands to Playwright fixtures, reuse the JSON user fixtures, keep the database reset before each file and the logout after each test, and port all specs one to one into a new directory with the same file names. Install what the app needs to run, including its database, and run the suite until it passes. Update the CI workflow to install Playwright browsers and run the suite on a Node version the app and Playwright both support, replacing the Cypress artifact upload with the Playwright report. Remove Cypress and its config only after the new suite passes. Open a pull request listing each ported spec and the final test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with playwright.config.js, test/e2e/playwright/fixtures.js and 13 spec files, @playwright/test in devDependencies and cypress removed, the test:e2e and test:ci scripts pointing at Playwright, cypress.json and the old test/e2e/integration, support and plugins directories deleted, .gitignore entries for test-results/ and playwright-report/, and the rewritten .github/workflows/e2e-test.yml. Application code under app/ and server.js is untouched.

The description lists every spec with its Cypress source file and Playwright target and the number of tests in each, then the final npx playwright test summary from the sandbox, the Node version the suite ran under and why it was chosen, and anything that could not be ported one to one with the reason. The full command output, including the MongoDB start and the browser install, is in the transcript at GET /o/{org}/sessions/{id}/messages.

A reviewer opens the Playwright report from the pull request's own workflow run, which now runs the new suite, spot-checks two or three ported specs against the originals in the diff, and confirms the Node version in the workflow matches what the app was tested under. A follow-up on the same session can add the Firefox and WebKit projects once Chromium is green.

Run it on every repository still on Cypress

A team with several Express services on old Cypress starts one run per repository from its own server: POST /o/{org}/sessions with this body and that repository in resources. GET /o/{org}/github lists what the GitHub App installation reaches, so a script can filter for a cypress.json and loop. Each run has its own sandbox, its own database container and its own pull request, and a request_id that is a UUID v5 of the repository name makes a retried start return the run already begun.

Give the key a webhook_url and each run reports run.completed or run.failed with its session_url within about 30 seconds of the turn ending. If a suite is too large for one turn, a follow-up POST …/sessions/{id}/messages wakes the same sandbox with the ported specs, the installed browsers and MongoDB still there.

The use case this job follows, with its automation and trigger: Write the missing tests.

Why run it on Rush?

Porting an end-to-end suite is mechanical work that constantly needs the application running: every selector and wait is checked against a real page, and here that means a Node process and a MongoDB. The agent brings both up in a sandbox, installs the browsers, and iterates until the suite passes, so the pull request contains a suite that has run rather than a translation that looks right.

The run keeps every command and its output, including the final Playwright summary and the Node version it ran under, so the pull request's claims are checkable. Several repositories can be migrated at once, each with its own database container, each with its own pull request.

Frequently asked questions

What happens to cy.exec for the database reset?

It becomes execSync('npm run db:seed') in a beforeAll hook in the shared fixtures, with the same tolerance of a non-zero exit the Cypress command had. If you would rather reset once per run, the pull request notes how to move it into a Playwright global setup.

Does the app have to run on a newer Node?

Playwright's current releases require a newer Node than the 10 to 14 range the old workflow tested. The agent starts the app under the candidate Node in the sandbox, with its MongoDB driver and bcrypt-nodejs dependency, and only writes that version into the workflow once the suite passes on it; the pull request states which version and what it checked.

Why Chromium only?

One browser keeps the first run fast and the diff reviewable; the Cypress suite ran in one browser too. Adding firefox and webkit projects is a few lines in playwright.config.js and a follow-up on the same session.

Are the Cypress files deleted?

Yes, in the same pull request, but only after the Playwright suite passed in the sandbox. The old integration, support and plugins directories, cypress.json and the cypress dependency go; the JSON user fixtures stay because the new suite reads them.

More Node.js jobs

The same job on other stacks

Keep reading