Webdriverio: 有没有办法在webdriverio中为chrome添加扩展?

创建于 2015-04-02  ·  4评论  ·  资料来源: webdriverio/webdriverio

实际上,我需要打开在任何浏览器(不是特别是 chrome)中安装了扩展程序的页面。 所以它可以是 firefox 或 phantomjs(根本不确定是否可能)。

那么,有什么方法可以通过带有预安装扩展的 webdriverio 运行 chrome/firefox/phantom,如果有 - 我该怎么做?

提前致谢!

最有用的评论

是的,这有效

var data = await fs.readFileSync('./ext.zip');
options.desiredCapabilities.chromeOptions.extensions = [data.toString('base64')];

所有4条评论

就在这里! 您可以在您所期望的能力中拥有chromeOptions属性。 该对象有一个名为extensions的属性,它采用crx文件的 base64 字符串。 您会找到更多信息https://sites.google.com/a/chromium.org/chromedriver/capabilities

是的,这有效

var data = await fs.readFileSync('./ext.zip');
options.desiredCapabilities.chromeOptions.extensions = [data.toString('base64')];

你好! 感谢您分享您的方法!
@ d668也许您在为测试添加扩展时遇到了一些类似的问题?
我试图添加一个扩展,在运行测试后,
我有一个错误:
ERROR webdriver: Request failed due to unknown error: unknown error: cannot process extension #1 from unknown error: cannot read manifest

 maxInstances: 5,
        "goog:chromeOptions": {
            extensions: [(function () {
                try {
                    const webExt = fs.readFileSync('./extension.zip').toString('base64');
                    return webExt;
                } catch (e) {
                    console.log(e, 'An error occurred while to parse extension zip file!');
                }
            })()],
            args: ['--headless', '--disable-gpu']
        },

@Madebyspeedster你需要打包扩展。 打开chrome://extensions ,然后单击 Pack extension。 它将生成 .crx 包和 .pem 密钥。 之后,您可以使用 .pem 密钥为您自己生成包。 您可以将这个库用于https://github.com/Constellation/crxmake

此页面是否有帮助?
0 / 5 - 0 等级