[ agent view ]
Documentation Index
Fetch the complete documentation index at: https://e2e.com/docs/llms.txt Use this file to discover all available pages before exploring further.
From Cypress
Replace Cypress command chains with async tests and keep your data-cy attributes.
e2e replaces Cypress command chains with async TypeScript tests that run in Node. Both suites can stay in the project while you move one spec at a time.
For a migration that spans several sessions, the migrate-to-e2e skill records what moved in a progress file and keeps the old suite running until you retire each test.
Port the config
<Note>Install e2e and configure a model with the quickstart. The example below uses an agent call.</Note>
Keep your data-cy attributes. The config below reads them as test ids.
| Cypress | e2e |
|---|---|
baseUrl | app: { url } on the target |
start-server-and-test | app: { url, command }, see Starting your app |
viewportWidth, viewportHeight | web({ viewport }) |
data-cy selectors | web({ testIdAttribute: 'data-cy' }), then screen.getByTestId |
retries | retries |
env, Cypress.env() | process.env |
cypress.env.json secrets | credentials and secrets, see Authentication |
cypress run --browser firefox | A second target with web({ browser: 'firefox' }) |
| Component testing | No equivalent |
export default {
targets: [{
engine: web({ testIdAttribute: 'data-cy' }),
app: { url: 'http://localhost:3000' },
}],
} satisfies E2EConfig;
Rewrite one spec
Start with a spec that often breaks.
describe('todos', () => {
it('completes one', () => {
cy.visit('/todos');
cy.get('[data-cy=new-todo]').type('Buy milk{enter}');
cy.get('[data-cy=new-todo]').type('Walk the dog{enter}');
cy.contains('li', 'Buy milk').find('[data-cy=toggle]').click();
cy.get('[data-cy=todo]').should('have.length', 2);
cy.contains('1 item left').should('be.visible');
});
});
describe('todos', () => {
test('completes one', async ({ app, agent, screen }) => {
await app.open('/todos');
await agent.act('add todos "Buy milk" and "Walk the dog"');
await expect(screen.getByTestId('todo')).toHaveCount(2);
await agent.act('complete "Buy milk"');
await expect(screen.getByText('1 item left')).toBeVisible();
});
});
Map each command
| Cypress | e2e |
|---|---|
cy.visit(path) | app.open(path) |
cy.get('[data-cy=x]') | screen.getByTestId('x') |
cy.get('css') | browser.locator('css'), not portable; prefer a role or label |
cy.contains('text') | screen.getByText('text', { exact: false }) |
cy.contains('li', 'text') | screen.getByRole('listitem').filter({ hasText: 'text' }) |
.find(), .within() | Chain a query off the locator: row.getByRole(...) |
.first(), .eq(n) | .first(), .nth(n) |
.click(), .dblclick(), .rightclick() | .tap(), .doubleTap() (or .dblclick()), .secondaryTap() |
.type('text') | .fill('text') replaces the content |
.type('{enter}') | .press('Enter') |
.clear(), .check(), .select() | .clear(), .check(), .selectOption() |
.selectFile() | .setInputFiles() |
.should('be.visible') | await expect(locator).toBeVisible() |
.should('have.text', t), .should('contain', t) | .toHaveText(t), .toContainText(t) |
.should('have.length', n) | .toHaveCount(n) |
.should('have.value', v) | .toHaveValue(v) |
.should('not.exist') | .toHaveCount(0); toBeHidden() also accepts a node that is still in the DOM |
cy.url().should('include', p) | expect(browser).toHaveURL(/p/) |
cy.title() | expect(browser).toHaveTitle() |
cy.intercept(url, body) | browser.route(url, route => route.fulfill({ json: body })) |
cy.wait('@alias') | browser.waitForResponse(url) |
cy.on('window:confirm') | browser.onDialog('accept') |
cy.window(), cy.document() | browser.evaluate(() => ...) |
cy.setCookie | browser.setCookies |
cy.viewport | browser.setViewport |
cy.session | test.setup and { session } |
cy.task, cy.exec, cy.request | Node code: fetch, fs, your database client |
cy.fixture | import data from './fixture.json' |
Cypress.Commands.add | A function, or a fixture from test.extend |
cy.wait(ms) | Use a locator assertion for the condition you need |
cypress open | npx e2e run --headed, plus --debug for the step table |
Two things differ from Cypress:
- There is no chain. Await each call on its own line. It returns a value:
const text = await locator.textContent(). - Actions and single-node reads and assertions need one match. Several fail
with
LOCATOR_AMBIGUOUS. Narrow with.filter(),.first(), or.nth(). See screen.
Next
Goals, assertions, and locators instead of scripted selectors.
Routes, dialogs, downloads, iframes, and page evaluation.
