JavaScript · Cypress
Legal with Cypress
Filter lawyers by practice area, city and language and book a consultation; then generate a rental agreement through a wizard with a live document preview, cross-field rules, typed e-signatures and a stamp-duty calculation.
App under test
⚖️ LexDesk
- URL
- /apps/legal
- Deposit cap
- 6 × monthly rent
- Stamp duty
- 0.25% (min ₹100)
- Consult days
- closed Sundays
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Directory filters
Beginnerarea-*, lawyer-city, lawyer-language and lawyer-sort change lawyer-count and order.
- 2
Booking modal validation
Intermediateconfirm-consult without mode/day/time or with a short description shows consult-error.
- 3
Live preview
IntermediateTyping in the wizard updates preview-* fields immediately; blanks show underscores.
- 4
Cross-field rules
AdvancedDeposit above 6 months' rent and landlord = tenant are rejected with specific error-* messages.
- 5
Exact-match signatures
Intermediatelandlord-signature / tenant-signature must match the names exactly (case and spaces).
- 6
Stamp duty maths
Intermediate₹25,000 × 11 months + ₹1,50,000 deposit → stamp-duty ₹1,063.
- 7
Wizard navigation
Beginnerdoc-back keeps entered values; the stepper marks completed steps.
Sample Cypress suite
A working starting point that finds elements every way Cypress can — by role, label, text, id, name, CSS, XPath and data-testid — so you practice them all. Pick your language, switch to data-testid only to compare, or try your own in the Locator Playground.
Cypress runs inside the browser, so it only supports JavaScript and TypeScript — there is no Python, Java or C# version of Cypress. For those languages, see Selenium or Playwright.
// Uses the getByTestId custom command from the Cypress setup (cypress/support/commands.js).
// Locators in this suite: cy.contains ×4 · #id ×7 · [name] ×6 · getByTestId ×13
describe('LexDesk — legal', () => {
it('books a lawyer and signs a rental agreement', () => {
cy.visit('/apps/legal');
cy.contains('button', 'Property').click();
cy.getByTestId('lawyer-count').should('contain', '2 lawyers');
cy.get('#lawyer-sort').select('fee');
cy.getByTestId('book-l4').click();
cy.contains('button', 'Video').click();
cy.get('[data-testid="consult-day"]:not([disabled])').first().click();
cy.get('[name="consult-time"]').select('12:00');
cy.get('#consult-issue').type('Need a review of my rental agreement before signing.');
cy.getByTestId('confirm-consult').click();
cy.getByTestId('consult-booked').should('contain', 'LX-');
// Generate a rental agreement
cy.contains('a', 'Create agreement').click();
cy.get('[name="landlord-name"]').type('Meera Kulkarni');
cy.get('#tenant-name').type('Amir Khan');
cy.getByTestId('preview-tenant').should('contain', 'Amir Khan');
cy.getByTestId('doc-next').click();
cy.get('[name="property-address"]').type('Flat 12B, Palm Residency, Baner');
cy.get('#property-city').select('Pune');
cy.getByTestId('doc-next').click();
cy.get('[name="monthly-rent"]').type('25000');
cy.get('#security-deposit').type('150000');
cy.get('[name="term-months"]').select('11');
cy.getByTestId('agreement-start').eq(0).click();
cy.getByTestId('preview-rent').should('contain', '₹25,000');
cy.getByTestId('duty-estimate').should('contain', '₹1,063');
cy.getByTestId('doc-next').click();
cy.get('#landlord-signature').type('Meera Kulkarni');
cy.get('[name="tenant-signature"]').type('Amir Khan');
cy.get('#esign-consent').check();
cy.contains('button', 'Sign agreement').click();
cy.getByTestId('agreement-id').should('contain', 'AGR-');
cy.getByTestId('stamp-duty').should('contain', '₹1,063');
cy.getByTestId('preview-signed').should('contain', 'Signed electronically');
});
});