This project is an example automates the testing of the EV Charging Portal using TypeScript, Cucumber, and Playwright. The tests are written in a Behavior-Driven Development (BDD) style to simulate a user's interaction with the portal, including requesting a charge card, verifying agreements, using the charge card for charging, and ending contracts.
This portal is a intro demo to what you can achieve with this setup. It is part of a aprox. 2 hour Gherkin Workshop.
- Description
- Features
- Installation
- Running Tests
- Debugging Tests
- Main Scenario Description
- Project Structure
The EV Charging Portal Test Suite tests the interactions between an EV driver and a charging portal system. The suite automates various scenarios such as requesting charge cards, verifying agreements, logging in, and using charge cards for EV charging. The tests ensure the system behaves as expected during these operations.
The project leverages:
- Cucumber: For defining and running the BDD-style test scenarios.
- Playwright: For browser automation and interaction.
- TypeScript: For writing strongly typed step definitions and improving code quality.
- Automated browser tests for EV driver actions like logging in, requesting charge cards, verifying terms, and using charge cards.
- Uses BDD (Behavior-Driven Development) style with Cucumber to define user scenarios.
- Efficient browser automation using Playwright.
- Fully customizable, reusable hooks (
BeforeAll
,AfterAll
,BeforeStep
) for setup, teardown, and step-specific actions.
- Node.js (v14 or higher)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/your-username/ev-charging-portal-tests.git cd ev-charging-portal-tests
-
Install dependencies: Install the necessary project dependencies using npm:
npm install
To run the tests, use the following command in two seperate shells:
npm run server
npm run test
This will start Cucumber with ts-node, run the test suite, and output the results in the terminal.
- Start Debugging:
- Make sure you do a
npm run server
in a seperate shell. - Select the
Debug Cucumber Tests
configuration in the Debug panel in VS Code. - Press
F5
to start debugging. - You can use F10 (Step Over) to step over lines of code or F11 (Step Into) to go inside a function or step.
- Make sure you do a
Debugging with breakpoints allows you to step through each test, inspect variables, and get a deeper understanding of what happens at each step in the test.
The primary scenario tested in this suite simulates an EV driver requesting a charge card via the portal. Here's an outline of the process:
- The EV driver logs into the portal.
- The driver selects a charge card from several options (e.g., Basic Charge Card, Premium Charge Card).
- The system processes the request and issues the selected charge card with a unique tag.
- The driver verifies the card tag and checks the agreement associated with the card.
- The driver uses the card for a charging session.
- Finally, the driver ends the contract, deactivating the charge card, and the agreement is archived.
Feature: EV Driver Requests Charge Card via Portal
Scenario Outline: EV Driver requests a charge card via portal and completes the card lifecycle
Given the EV driver is logged into the portal
When the EV driver selects the "<Card Type>" charge card
And submits a request for the charge card
Then the system should process the request
And the system should issue the "<Card Type>" charge card with a unique card tag
And the agreement for "<Card Type>" should be visible in the driver's account
When the EV driver verifies the issued charge card tag and agreement
Then the tag should match the expected format
And the agreement should include all necessary terms for "<Card Type>"
When the EV driver uses the "<Card Type>" for a charging session
Then the session should be successfully logged with the correct charge card tag
When the EV driver ends the contract for "<Card Type>"
Then the system should mark the charge card as deactivated
And the agreement should show to be ended to the customer
Examples:
| Card Type | Description | Validity Period | Fee Structure |
| Pay-As-You-Go Charge Card | No fixed fee, per session cost| Unlimited | $0/month + $1/session|
| Premium Charge Card | Card with higher access levels| 24 months | $10/month |
| Basic Charge Card | Standard card with monthly fee| 12 months | $5/month |
This scenario ensures that the charge card lifecycle works smoothly from request to contract termination.
The project structure follows a typical Cucumber + Playwright + TypeScript setup:
.
├── features/ # Contains all feature files and step definitions
│ ├── charging-portal/ # Specific to charging portal scenarios
│ │ ├── charging-portal.feature
│ │ ├── charging-portal.steps.ts
├── node_modules/ # Installed dependencies
├── cucumber.config.ts # Cucumber configuration file
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration file
└── README.md # This file
This test suite provides a comprehensive way to validate the functionality of the EV Charging Portal by simulating real-world user interactions. It automates the entire lifecycle of a charge card request and usage, ensuring that the system behaves correctly throughout. Feel free to explore and extend the test scenarios as needed!