JavaScript · Cypress
Real estate with Cypress
Buy/Rent search with BHK chips, budget ranges and type filters, grid/list views, a shortlist with side-by-side compare, a photo gallery, an EMI calculator and site-visit booking.
App under test
🏠 HomeNest
- URL
- /apps/realestate
- Login
- not required
- Cities
- Pune · Mumbai · Bengaluru
- EMI
- standard reducing-balance formula
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Buy vs Rent
Beginnermode-rent swaps the budget options (₹/month) and the listings; price labels end in /mo.
- 2
Combined filters
Intermediatebhk-* chips + budget-min/max + type-* + furnishing; a min above max shows budget-error.
- 3
Sorting & views
Intermediateestate-sort by price; view-list/view-grid changes data-view on property-list.
- 4
Shortlist state
Beginnershortlist-<id> toggles aria-pressed and the shortlist-count badge; it persists across reloads.
- 5
Compare limit
IntermediateTick compare-* on 2–3 shortlisted homes for compare-table; a 4th shows compare-limit.
- 6
Gallery carousel
Beginnergallery-next/prev wrap around; thumb-* jumps; gallery-counter shows “n / 4”.
- 7
EMI maths
AdvancedChange emi-down, emi-rate, emi-tenure and verify emi-loan and emi-result against the formula.
- 8
Masked phone & visits
Intermediatecontact-agent masks the number until reveal-phone; book-visit validates, then list/cancel it under My visits.
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 ×2 · #id ×5 · [name] ×5 · [aria-label] ×2 · getByTestId ×9
describe('HomeNest — real estate', () => {
it('shortlists a flat and books a site visit', () => {
cy.visit('/apps/realestate');
cy.contains('button', 'buy').click();
cy.get('#estate-city').select('pune');
cy.getByTestId('bhk-2').click();
cy.get('[name="budget-max"]').select('10000000');
cy.get('#type-apartment').check();
cy.get('[aria-label="Sort"]').select('price-asc');
cy.getByTestId('property-count').should('contain', '2 properties');
cy.getByTestId('shortlist-p2').click();
cy.getByTestId('shortlist-count').should('contain', '1');
cy.getByTestId('view-property-p2').click();
cy.getByTestId('property-title').should('contain', '2 BHK Apartment in Baner');
cy.get('[aria-label="Next photo"]').click();
cy.getByTestId('gallery-counter').should('contain', '2 / 4');
// EMI for ₹85 L with 20% down, 8.5% for 20 years
cy.get('[name="emi-down"]').select('20');
cy.get('#emi-rate').select('8.5');
cy.get('[name="emi-tenure"]').select('20');
cy.getByTestId('emi-result').should('contain', '59,012');
cy.getByTestId('visit-day').eq(0).click();
cy.get('#visit-time').select('11:00');
cy.get('[name="visitor-name"]').type('Amir Khan');
cy.get('#visitor-phone').type('9876543210');
cy.get('[name="visitor-email"]').type('amir@example.com');
cy.contains('button', 'Book visit').click();
cy.getByTestId('visit-confirmed').should('contain', 'VIS-');
});
});