【发布时间】:2014-09-01 17:28:57
【问题描述】:
谁能帮助阐明是什么阻止了 Karma javascript 测试运行程序连接和使用我的 selenium 网格/服务器?
我有一个成功运行的 selenium 网格环境,我已经将它与 python selenium 绑定一起用于 Web 应用程序系统测试。我目前正在运行 Selenium Server v.2.34.0,它有 4 个独立的网格节点连接到它。
我还想利用和重用这个资源来针对多个浏览器进行 javascript 测试。具体来说,我正在使用基于 node.js 的 Karma 测试运行器执行基于 jasmine 的单元测试。我已经安装了“karma-webdriver-launcher”插件。我可以使用 karma 在本地生成 firefox、chrome 或 IE 浏览器来运行我的 javascript 测试。
当我尝试使用远程 selenium 服务器使用池/场中的浏览器时,它无法找到浏览器并且我收到以下警告输出:
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from C:\nodedebug\itpt\node_modules
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-html-reporter.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-ie-launcher.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-typescript-preprocessor.
DEBUG [plugin]: Loading plugin C:\nodedebug\itpt\node_modules/karma-webdriver-launcher.
DEBUG [plugin]: Loading inlined plugin (defining launcher:firefox).
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser firefox via Remote WebDriver
WARN [launcher]: firefox via Remote WebDriver have not captured in 60000 ms, killing.
Killed Karma test.
当我运行时调试 karma-webdriver-launcher 时,它似乎在 wd 请求中失败。不过,我的节点 JavaScript 技能仅处于初学者水平,因此我可能会遗漏一些明显的东西。不过,所有配置细节似乎都正确传递了,用于连接到 selenium 服务器的 url 对我来说看起来是正确的。
在第 33 行的 karma-webdriver-launcher\node_modules\wd\lib\webdriver.js 调用中失败,
this._request(httpOpts, function(err, res, data) {
这是我的 karma.config.js 文件:-
// Karma configuration
module.exports = function (config) {
var webdriverConfig = {
hostname: '172.17.126.52',
port: 9625
}
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'Scripts/Libs/JsResources.js',
// watch every ts file
'Scripts/Local/**/*.ts'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.ts': ['typescript']
},
typescriptPreprocessor: {
// options passed to the typescript compiler
options: {
target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
}
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots', 'html'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
customLaunchers: {
'firefox': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'firefox',
}
},
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
【问题讨论】:
-
您是否已配置为使用您的网格/节点?如错误消息中所示,本地 webdriver 启动与您的脚本向远程服务器发送请求
-
@NguyenVuHoang 我不确定你的意思。我的 selenium 网格集线器肯定在我配置 Karma 以在 172.17.126.52 上查找它的机器上运行。 “本地网络驱动程序启动与您的脚本向远程服务器发送请求”是什么意思?在我上面的日志中,只有一个远程驱动程序正在尝试启动(并且失败)。没有使用本地驱动程序(也不应该使用)。我的 selenium 网格 hud 和节点在使用它的其他非基于业力的测试中运行良好。我只是无法使用它。
标签: javascript node.js selenium karma-runner selenium-grid