ui-omakase-framework
Version:
A comprehensive E2E testing framework library with pre-built Cucumber step definitions and utilities for web automation testing
368 lines (280 loc) โข 8.8 kB
Markdown
with Cucumber.js and Playwright. This library provides pre-built step definitions, utilities, and configuration management for web automation testing.
- **Pre-built Step Definitions**: Over 50+ ready-to-use Cucumber step definitions for common web interactions
- **Playwright Integration**: Built on Playwright for reliable cross-browser automation
- **Flexible Configuration**: Configurable environments, page mappings, and test data
- **Accessibility Testing**: Built-in accessibility testing with axe-core
- **Mock Support**: Comprehensive mocking capabilities for API testing
- **TypeScript Support**: Full TypeScript support with type definitions
- **Multi-browser Support**: Chrome, Firefox, Safari support out of the box
- **Parallel Execution**: Built-in support for parallel test execution
```bash
npm install @your-org/e2e-framework
```
Make sure you have the following peer dependencies installed:
```bash
npm install @cucumber/cucumber playwright
```
This version introduces cleaner, more intuitive import patterns:
```typescript
// Clean type imports
import type { GlobalConfig, ScenarioWorld } from 'ui-omakase-framework'
// Essential utilities
import { env, envNumber, setupUtils } from 'ui-omakase-framework'
// Specific support modules
import { waitFor, clickElement } from 'ui-omakase-framework/support/browser-behavior'
// Environment utilities with enhanced features
import { enhancedEnv, envBoolean } from 'ui-omakase-framework/env'
```
See [IMPORT_EXAMPLES.md](./IMPORT_EXAMPLES.md) for comprehensive usage examples.
Create a new project and install the framework:
```bash
mkdir my-e2e-tests
cd my-e2e-tests
npm init -y
npm install @your-org/e2e-framework @cucumber/cucumber playwright ts-node typescript
```
Create the following directory structure:
```
my-e2e-tests/
โโโ config/
โ โโโ hosts.json
โ โโโ pages.json
โ โโโ emails.json
โ โโโ errors.json
โ โโโ mocks.json
โ โโโ mappings/
โ โ โโโ common.json
โ โ โโโ home.json
โ โโโ json_payloads/
โ โโโ users.json
โโโ env/
โ โโโ common.env
โ โโโ localhost.env
โโโ src/
โ โโโ features/
โ โ โโโ example.feature
โ โโโ step-definitions/
โ โโโ custom-steps.ts (optional)
โโโ cucumber.js
โโโ package.json
```
**env/common.env**:
```bash
UI_AUTOMATION_BROWSER=chromium
HEADLESS=true
BROWSER_WIDTH=1920
BROWSER_HEIGHT=1080
PARALLEL=1
RETRY=0
HOSTS_URLS_PATH=/config/hosts.json
PAGE_URLS_PATH=/config/pages.json
```
**env/localhost.env**:
```bash
NODE_ENV=localhost
BASE_URL=http://localhost:3000
```
**config/hosts.json**:
```json
{
"localhost": "http://localhost:3000",
"staging": "https://staging.example.com",
"production": "https://example.com"
}
```
**config/pages.json**:
```json
{
"home": {
"route": "/",
"title": "Home Page"
},
"login": {
"route": "/login",
"title": "Login"
}
}
```
**config/mappings/common.json**:
```json
{
"login button": "button[data-testid='login-btn']",
"username field": "input[name='username']",
"password field": "input[name='password']",
"error message": ".error-message"
}
```
**cucumber.js**:
```javascript
const { createFrameworkConfig } = require('@your-org/e2e-framework');
// Initialize the framework configuration
const frameworkConfig = createFrameworkConfig({
configPath: './config',
envPath: './env/',
featuresPath: './src/features/**/*.feature',
customStepDefsPath: './src/step-definitions/**/*.ts'
});
module.exports = {
default: frameworkConfig.cucumberConfig.dev
};
```
**src/features/example.feature**:
```gherkin
@dev
Feature: Login functionality
Background:
Given I am on the "home" page
Scenario: Successful login
When I click the "login button"
And I fill the "username field" with "testuser"
And I fill the "password field" with "password123"
And I click the "login button"
Then I should be on the "dashboard" page
```
Add these scripts to your `package.json`:
```json
{
"scripts": {
"test": "NODE_ENV=localhost COMMON_CONFIG_FILE=env/common.env cucumber-js",
"test:dev": "NODE_ENV=localhost COMMON_CONFIG_FILE=env/common.env cucumber-js --tags @dev",
"test:smoke": "NODE_ENV=localhost COMMON_CONFIG_FILE=env/common.env cucumber-js --tags @smoke",
"test:headful": "HEADLESS=false npm run test"
}
}
```
The framework provides numerous pre-built step definitions:
- `Given I am on the "{page}" page`
- `When I navigate to the "{page}" page`
- `Then I should be on the "{page}" page`
- `When I click the "{element}" element`
- `When I fill the "{element}" with "{text}"`
- `When I select "{option}" from the "{element}" dropdown`
- `When I check the "{element}" checkbox`
- `Then I should see the "{element}" element`
- `Then I should not see the "{element}" element`
- `Then the "{element}" should contain "{text}"`
- `Then the "{element}" should be enabled`
- `When I wait "{seconds}" seconds`
- `When I wait for the "{element}" to be visible`
- `When I wait for the "{element}" to be hidden`
- `When I submit the form`
- `Then the "{element}" should have the value "{value}"`
Create custom step definitions in your project:
**src/step-definitions/custom-steps.ts**:
```typescript
import { Given, When, Then } from '@cucumber/cucumber';
import { ScenarioWorld } from '@your-org/e2e-framework';
Given('I perform a custom action', async function(this: ScenarioWorld) {
// Your custom logic here
const { page } = this.screen;
await page.locator('custom-selector').click();
});
```
```javascript
// cucumber.js
const { createFrameworkConfig } = require('@your-org/e2e-framework');
const environment = process.env.NODE_ENV || 'localhost';
const frameworkConfig = createFrameworkConfig({
configPath: `./config/${environment}`,
envPath: './env/',
environment: environment
});
module.exports = {
default: frameworkConfig.cucumberConfig[process.env.TEST_TYPE || 'dev']
};
```
**config/mocks.json**:
```json
{
"users_api": "http://localhost:8080/api/users",
"auth_api": "http://localhost:8080/api/auth"
}
```
**config/json_payloads/users.json**:
```json
{
"single_user": {
"id": 1,
"name": "Test User",
"email": "test@example.com"
}
}
```
```bash
npm test
npm run test:dev
npm run test:smoke
npm run test:headful
npx cucumber-js src/features/login.feature
npx cucumber-js --tags "@regression and not @skip"
```
Set browser via environment variables:
```bash
UI_AUTOMATION_BROWSER=chromium npm test
UI_AUTOMATION_BROWSER=firefox npm test
UI_AUTOMATION_BROWSER=webkit npm test
```
The framework generates detailed HTML reports in the `reports/` directory after test execution.
When developing the framework library itself:
```bash
git clone <repository>
cd e2e-framework
npm install
npm run build
npm test
```
ISC
For issues and questions:
- GitHub Issues: [Repository Issues](https://github.com/your-org/e2e-framework/issues)
- Documentation: [Framework Docs](https://github.com/your-org/e2e-framework#readme)
If you have an existing E2E project, follow these steps:
1. Install the framework: `npm install @your-org/e2e-framework`
2. Move your `config/` and `env/` directories to match the expected structure
3. Update your `cucumber.js` to use `createFrameworkConfig()`
4. Remove duplicate step definitions that are provided by the framework
5. Import the framework in your main test file or cucumber configuration
6. Update your package.json scripts to use the new configuration
The framework is designed to be backward-compatible with most existing Cucumber.js + Playwright setups.
A comprehensive, reusable E2E testing framework built