PracticeQAAutomation logoPracticeQAAutomation
Cy

JavaScript · Cypress

Logistics with Cypress

Pincode serviceability lookups that auto-fill the city, volumetric vs chargeable weight maths, service rules, COD limits, a barcode label and a live tracking timeline.

App under test

📦 ShipFast

URL
/apps/logistics
Pincodes
400001, 560001, 110001…
Demo AWB
SF1234567890
COD limit
₹20,000

Scenarios to automate

Work top to bottom — each one adds a new technique.

  1. 1

    Pincode lookup

    Beginner

    After 6 digits a spinner runs, then sender-city shows the city; unknown pincodes show “Not serviceable”.

  2. 2

    Weight maths

    Intermediate

    30×20×15 cm → volumetric-weight 1.8 kg; chargeable-weight is the higher value rounded up to 0.5 kg.

  3. 3

    Service rules

    Intermediate

    service-same-day is disabled unless both pincodes are in the same city.

  4. 4

    COD limit

    Intermediate

    Declared value above ₹20,000 with pay-cod shows error-payment.

  5. 5

    Live quote

    Beginner

    freight-charge and shipment-total update as weight, service, insurance and payment change.

  6. 6

    Label & barcode

    Intermediate

    awb-number is SF + 10 digits; download-label saves a text file named after it.

  7. 7

    Polling a timeline

    Advanced

    A new shipment's current-status moves Booked → Picked up → In transit every ~4s; wait for text.

  8. 8

    Unknown AWB

    Beginner

    Tracking a random AWB shows track-error; SF1234567890 shows a delivered journey.

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.

Language

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.

shipfast.cy.js
// Uses the getByTestId custom command from the Cypress setup (cypress/support/commands.js).
// Locators in this suite: cy.contains ×2 · #id ×6 · [name] ×6 · getByTestId ×13
describe('ShipFast — courier', () => {
  it('books and tracks a shipment', () => {
    cy.visit('/apps/logistics');
    cy.getByTestId('ship-now').click();
    cy.location('pathname').should('include', '/apps/logistics/ship');
    cy.get('#sender-name').type('Amir Khan');
    cy.get('[name="sender-phone"]').type('9876543210');
    cy.get('#sender-pincode').type('400001');
    cy.getByTestId('sender-city').should('contain', 'Mumbai');
    cy.get('[name="sender-address"]').type('12 Marine Drive, Churchgate');
    cy.get('#receiver-name').type('Sara Khan');
    cy.get('[name="receiver-phone"]').type('9812345678');
    cy.getByTestId('receiver-pincode').type('560001');
    cy.get('#receiver-city').should('contain', 'Bengaluru');
    cy.get('[name="receiver-address"]').type('44 MG Road, Ashok Nagar');
    cy.getByTestId('package-parcel').click();
    cy.get('#weight').type('2');
    cy.get('[name="length"]').type('30');
    cy.getByTestId('width').type('20');
    cy.get('#height').type('15');
    cy.getByTestId('volumetric-weight').should('contain', '1.8 kg');
    cy.getByTestId('chargeable-weight').should('contain', '2 kg');
    cy.get('[name="declared-value"]').type('2500');
    cy.getByTestId('service-express').click();
    cy.getByTestId('pay-prepaid').click();
    cy.getByTestId('shipment-total').should('contain', '220.00');
    cy.contains('button', 'Book shipment').click();
    cy.getByTestId('shipment-booked').should('be.visible');
    cy.getByTestId('awb-number').should('contain', 'SF');
    cy.contains('a', 'Track shipment').click();
    cy.getByTestId('tracking-result').should('contain', 'Mumbai → Bengaluru');
  });
});

Practicing another tool?