google-chromegoogle-chrome-extensioncucumberwebdriver-iowdio

WebDriver.IO configuration not loading any Chrome extensions?


I have a suite of UI tests built on WebDriver.IO and Cucumber JS, where I am attempting to load a Chrome extension before starting the test steps. I have tried both ways of loading an extension outlined in the Web Extension Testing docs provided by WDIO, but neither one has been successful so far.

Adding the load-extension argument to the list of args in goog:chromeOptions has not worked when passing in the folder containing the unpacked extension files like so:

const extensionPath = path.join(__dirname, '..', 'test');
// This resolves to /Users/<username>/<app>/test, which contains a .js file and manifest.json
...

capabilities: [{
    browserName: 'chrome'
    'goog:chromeOptions': {
      args: [`load-extension=${extensionPath}`]
      // I've tried this arg with and without adding -- as a prefix
    }
  }],

I have also tried injecting a bundled .crx file in the extensions array like below, which is also not working:

capabilities: [{
    browserName: 'chrome'
    'goog:chromeOptions': {
      args: [],
      extensions = [(await fs.readFile(`${extensionPath}.crx`)).toString('base64')];
    }
  }],

I'm curious if anyone has any tips or knows of other configuration settings that might affect this. I've tried modifying or disabling our other config settings to no success. The extension loads correctly when I manually install it in the browser, but when running through WDIO I get no feedback or error messages.

Thanks!

Edit: Checked logs on Haxor's recommendation below, I think they may show what the problem is. During the browser's initialization the logs show all the enabled flags like so:

2023-09-27T15:34:41.648Z INFO devtools: Launch Google Chrome (undefined) with flags: --enable-automation -—disable-popup-blocking --disable-extensions --disable-background-networking --disable-background-timer-throttling —-disable-backgrounding-occluded-windows -—disable-sync —-metrics-recording-only -—disable-default-apps —-mute-audio —-no-first-run --no-default-browser-check --disable-hang-monitor --disable-prompt-on-repost -—disable-client-side-phishing-detection —-password-store=basic -—use-mock-keychain --disable-component-extensions-with-background-pages -—disable-breakpad -—disable-dev-shm-usage —-disable-ipc-flooding-protection --disable-renderer-backgrounding --force-fieldtrials=*BackgroundTracing/default/ --enable-features=NetworkService,NetworkServiceInProcess —-disable-features=site-per-process, TranslateUI, BlinkGenPropertyTrees
--window-position=0,0 —-window-size=1200,900 —-window-size=1600,1200 --load-extension=/Users/<username>/<app>/test

Specifically it looks like --disable-extensions is being added somewhere in the process, even though I'm not manually setting it anywhere in my code.


Solution

  • Figured it out. The devtools service was using Puppeteer, which sets --disable-extensions as one of its default flags. The solution was to add a new section to the capability:

    capabilities: [{
        browserName: 'chrome'
        'goog:chromeOptions': {
          args: [`load-extension=${extensionPath}`]
        }
        'wdio:devtoolsOptions': {
          ignoreDefaultArgs: ['--disable-extensions']
        },
      }],
    

    which filters that flag out, allowing the extension to load. Discovered the setting in WDIO's config file documentation