IO配置没有加载任何Chrome扩展?

blpfk2vs  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(106)

我有一套基于WebDriver.IO和CucumberJS的UI测试,我试图在开始测试步骤之前加载一个Chrome扩展。我尝试了Web Extension Testing docs provided by WDIO中概述的两种加载扩展的方法,但到目前为止都没有成功。
当传入包含解压缩的扩展文件的文件夹时,将load-extension参数添加到goog:chromeOptions中的参数列表中不起作用,如下所示:

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
    }
  }],

我还尝试在extensions数组中注入一个捆绑的.crx文件,如下所示,这也不起作用:

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

我很好奇,如果有人有任何提示或知道其他配置设置,可能会影响这一点。我已经尝试修改或禁用我们的其他配置设置没有成功。当我在浏览器中手动安装扩展时,它可以正确加载,但是当通过WDIO运行时,我没有得到任何反馈或错误消息。
谢谢你,谢谢
编辑:检查下面的Haxor建议的日志,我认为它们可能会显示问题所在。在浏览器初始化期间,日志显示所有启用的标志,如下所示:

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

具体来说,它看起来像是在过程中的某个地方添加了--disable-extensions,尽管我没有在代码中的任何地方手动设置它。

z2acfund

z2acfund1#

想明白了devtools服务使用Puppeteer,它将--disable-extensions设置为默认标志之一。解决方案是在功能中添加一个新的部分:

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

过滤掉该标记,允许加载扩展。发现WDIO's config file documentation中的设置

相关问题