Page Object Model — typed and chainable
A typed, chainable page object for a login page. Encapsulates selectors, exposes intent-named actions, and returns `this` for fluent test code.
export class LoginPage {
visit(): this {
cy.visit('/login');
return this;
}
fillEmail(email: string): this {
cy.get('[data-testid="email-input"]').type(email);
return this;
}
fillPassword(password: string): this {
cy.get('[data-testid="password-input"]').type(password, { log: false });
return this;
}
submit(): this {
cy.get('[data-testid="submit-btn"]').click();
return this;
}
assertInvalidCredentials(): this {
cy.get('[data-testid="error-message"]')
.should('be.visible')
.and('contain', 'Invalid credentials');
return this;
}
}// Setup
loginPage.ts in cypress/pages/. No extra packages required — the class uses global cy commands. Ensure cypress/tsconfig.json includes "types": ["cypress"] so TypeScript resolves cy.// How to use
describe block (const loginPage = new LoginPage()) and chain methods: loginPage.visit().fillEmail('…').submit(). Each method returns this, so assertions can be chained inline too.