Powered By Blogger

Search Here!

Tuesday, September 3, 2024

WebdriverIO Chrome Browser Capabilities For Windows & Linux Environment

wdio.conf.js
// Set the path to the Chromedriver executable based on the
operating system
const isWindows = os.platform() === "win32";
const chromedriverPath = isWindows
    ? "./driver/win/chromedriver.exe" // Path for Chromedriver
on Windows
    : "./driver/linux/chromedriver"; // Path for Chromedriver
on Linux

// Set the path to the Chrome binary based on the operating system
const chromeBinaryPath =
    os.platform() === "win32"
        ? "C:\\Program Files\\Google\\Chrome\\Application
        \\chrome.exe" // Path for Chrome on Windows
        : "/usr/bin/google-chrome"; // Default path for Chrome
on Linux

capabilities: [
        {
            //maxInstances can get overwritten per capability.
So if you have an in-house Selenium
            // grid with only 5 firefox instances available
you can make sure that not more than
            // 5 instances get started at a time.
            browserName: CONSTANT.CONFIG_SETTING.CHROME_BROWSER_NAME,
            acceptInsecureCerts: true,
            "goog:chromeOptions": {
                binary: chromeBinaryPath, // Set the Chrome
                binary path dynamically
                prefs: {
                    credentials_enable_service: false,
                    profile: {
                        password_manager_enabled: false,
                    },
                    w3c: true,
                    download: {
                        default_directory: path.join(process.cwd(),
                        "downloads"),
                        prompt_for_download: false,
                        directory_upgrade: true,
                        "safebrowsing.enabled": false,
                    },
                },
                args: [
                    ...(process.env.HEADLESS === "true"
                        ? ["--headless", "--disable-gpu",
                        "--window-size=1920,1080"]
                        // Configurations for headless mode
                        : []), // No additional args for
                        non-headless mode
                    "--disable-cache",
                    "--no-sandbox",
                    "--disable-dev-shm-usage",
                    "--disable-application-cache",
                    "--disable-offline-load-stale-cache",
                    "--disk-cache-size=0",
                    "--v8-cache-options=off",
                    "--disable-infobars",
                    "--kiosk-printing",
                ].filter(Boolean), // Filter out any empty strings
            },

    ], 

No comments:

Post a Comment