JavaScript · Cypress
Banking with Cypress
Two-step login with lockout, account dashboard, add a beneficiary, transfer funds with OTP, manager approval for large transfers, session timeout, a paginated statement and a buggy build.
App under test
🏦 TrustBank
- URL
- /apps/bank
- Customer ID
- 100200300
- Manager ID
- 900800700
- Password
- Bank@123
- Security answer
- greenwood
- OTP
- 246810
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Invalid login & lockout
BeginnerWrong password shows attempts left in login-error; the 3rd failure locks the form (reset-lock).
- 2
Two-step authentication
BeginnerAfter step 1, security-question appears; a wrong answer keeps you on step 2.
- 3
Route guard
BeginnerOpening /apps/bank/dashboard signed out redirects to the login page.
- 4
Add a payee
IntermediateValidate IFSC pattern and matching account numbers; pasting into the confirm field is blocked.
- 5
Transfer rules
IntermediateBalance, daily limit (₹50,000) and RTGS minimum each raise their own error-* message.
- 6
OTP step
IntermediateWrong OTP shows otp-error; 246810 completes the transfer after a processing overlay.
- 7
Balance reconciliation
Advancednew-balance on the receipt must equal the old balance minus the amount, and match the dashboard.
- 8
Statement filters & paging
AdvancedCombine history-* filters, walk page-next until disabled, export download-statement CSV.
- 9
Session timeout
AdvancedMock the clock 10 minutes ahead: you're logged out and see session-expired.
- 10
Maker and checker
Advanced₹25,000 or more shows approval-notice and ends on transfer-pending with the balance unchanged; manager 900800700 approves or rejects (10+ character reason) in approvals-table.
- 11
Role-based access
IntermediateThe customer sees access-denied on /apps/bank/approvals; the manager sees it on /apps/bank/transfer.
- 12
Bug hunt
AdvancedCustomer ID 100200399 has 5 seeded defects (daily limit, receipt balance, debit filter, CSV, OTP) — catch each with a test.
- 13
UI vs API
AdvancedPOST /api/bank/transfer-check returns the same error text as the form; GET /api/bank/rules lists the limits.
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 ×6 · #id ×5 · [name] ×5 · [aria-label] ×1 · getByTestId ×9
describe('TrustBank — net banking', () => {
it('transfers money to a new payee', () => {
cy.visit('/apps/bank');
cy.get('#customer-id').type('100200300');
cy.get('[name="bank-password"]').type('Bank@123');
cy.contains('button', 'Continue').click();
cy.getByTestId('security-question').should('be.visible');
cy.get('#security-answer').type('greenwood');
cy.contains('button', 'Sign in').click();
cy.location('pathname').should('include', '/apps/bank/dashboard');
cy.getByTestId('customer-name').should('contain', 'Amir Khan');
cy.getByTestId('action-transfer').click();
cy.location('pathname').should('include', '/apps/bank/transfer');
cy.get('[name="from-account"]').select('savings');
// Add a beneficiary in the modal
cy.getByTestId('add-payee').click();
cy.get('#payee-name').type('Ravi Kumar');
cy.get('[name="payee-account"]').type('123456789012');
cy.get('#payee-confirm-account').type('123456789012');
cy.get('[name="payee-ifsc"]').type('TRST0001234');
cy.contains('button', 'Save payee').click();
cy.get('#amount').type('2500');
cy.getByTestId('mode-imps').click();
cy.get('[name="remarks"]').type('Rent');
cy.contains('button', 'Review transfer').click();
cy.getByTestId('review-payee').should('contain', 'Ravi Kumar');
cy.contains('button', 'Confirm').click();
cy.get('[aria-label="One-time password"]').type('246810');
cy.contains('button', 'Verify & transfer').click();
cy.getByTestId('transfer-success').should('be.visible');
cy.getByTestId('transfer-amount').should('contain', '2,500.00');
cy.getByTestId('new-balance').should('contain', '1,22,930.50');
});
});