【问题标题】:How do I get karma webdriver launcher to use my selenium server/grid如何让业力 webdriver 启动器使用我的 selenium 服务器/网格
【发布时间】: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


【解决方案1】:

我已经开始工作了。从我最初的帖子中必须解决两个问题。

第一个修复:在 karma.conf.js 文件中,我必须将主机名设置为运行 karma 的机器(即我的本地机器)的 IP 地址。不要将此设置为 selenium 服务器网格集线器的 IP 地址。

config.set({
...
hostname: '172.123.123.123',
...
})

第二次修复:我的 karma 项目 package.json 文件在 devDependencies 字典中缺少这一行。

"karma-webdriver-launcher": "~0.2.0",

所以 package.json 的内容看起来像:-

{
  "name": "MyKarmaProject",
  "devDependencies": {
    "karma": "~0.12.16",
    "karma-chrome-launcher": "~0.1.4",
    "karma-firefox-launcher": "~0.1.3",
    "karma-html-reporter": "^0.2.3",
    "karma-ie-launcher": "~0.1.5",
    "karma-webdriver-launcher": "~0.2.0",
    "karma-jasmine": "^0.2.2",
    "karma-phantomjs-launcher": "^0.1.4",
    "karma-typescript-preprocessor": "0.0.7",
    "phantomjs": "^1.9.7-12"
  }
}

我相信,如果您在 package.json 文件更新后从项目目录 cmd 提示符“npm install”运行,它将确保所有内容都已正确下载和安装。 完成此操作后,karma runner 能够连接到我的 selenium 网格服务器集线器并从池中请求适当的浏览器节点。我希望这个问题和答案在未来对其他人有所帮助!

【讨论】:

  • 那么你是如何告诉 karma 硒服务器在哪里的呢?
  • @MattSmith webdriverConfig 中的 hostname 是 selenium 服务器的位置。 karma 配置根目录中的hostname 是站点应该提供服务的位置,如果它正在运行您的测试服务器(Karma 运行),则可以是您的 IP 地址。如果您有运行测试的构建服务器,请不要在此处硬编码地址。让构建过程动态填充。
猜你喜欢
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 2016-06-14
  • 1970-01-01
  • 2018-05-08
  • 2014-09-15
  • 1970-01-01
相关资源
最近更新 更多