gpt4 book ai didi

javascript - 如何让 karma webdriver 启动器使用我的 selenium 服务器/网格

转载 作者:数据小太阳 更新时间:2023-10-29 05:07:47 25 4
gpt4 key购买 nike

任何人都可以帮助阐明阻止 Karma javascript 测试运行程序连接和使用我的 selenium 网格/服务器的原因吗?

我有一个成功运行的 selenium 网格环境,我已经将它与 python selenium 绑定(bind)一起用于 Web 应用程序系统测试。我目前正在运行 Selenium Server v.2.34.0,它连接了 4 个独立的网格 Node 。

我还想利用和重用此资源以针对多个浏览器进行 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 请求中失败了。我的 Node 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
});
};

最佳答案

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

第一个修复:在 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 网格服务器中心并从池中请求适当的浏览器 Node 。我希望这个问题和答案对以后的其他人有所帮助!

关于javascript - 如何让 karma webdriver 启动器使用我的 selenium 服务器/网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24691790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com