Writing Tests
Overview
Playwright Bingo uses Cucumber for writing tests in a Behavior-Driven Development (BDD) style. This approach makes tests more readable and maintainable by using natural language to describe test scenarios.
Feature Files
Feature files are written in Gherkin syntax and describe the behavior of your application:
Feature: Login Functionality
Scenario: Successful login
Given I am on the login page
When I enter my credentials
Then I should be logged in
Step Definitions
Step definitions connect your Gherkin scenarios to the actual test code:
const { Given, When, Then } = require('@cucumber/cucumber');
const { env } = require('./lib/mask');
Given('I am on the login page', async function() {
await this.page.goto('/login');
});
When('I enter my credentials', async function() {
const email = env.TEST_EMAIL;
const password = env.TEST_PASSWORD;
await this.loginPage.login(email, password);
});
Then('I should be logged in', async function() {
await this.dashboardPage.verifyLoggedIn();
});
Test Organization
Organize your tests effectively:
Directory Structure
playwright-bingo/
├── features/ # Cucumber feature files
├── step-definitions/ # Step definitions
├── support/ # Support files
└── tests/ # Test files
Best Practices
- Group related scenarios in feature files
- Use tags to organize and filter tests
- Keep step definitions focused and reusable
- Use page objects for all page interactions
- Implement proper error handling and logging
Running Tests
Run your tests using the following commands:
# Run all tests
npm test
# Run specific feature
npm test -- features/login.feature
# Run tests with specific tag
npm test -- --tags @smoke
Test Reports
Playwright Bingo generates detailed test reports:
- Cucumber HTML reports
- Allure reports for detailed test analysis
- Screenshots for failed tests