是否有可能增加一个插件下量角器测试chromedriver? [英] Is it possible to add a plugin to chromedriver under a protractor test?
问题描述
我一直想我量角器测试过程中处理基本身份验证。它的一些困难时期,所以我已经找到了一个镀铬插件至极自动发送我的凭据为需要基本身份验证的网站。
I've been trying to handle the basic authentication during my protractor test. Some hard time on it, so i've found a chrome plugin wich sends automatically my credentials for websites that require basic authentication.
由于每次执行的chromedriver,新的配置文件被加载时,我怎么能permanelty一个插件添加到我的测试?我知道有 https://sites.google.com/a/chromium。组织/ chromedriver /扩展程序,但我不认为这是很清楚。
As each time that chromedriver is executed, a new profile is loaded, how can i permanelty add a plugin to my tests? I know that there is https://sites.google.com/a/chromium.org/chromedriver/extensions, but i dont think this very clear.
推荐答案
您需要配置扩展
在<列表href=\"https://github.com/angular/protractor/blob/f56d850bafb25bbc9851709fab1d892ea59d11f0/docs/browser-setup.md#adding-chrome-specific-options\"相对=nofollow> chromeOptions
:
You need to configure extensions
list inside chromeOptions
:
capabilities {
'browserName': 'chrome',
'chromeOptions': {
'extensions': ['base64 encoded extension']
}
}
请注意,它在扩展
,它提供了一个<一个很重要href=\"https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-List-of-recognized-capabilities\"相对=nofollow>基带64 codeD的包装清单Chrome扩展。
Note that it in extensions
, it is important to provide a list of base-64 encoded packed Chrome extension.
要获得的的base64 EN codeD延长的,你需要阅读 .ctx
扩展文件和连接code中的与的base64内容
。例如,使用python:
To get a base64 encoded extension, you need to read the .ctx
extension file and encode the contents with base64
. For example, using python:
>>> import base64
>>> data = open('path_to_the_ctx_extension').read()
>>> base64.standard_b64encode(data).decode('UTF-8')
# outputs the encoded chrome extension which you can paste in the config
或者,更方便,用做 helper.js
文件 FS
和①
:
Or, easier, make a helper.js
file using fs
and q
:
var q = require('q');
var fs = require('fs');
exports.getCapabilities = function (filename) {
var deferred = q.defer();
fs.readFile(filename, function (err, data) {
var capabilities = {
'browserName': 'chrome',
'chromeOptions': {
extensions: [
data.toString('base64')
]
}
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
然后,在你的量角器配置,使用的getCapabilities()
函数获得的功能:
var helper = require('./helper.js');
exports.config = {
capabilities: helper.getCapabilities('/path/to/crx/extension'),
...
}
目前,它的工作原理与单个延伸,所以有改善的余地。
Currently, it works with a single extension, so there is a room for improvement.
另外,期待通过下面的问题,如果你有问题:
Also, look through the following issue in case you have problems:
- Setting Chrome Options
这篇关于是否有可能增加一个插件下量角器测试chromedriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!