UNPKG

ui-omakase-framework

Version:

A comprehensive E2E testing framework library with pre-built Cucumber step definitions and utilities for web automation testing

140 lines (132 loc) 4.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCustomWorld = createCustomWorld; exports.registerStepDefinitions = registerStepDefinitions; exports.setupUtils = void 0; exports.setupWorld = setupWorld; var _playwright = require("playwright"); var _parseEnv = require("./env/parseEnv"); /** * Setup utilities for the E2E framework * These functions can be called by consumers to register components with their Cucumber instance */ // Export the ScenarioWorld interface for consumers to use /** * Creates a custom world class that consumers can use */ function createCustomWorld(WorldConstructor, globalConfig) { return class CustomWorld extends WorldConstructor { constructor(options) { super(options); this.globalVariables = {}; // Merge provided config with default config this.globalConfig = { pageElementMappings: {}, mockPayloadMappings: {}, hostsConfig: {}, pagesConfig: {}, errorsConfig: [], emailsConfig: {}, mocksConfig: {}, ...globalConfig, ...(options.parameters || {}) }; } async init() { const browserType = (0, _parseEnv.env)('UI_AUTOMATION_BROWSER') || 'chromium'; const headless = (0, _parseEnv.env)('HEADLESS') === 'true'; let browser; switch (browserType) { case 'firefox': browser = await _playwright.firefox.launch({ headless }); break; case 'webkit': browser = await _playwright.webkit.launch({ headless }); break; default: browser = await _playwright.chromium.launch({ headless }); } const context = await browser.newContext({ viewport: { width: (0, _parseEnv.envNumber)('BROWSER_WIDTH') || 1920, height: (0, _parseEnv.envNumber)('BROWSER_HEIGHT') || 1080 } }); const page = await context.newPage(); this.screen = { browser, context, page }; } }; } /** * Simple utility functions that can be used inline */ const setupUtils = exports.setupUtils = { /** * Get viewport configuration from environment */ getViewPort() { return { width: (0, _parseEnv.envNumber)('BROWSER_WIDTH') || 1920, height: (0, _parseEnv.envNumber)('BROWSER_HEIGHT') || 1080 }; }, /** * Environment utilities */ env: key => (0, _parseEnv.env)(key), envNumber: key => (0, _parseEnv.envNumber)(key), /** * Browser setup utility */ async setupBrowser(browserType = 'chromium', headless = true) { switch (browserType) { case 'firefox': return await _playwright.firefox.launch({ headless }); case 'webkit': return await _playwright.webkit.launch({ headless }); default: return await _playwright.chromium.launch({ headless }); } } }; /** * Function to set up the world constructor with the consumer's Cucumber instance */ function setupWorld(cucumber, globalConfig) { const { setWorldConstructor, World } = cucumber; const CustomWorld = createCustomWorld(World, globalConfig); setWorldConstructor(CustomWorld); return CustomWorld; } /** * Function to register all step definitions with the consumer's Cucumber instance * This approach avoids Cucumber instance conflicts */ function registerStepDefinitions(cucumber) { // Pass the cucumber instance to each step definition module // This way they use the consumer's Cucumber instance, not ours const stepDefModules = ['./step-definitions/accessibility', './step-definitions/alerts', './step-definitions/check', './step-definitions/click', './step-definitions/form', './step-definitions/general', './step-definitions/iframe', './step-definitions/mock', './step-definitions/navigation', './step-definitions/page', './step-definitions/scoll', './step-definitions/stored', './step-definitions/assertions/verify-element-checked', './step-definitions/assertions/verify-element-value', './step-definitions/assertions/verify-element-visibility', './step-definitions/assertions/verify-iframe', './step-definitions/assertions/verify-new-page', './step-definitions/assertions/verify-stored-value', './step-definitions/assertions/verify-table-value', './step-definitions/setup/hooks']; // For now, return the module paths so consumers can require them return stepDefModules.map(modulePath => require(modulePath)); }