// Jest setup file for LOCAL Selenium tests (browser runs on host) const { Builder } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); // Global test configuration for local testing global.testConfig = { baseUrl: process.env.BASE_URL || 'http://localhost:5173', seleniumHub: null, // Direct connection, no hub timeout: 30000, isHeadless: process.env.HEADLESS === 'true' }; // Create driver directly without Selenium Grid global.createDriver = async () => { const chromeOptions = new chrome.Options(); if (global.testConfig.isHeadless) { chromeOptions.addArguments('--headless'); } chromeOptions.addArguments('--no-sandbox'); chromeOptions.addArguments('--disable-dev-shm-usage'); chromeOptions.addArguments('--disable-gpu'); chromeOptions.addArguments('--window-size=1920,1080'); // Direct connection to Chrome on host const driver = await new Builder() .forBrowser('chrome') .setChromeOptions(chromeOptions) .build(); // Set implicit wait await driver.manage().setTimeouts({ implicit: 1000 }); return driver; }; // Global cleanup function global.quitDriver = async (driver) => { if (driver) { await driver.quit(); } }; // Extend Jest matchers for better assertions expect.extend({ async toBeDisplayed(element) { const isDisplayed = await element.isDisplayed(); return { message: () => `expected element to ${this.isNot ? 'not ' : ''}be displayed`, pass: isDisplayed }; }, async toHaveText(element, expectedText) { const actualText = await element.getText(); const pass = actualText.includes(expectedText); return { message: () => `expected element to contain text "${expectedText}", but got "${actualText}"`, pass }; } });