Onprepare with jasmine reporters在使用IE执行时导致失败
在花了一段时间试图找出为什么我的测试一开始就失败了(仅适用于IE,chrome可以正常工作)之后,我发现这是由on prepare函数在代码的这一部分导致的:Onprepare with jasmine reporters在使用IE执行时导致失败,jasmine,protractor,Jasmine,Protractor,在花了一段时间试图找出为什么我的测试一开始就失败了(仅适用于IE,chrome可以正常工作)之后,我发现这是由on prepare函数在代码的这一部分导致的: jasmine.getEnv().addReporter({ specDone: function (result) { browser.getCapabilities().then(function (caps) { var browserName = caps.get('brows
jasmine.getEnv().addReporter({
specDone: function (result) {
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
});
如果我评论这一部分,测试将顺利进行。
我的登录页面没有角度,所以我关闭了登录的同步,然后再次打开,不确定这是否相关
在继续运行之前,如何强制量角器等待此部分完成
我已经尝试在promise(conf文件)中添加此代码以使量角器等待,但即使这样,我也得到了jasmine timeout“TimeoutError:wait timed out after 20000ms”,因此我相信我做得不对
我得到的错误是:
Failed: Unable to determine type from: E. Last 1 characters read: E
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxxxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.2'
Driver info: driver.version: unknown
完整配置文件:
var jasmineReporters = require('./lib/node_modules/jasmine-reporters');
var HTMLReport = require('./lib/node_modules/protractor-html-reporter-2');
var mkdirp = require('./lib/node_modules/mkdirp');
var fs = require('./lib/node_modules/fs-extra');
let date = require('./lib/node_modules/date-and-time');
var environmentToExecute = 'https://myportal'
exports.config = {
seleniumAddress: 'http://'+process.env.AUTOTEST_ADDRESS+'/wd/hub',
framework: 'jasmine2',
specs: ['all my specs'],
suites: {
//All my suites
},
allScriptsTimeout: 20000,
onPrepare: function () {
{
//Here I create the folders (removed to make it shorter)
}
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './execution_results/reports/xml/',
filePrefix: 'xmlresults'
}));
jasmine.getEnv().addReporter({
specDone: function (result) {
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
});
},
//HTMLReport called once tests are finished
onComplete: function()
{
//I removed this to make it shorter, but basically it is the function
// that comverts the xml in html and build the report
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
// If true, display spec names.
isVerbose: true,
defaultTimeoutInterval: 100000
},
params: {
//Other files like functions and so on...
},
login:{
//parameters to login
}
},
multiCapabilities:
[
{
'browserName': 'internet explorer',
'version': 11,
},
/*
//chrome, firefox...
*/
],
};//end of Conf.js
谢谢 最近,我在一个Jasmine reporter中也遇到了异步操作的问题,不幸的是,我不知道如何让他们在继续之前正确地等待承诺结果。如果其他人有这方面的信息,我也将非常感谢 我确实实现了一个使用全局变量和AfterAll钩子的工作,它能够正确地等待可能对您有用的承诺。 我假设您只需要结果的“fullname”属性,这样您就可以尝试这个 在onPrepare中声明全局属性,可以在reporter中为该全局变量赋值。在specStarted中为其指定spec fullname值,而不是specDone。然后,您可以在测试中创建屏幕截图,所有语句都可以正确地等待承诺结果
onPrepare: function () {
global.currentlyExecutingSpec = 'tbd';
jasmine.getEnv().addReporter({
specStarted: function (result) {
currentlyExecutingSpec = result.fullName
}
})
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './execution_results/reports/xml/',
filePrefix: 'xmlresults'
}));
}
在您的测试文件中
afterEach(function(){
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream =
fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + currentlyExecutingSpec + '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
};
});
你好非常感谢你。。这成功了!只是不得不从AfterAll改为afterEach,以便每个“It”都有一个屏幕截图,谢谢你的帮助