Automated E2E Testing of Identity Workflows: Cypress & Didit
Learn how to implement robust end-to-end testing for your identity verification workflows using Cypress and Didit's developer-first sandbox.

Streamline Testing with Didit SandboxDidit provides a developer-first sandbox environment, allowing you to simulate real identity verification scenarios without impacting production or incurring costs, making it ideal for automated E2E testing.
Cypress for Comprehensive E2E CoverageCypress offers a fast, reliable, and developer-friendly framework for writing end-to-end tests that interact directly with your application's UI, including complex identity verification flows.
Automate Identity Workflow ValidationBy combining Cypress with Didit's API, you can programmatically create test sessions, trigger various verification outcomes, and assert that your application correctly handles each scenario, from successful KYC to rejections.
Didit's Modular Architecture Enhances TestabilityDidit's open, modular identity platform allows for granular testing of individual verification steps like ID Verification or Liveness, and then integrating them into orchestrated workflows, ensuring each component functions flawlessly.
The Challenge of Testing Identity Workflows
Identity verification workflows are critical components of modern applications, safeguarding against fraud and ensuring compliance. However, their multi-step nature, reliance on external services, and varying outcomes make them notoriously difficult to test comprehensively. Manual testing is slow, error-prone, and doesn't scale. Automated end-to-end (E2E) testing is essential to ensure a smooth, secure, and reliable user experience, but it requires a strategic approach, especially when dealing with third-party identity providers.
Traditional testing often struggles with simulating real-world scenarios for ID verification, liveness checks, or AML screening without incurring costs or relying on slow, inconsistent external systems. This is where a developer-first identity platform like Didit, combined with a powerful E2E testing tool like Cypress, becomes invaluable. By leveraging Didit's sandbox environment and clean APIs, developers can simulate a full spectrum of identity verification outcomes, ensuring every edge case is covered without compromise.
Setting Up Your E2E Testing Environment with Cypress
Cypress is a next-generation front-end testing tool built for the modern web. It offers a unique architecture that runs tests directly in the browser, providing fast execution, real-time reloading, and excellent debugging capabilities. To get started, you'll need to install Cypress in your project:
npm install cypress --save-dev
npx cypress open
Once installed, Cypress will create a cypress folder with example tests. For identity workflows, you'll typically interact with your application's UI to initiate a verification session and then potentially interact with Didit's API to control or query the session status. Cypress allows you to write tests that:
- Navigate to your onboarding or verification page.
- Fill out forms and click buttons.
- Intercept network requests to mock API responses (though for Didit, we'll often prefer real API calls to the sandbox).
- Assert on UI elements and their states after verification outcomes.
Integrating Didit's Sandbox for Realistic Scenarios
Didit is designed with developers in mind, offering an AI-native, modular identity platform. A key advantage for testing is its robust sandbox environment. This allows you to perform full identity verification flows – including ID Verification (OCR, MRZ, barcodes), Passive & Active Liveness, 1:1 Face Match, and AML Screening & Monitoring – without using real user data or incurring production costs. You can trigger specific outcomes (e.g., approved, declined, in review) using the sandbox, making your E2E tests incredibly powerful and predictable.
When you create a Didit workflow in your Business Console, you get a workflow_id. For testing, you'll use this workflow_id in conjunction with your Didit API Key (from the 'API & Webhooks' section in your console) to programmatically create verification sessions within your Cypress tests. This allows you to:
- Initiate Sessions: Use Didit's API to create a verification session, retrieving the
verification_urlto redirect your Cypress browser to. - Simulate User Actions: Within Cypress, navigate through the Didit-hosted verification flow, simulating document uploads, liveness checks, etc.
- Control Outcomes (Sandbox): In a sandbox environment, you can often use specific test data or parameters to force a particular outcome (e.g., a specific document image for an 'approved' result, or a known fraudulent image for 'declined').
- Retrieve Results: After the user completes the flow (or it's abandoned/declined), use Didit's API again to retrieve the session status and detailed results.
Automating Identity Workflow Validation with Didit and Cypress
The real power comes from combining Cypress's UI interaction capabilities with Didit's API for session management. Consider a test case where a user completes a KYC flow successfully:
- A Cypress test starts: Your test navigates to your application's login/signup page.
- Trigger Didit session: Your application, or the Cypress test itself (via
cy.request), makes an API call to Didit to create a verification session using a specificworkflow_idconfigured for your sandbox. - Redirect to Didit: Your application redirects the user (and thus Cypress) to the
verification_urlreturned by Didit. - Complete verification: Cypress interacts with the Didit-hosted flow, simulating document uploads and liveness checks. Within the sandbox, you can use predefined test images or data to ensure a successful outcome.
- Return to your app: After completion, Didit redirects back to your application's callback URL.
- Verify application state: Cypress asserts that your application's UI reflects the successful verification (e.g., a 'Verified' status, access to restricted features).
- Post-test cleanup: Optionally, your test can call Didit's API to fetch the full session details (ID data, liveness scores, AML results) and assert that the data returned matches expectations.
This approach allows for robust testing of both your integration with Didit and your application's handling of various verification states. Didit's modular architecture means you can test individual components like ID Verification, Passive & Active Liveness, or AML Screening & Monitoring in isolation, then combine them into complex workflows, ensuring comprehensive coverage.
How Didit Helps
Didit is engineered to simplify identity verification and, by extension, its testing. Our modular architecture and developer-first approach are perfectly suited for automated E2E testing with tools like Cypress. Didit provides:
- Free Core KYC: Our generous free tier allows extensive testing without cost concerns, especially in sandbox environments.
- Developer-First APIs and Sandbox: Instantly provisioned sandbox environments and clean APIs enable programmatic control over verification sessions, making it easy to create, manage, and query test sessions.
- Orchestrated Workflows: Design complex identity journeys (KYC, age checks, AML) in our no-code Business Console, then test them end-to-end. You can retrieve
workflow_ids from the API to use in your tests. - Structured Identity Data: After a session, retrieve comprehensive, structured data including ID Verification results, Liveness scores, 1:1 Face Match, and AML Screening outcomes, making assertions in your tests straightforward.
- Global by Design: Test your workflows across different document types and regions, ensuring your application is ready for a global user base.
By using Didit, you can focus on building your application's core features, confident that your identity verification flows are thoroughly tested and reliable. Our AI-native platform ensures accuracy, while our flexible architecture ensures testability.
Ready to Get Started?
Ready to see Didit in action? Get a free demo today.
Start verifying identities for free with Didit's free tier.