Selenium ChromeDriver,无法在加载了扩展程序的情况下启动Google Chrome [英] Selenium ChromeDriver, cannot start Google Chrome with Extension loaded

查看:122
本文介绍了Selenium ChromeDriver,无法在加载了扩展程序的情况下启动Google Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium 2.0通过以下方式为我的Google Chrome扩展程序创建自动化测试:

I am working on creating automated tests for my Google Chrome Extension using Selenium 2.0 with:

  1. WebdriverJS + NodeJS
  2. ChromeDriver
  3. MacOSX 10.8.4
  1. WebdriverJS + NodeJS
  2. ChromeDriver
  3. MacOSX 10.8.4

首先,我也想测试安装过程,但是当使用Selenium弹出安装对话框时,似乎无法单击添加"按钮. (关于此的其他问题).

First, I wanted to test the installation process as well, but it doesn't seem possible to click the "Add" button when the installation dialog pops up using Selenium. (My other SO question about this).

现在,我改变了计划.我不想将扩展程序作为测试驱动器的一部分进行安装,而是要在安装扩展程序的情况下启动Chrome.但是我没有成功.

Now, I changed my plan. Instead of installing the extension as part of the test drive, I want to start Chrome with my extension installed. But I have not been successful.

请查看以下代码:

var webdriver = require('selenium-webdriver'),
    chrome = require('selenium-webdriver/chrome');

var o = new chrome.Options();
o.addExtensions(['extensions/chrome/chrome_extension.zip']); // crx file is just a zip file
var s = new chrome.ServiceBuilder('bin/chromedriver').build();
var driver = chrome.createDriver(o, s)

运行上面的代码时,出现以下错误:

When I run the code above, I get the following error:

我注意到,ChromeDriver在打开Chrome时会加载名为"Chrome Automation Extension 1"的Chrome扩展程序,因此,必须有一种方法来加载另一个扩展程序,或者直接从网上商店使用应用ID加载它,或者加载从本地计算机-包装或未包装.

I've noticed that ChromeDriver loads a Chrome Extension called "Chrome Automation Extension 1" when it opens Chrome, so there must be a way to load another extension, either load it straight from the Webstore with the app ID, or load from local machine - packed or unpacked.

任何帮助将不胜感激!

推荐答案

请确保"manifest.json"位于zip文件的根目录中.意外压缩扩展目录而不是扩展文件是一个常见错误.

Make sure that "manifest.json" is at the root of your zip file. It's a common error to accidentally zip the extension's directory instead of the extension files.

使用 zip :

cd path/to/extension
zip -ur ../chrome_extension.zip *

使用 7-zip :

cd path/to/extension
7z u -tzip ../chrome-extension.zip *

这篇关于Selenium ChromeDriver,无法在加载了扩展程序的情况下启动Google Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆