Evo*_*olk 6 javascript selenium selenium-grid node.js karma-runner
任何人都可以帮助解决阻止Karma javascript测试运行器连接和使用我的selenium网格/服务器的问题?
我有一个成功运行的selenium网格环境,我已经使用python selenium绑定进行Web应用程序系统测试.我目前正在运行Selenium Server v.2.34.0,它有4个独立的网格节点连接到它.
我还想利用和重用这个资源来针对多个浏览器进行javascript测试.具体来说,我正在使用基于node.js的Karma测试运行器执行基于jasmine的单元测试.我已经安装了" karma-webdriver-launcher "插件.我可以运行我的javascript测试与karma本地产生firefox,chrome或IE浏览器就好了.
当我尝试使用远程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.
Run Code Online (Sandbox Code Playgroud)
当我运行时调试karma-webdriver-launcher单步执行它时,它似乎在wd请求中失败.我的节点javascript技能只是在初学者水平,所以我可能会遗漏一些明显的东西.所有的配置细节似乎都被正确传递,并且用于连接到selenium服务器的url看起来对我来说是正确的.
它在第33行的karma-webdriver-launcher \node_modules\wd\lib\webdriver.js调用中失败,
this._request(httpOpts, function(err, res, data) {
Run Code Online (Sandbox Code Playgroud)
这是我的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
});
};
Run Code Online (Sandbox Code Playgroud)
Evo*_*olk 10
我有它的工作.我的初始帖子必须修复两个问题.
第一个修复:在karma.conf.js文件中,我必须将主机名设置为运行karma的机器的IP地址(即我的本地机器).不要将其设置为selenium服务器网格集线器的IP地址.
config.set({
...
hostname: '172.123.123.123',
...
})
Run Code Online (Sandbox Code Playgroud)
第二个修复:我的karma项目package.json文件在devDependencies字典中缺少此行.
"karma-webdriver-launcher": "~0.2.0",
Run Code Online (Sandbox Code Playgroud)
所以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"
}
}
Run Code Online (Sandbox Code Playgroud)
我相信如果你在更新package.json文件后从你的项目目录cmd提示符"npm install"运行它将确保所有内容都被正确下载和安装.完成此操作后,karma运行器能够连接到我的selenium网格服务器中心并从池中请求相应的浏览器节点.我希望这个问题和答案将来可以帮助别人!
| 归档时间: |
|
| 查看次数: |
9850 次 |
| 最近记录: |