A professional test automation framework for SLB website testing using TypeScript, Cucumber (BDD), and Playwright.
- BDD Approach: Behavior-Driven Development with Cucumber and Gherkin syntax
- TypeScript: Type-safe test automation with full IntelliSense support
- Playwright: Modern, reliable browser automation across Chromium, Firefox, and WebKit
- Page Object Model: Maintainable test architecture with reusable page objects
- Single Session Mode: Optional feature to run all scenarios in one browser session (50-60% faster)
- Robust Cookie Handling: Automatic OneTrust cookie consent management with multi-strategy approach
- Resilient Interactions: Smart click strategies (normal β JavaScript β navigation) to handle overlays
- Rich Reporting: HTML, JSON, and JUnit reports with screenshots and videos on failure
- Code Quality: ESLint and Prettier for consistent code style
- CI/CD Ready: Configured for continuous integration pipelines
- Node.js (v18 or higher)
- npm or yarn
- Git
- Clone the repository:
git clone <repository-url>
cd slb-tests- Install dependencies:
npm install- Install Playwright browsers:
npx playwright install- Set up environment variables:
cp .env.example .envslb-tests/
βββ features/ # Cucumber feature files (BDD scenarios)
β βββ homepage-navigation.feature
β βββ content-verification.feature
β βββ search.feature # Search functionality tests
βββ src/
β βββ pages/ # Page Object Model classes
β β βββ BasePage.ts
β β βββ HomePage.ts
β β βββ ContactPage.ts
β βββ steps/ # Cucumber step definitions
β β βββ homepage-steps.ts
β β βββ content-steps.ts
β β βββ search-steps.ts # Search-related steps
β βββ support/ # Test support files
β β βββ browser.ts # Browser management
β β βββ hooks.ts # Cucumber hooks
β β βββ report-generator.js # Report generation
β βββ utils/ # Utility functions
β β βββ cookie-handler.ts # Cookie banner handling
β βββ config/ # Configuration files
β βββ config.ts
βββ reports/ # Test reports and artifacts
βββ cucumber.js # Cucumber configuration
βββ playwright.config.ts # Playwright configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json
npm testnpm run test:allnpm run test:headednpx cucumber-js features/homepage-navigation.featurenpx cucumber-js features/homepage-navigation.feature:10After running tests, reports are generated in the reports/ directory:
- HTML Report:
reports/index.html- Interactive HTML report with test results - JSON Report:
reports/cucumber-report.json- Machine-readable test results - JUnit Report:
reports/cucumber-report.xml- For CI/CD integration - Screenshots: Captured automatically on test failures
- Videos: Recorded for failed test scenarios
To generate the HTML report after tests:
npm run test:reportCreate a .env file from .env.example:
BASE_URL=https://www.slb.com
HEADLESS=true
SINGLE_SESSION=true # Run all scenarios in one browser session (default: true)Configuration Options:
BASE_URL: The base URL for the application under testHEADLESS: Run browser in headless mode (true) or headed mode (false)SINGLE_SESSION: Run all scenarios in single browser session (true) or create new browser per scenario (false)- Default:
true- Faster execution, lower resource usage - Set to
falsefor complete isolation between scenarios
- Default:
Performance Impact:
SINGLE_SESSION=true: ~50-60% faster execution timeSINGLE_SESSION=false: Complete scenario isolation, slower but ensures clean state
See SINGLE_SESSION_FEATURE.md for detailed documentation.
Modify playwright.config.ts to customize:
- Browsers (Chromium, Firefox, WebKit)
- Timeouts
- Screenshots and video settings
- Base URL
- Parallel execution
Modify cucumber.js to customize:
- Report formats
- Step definition paths
- Feature file locations
- Retry attempts
- Encapsulates page elements and actions
- Promotes code reusability and maintainability
- Reduces code duplication
- Human-readable test scenarios
- Collaboration between technical and non-technical stakeholders
- Living documentation
- Type safety and early error detection
- Better IDE support and autocomplete
- Improved code quality
- Page Objects: UI interactions
- Step Definitions: Test logic
- Feature Files: Test scenarios
- Support Files: Utilities and hooks
- Environment-based configuration
- Externalized test data
- Configurable base URLs
- Screenshots on failure
- Video recording for debugging
- Detailed error messages in reports
- ESLint for code linting
- Prettier for code formatting
- Consistent coding standards
- JUnit XML reports for integration
- Environment variable support
- Headless execution by default
- Automatic dismissal of OneTrust cookie consent on first page load
- Handled once in Before hook when browser starts
- No need for per-test cookie checks
- Cookies persist across entire test session
- Prevents test flakiness without performance overhead
- Step definitions focused on business logic
- No cookie handling code in tests
- Infrastructure concerns separated in hooks
- Easy to read and maintain
- β Homepage loads successfully
- β Main sections visibility verification
- β Navigation menu interactions
- β Contact page navigation
- β Hero section content validation
- β Company tagline verification
- β CTA button presence checks
- β Search panel opening
- β Search input field availability
- β Popular searches navigation
- β Search query execution
- β Results page validation
npm run lintnpm run lint:fixnpm run formatnpm run cleanCreate a new .feature file in the features/ directory:
Feature: Feature Name
As a user
I want to do something
So that I can achieve a goal
Scenario: Scenario name
Given I am on the homepage
When I click on a button
Then I should see the resultCreate a new page class in src/pages/:
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
export class MyPage extends BasePage {
private readonly myElement = '#element';
constructor(page: Page) {
super(page);
}
async clickElement(): Promise<void> {
await this.click(this.myElement);
}
}Create step definitions in src/steps/:
import { Given, When, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
import { MyPage } from '../pages/MyPage';
import { getPage } from '../support/browser';
let myPage: MyPage;
Given('I am on my page', async function () {
const page = getPage();
myPage = new MyPage(page);
await myPage.navigate();
});- Cookies are automatically accepted when browser first starts (Before hook)
- Check console logs for "β Initial page loaded and cookies accepted"
- If cookie banner persists, check
src/utils/cookie-handler.ts - Verify the OneTrust button selector is still valid
- Cookie acceptance happens once per session in single session mode
- Increase timeout in
playwright.config.ts - Check network connectivity
- Verify the website is accessible
- Reinstall browsers:
npx playwright install - Check system requirements
- Try running in headed mode:
npm run test:headed
- Run
npm installto ensure all dependencies are installed - Check
tsconfig.jsonconfiguration - Verify all imports are correct
Create .github/workflows/tests.yml:
name: Test Automation
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npx playwright install --with-deps
- run: npm run test:all
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-reports
path: reports/- TypeScript 5.9+: Type-safe test automation
- Playwright 1.57+: Cross-browser automation framework
- Cucumber 12.2+: BDD testing framework with Gherkin syntax
- Node.js 18+: JavaScript runtime
- ESLint: Code quality and style checking
- Prettier: Code formatting
- ts-node: TypeScript execution
- dotenv: Environment variable management
- multiple-cucumber-html-reporter: Rich HTML reports
- Cucumber JSON: Machine-readable test results
- JUnit XML: CI/CD integration format
- Page Object Model (POM): UI abstraction layer
- Behavior-Driven Development (BDD): Human-readable scenarios
- Separation of Concerns: Modular, maintainable codebase
- Configuration Management: Environment-based settings
- Robust Error Handling: Screenshots, HTML dumps, detailed logs
- Follow the existing code style
- Write meaningful test scenarios
- Update documentation as needed
- Run linting and formatting before committing
- Ensure all tests pass
ISC
Test Automation Team
Happy Testing! π