Skip to content

fleetframework/demo-slb-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SLB Website Test Automation Framework

A professional test automation framework for SLB website testing using TypeScript, Cucumber (BDD), and Playwright.

🎯 Features

  • 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

πŸ“‹ Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn
  • Git

πŸš€ Getting Started

Installation

  1. Clone the repository:
git clone <repository-url>
cd slb-tests
  1. Install dependencies:
npm install
  1. Install Playwright browsers:
npx playwright install
  1. Set up environment variables:
cp .env.example .env

πŸ“ Project Structure

slb-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

πŸ§ͺ Running Tests

Run all tests:

npm test

Run tests with HTML report:

npm run test:all

Run tests in headed mode (visible browser):

npm run test:headed

Run specific feature:

npx cucumber-js features/homepage-navigation.feature

Run specific scenario by line:

npx cucumber-js features/homepage-navigation.feature:10

πŸ“Š Reports

After 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:report

πŸ”§ Configuration

Environment Variables

Create 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 test
  • HEADLESS: 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 false for complete isolation between scenarios

Performance Impact:

  • SINGLE_SESSION=true: ~50-60% faster execution time
  • SINGLE_SESSION=false: Complete scenario isolation, slower but ensures clean state

See SINGLE_SESSION_FEATURE.md for detailed documentation.

Playwright Configuration

Modify playwright.config.ts to customize:

  • Browsers (Chromium, Firefox, WebKit)
  • Timeouts
  • Screenshots and video settings
  • Base URL
  • Parallel execution

Cucumber Configuration

Modify cucumber.js to customize:

  • Report formats
  • Step definition paths
  • Feature file locations
  • Retry attempts

πŸ—οΈ Best Practices Implemented

1. Page Object Model (POM)

  • Encapsulates page elements and actions
  • Promotes code reusability and maintainability
  • Reduces code duplication

2. BDD with Cucumber

  • Human-readable test scenarios
  • Collaboration between technical and non-technical stakeholders
  • Living documentation

3. TypeScript

  • Type safety and early error detection
  • Better IDE support and autocomplete
  • Improved code quality

4. Separation of Concerns

  • Page Objects: UI interactions
  • Step Definitions: Test logic
  • Feature Files: Test scenarios
  • Support Files: Utilities and hooks

5. Test Data Management

  • Environment-based configuration
  • Externalized test data
  • Configurable base URLs

6. Error Handling

  • Screenshots on failure
  • Video recording for debugging
  • Detailed error messages in reports

7. Code Quality

  • ESLint for code linting
  • Prettier for code formatting
  • Consistent coding standards

8. CI/CD Ready

  • JUnit XML reports for integration
  • Environment variable support
  • Headless execution by default

9. Simplified Cookie Banner Handling

  • 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

10. Clean Test Code

  • Step definitions focused on business logic
  • No cookie handling code in tests
  • Infrastructure concerns separated in hooks
  • Easy to read and maintain

🎯 Implemented Test Scenarios

Homepage Navigation

  • βœ… Homepage loads successfully
  • βœ… Main sections visibility verification
  • βœ… Navigation menu interactions
  • βœ… Contact page navigation

Content Verification

  • βœ… Hero section content validation
  • βœ… Company tagline verification
  • βœ… CTA button presence checks

Search Functionality

  • βœ… Search panel opening
  • βœ… Search input field availability
  • βœ… Popular searches navigation
  • βœ… Search query execution
  • βœ… Results page validation

🧹 Code Quality

Lint code:

npm run lint

Fix linting issues:

npm run lint:fix

Format code:

npm run format

Clean reports:

npm run clean

πŸ“ Writing Tests

1. Create a Feature File

Create 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 result

2. Create a Page Object

Create 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);
  }
}

3. Create Step Definitions

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();
});

πŸ› Troubleshooting

Tests failing with cookie banner visible

  • 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

Tests failing with timeout errors

  • Increase timeout in playwright.config.ts
  • Check network connectivity
  • Verify the website is accessible

Browser not launching

  • Reinstall browsers: npx playwright install
  • Check system requirements
  • Try running in headed mode: npm run test:headed

TypeScript compilation errors

  • Run npm install to ensure all dependencies are installed
  • Check tsconfig.json configuration
  • Verify all imports are correct

πŸ”„ CI/CD Integration

GitHub Actions Example

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/

πŸ“š Additional Resources

πŸ› οΈ Tech Stack

Core Technologies

  • 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

Development Tools

  • ESLint: Code quality and style checking
  • Prettier: Code formatting
  • ts-node: TypeScript execution
  • dotenv: Environment variable management

Reporting

  • multiple-cucumber-html-reporter: Rich HTML reports
  • Cucumber JSON: Machine-readable test results
  • JUnit XML: CI/CD integration format

Architecture Patterns

  • 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

🀝 Contributing

  1. Follow the existing code style
  2. Write meaningful test scenarios
  3. Update documentation as needed
  4. Run linting and formatting before committing
  5. Ensure all tests pass

πŸ“„ License

ISC

πŸ‘₯ Authors

Test Automation Team


Happy Testing! πŸš€

About

AI-generated demo test suite for main SLB web page

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published