JavaScript · Cypress
Agriculture with Cypress
Three tools in tabs: a sortable mandi price table with price alerts, a fertiliser calculator that turns soil-test levels into urea/DAP/MOP bag counts, and equipment rental with dates and day steppers.
App under test
🌾 FarmMart
- URL
- /apps/agri
- Login
- not required
- Bags
- 50 kg each
- Prices
- ₹ per quintal (fictional)
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Tab switching
Beginneragri-tab-* are role=tab with aria-selected; only the active panel is rendered.
- 2
Sort a column
Beginnersort-modal-price toggles descending/ascending; aria-sort on the header changes too.
- 3
Dependent data
IntermediateChanging price-state or price-crop reloads price-row rows and alert-market options.
- 4
Alert logic
IntermediateSetting an alert below the current price says “already above”; above it says “we'll notify you”.
- 5
Calculator maths
AdvancedWheat, 5 acres, soil N low / P medium / K high → urea 12, DAP 6, MOP 2 bags.
- 6
Calculator validation
BeginnerMissing crop/soil or area outside 0–100 shows fert-error.
- 7
Rental totals
Intermediaterental-total = per-day rate × rental-days; book-rental stays disabled until equipment and date are chosen.
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 ×3 · #id ×4 · [name] ×4 · [aria-label] ×2 · getByTestId ×11
describe('FarmMart — agriculture', () => {
it('checks prices, doses fertiliser and rents a tractor', () => {
cy.visit('/apps/agri');
cy.get('#price-state').select('Punjab');
cy.get('[name="price-crop"]').select('wheat');
cy.getByTestId('modal-price').eq(0).should('contain', '2,490');
cy.getByTestId('sort-modal-price').click();
cy.getByTestId('modal-price').eq(0).should('contain', '2,175');
cy.get('#alert-market').select('Ludhiana');
cy.get('[name="alert-price"]').type('2400');
cy.contains('button', 'Set alert').click();
cy.getByTestId('alert-message').should('contain', 'already above');
cy.getByTestId('agri-tab-fertiliser').click();
cy.get('#fert-crop').select('wheat');
cy.get('[name="fert-acres"]').type('5');
cy.get('#soil-n').select('low');
cy.get('[name="soil-p"]').select('medium');
cy.getByTestId('soil-k').select('high');
cy.contains('button', 'Calculate').click();
cy.getByTestId('fert-urea-bags').should('contain', '12');
cy.getByTestId('fert-dap-bags').should('contain', '6');
cy.getByTestId('fert-mop-bags').should('contain', '2');
cy.getByTestId('agri-tab-rental').click();
cy.getByTestId('equipment-tractor').click();
cy.getByTestId('rental-start').eq(0).click();
cy.get('[aria-label="Increase Days"]').click();
cy.get('[aria-label="Increase Days"]').click();
cy.getByTestId('rental-total').should('contain', '₹3,600');
cy.contains('button', 'Book equipment').click();
cy.getByTestId('rental-booked').should('contain', 'RNT-');
});
});