我正在使用Jasmine-3.3.1,并结合了ProtractorJS。
我的要求是存储每个规范的结果(或描述/测试),并使用afterEach()方法在Testrail系统中更新结果。我想将结果存储到变量“ testResult”中。
尝试了各种方法-custom_reports.js等,但无法获得我所需要的。
代码段:
var testResult;
describe('1st scenario', function () {
it('1st Test', function () {
expect(true).toBe(true);
testResult=5;
});
});
describe('2nd scenario', function () {
it('2nd Test', function () {
expect(true).toBe(true);
testResult=1;
});
});
afterEach(function () {
helper.updateResults("Section Name", testcaseID, testResult);
});
答案 0 :(得分:1)
我通过创建自己的自定义记者获得了类似的成就。我的报告者在每个规范完成后将规范结果(其块)上载到dynamoDB表中,并在所有测试完成后上传套件结果(描述块)。所有上传都是异步进行的,但是在onComplete中,所有异步上传操作都在等待中。
很明显,我使用的是异步/等待方法,而不是您看到的SELENIUM_PROMISE_MANAGER。我建议进行更改。
DBReporter.js
function dbReporter() {
this.jasmineStarted = function (options) {};
this.specStarted = function (result) {};
this.specDone = async function (result) {
if (result.status == 'pending') {
}
else if (result.status == 'passed') {
}
else if (result.status == 'failed') {
//Put your testrail interaction code here
}
testResultsUploadQueue.push(result);
};
this.suiteStarted = function (result) {};
this.suiteDone = function (result) {}
this.jasmineDone = async function (result) {}
}
module.exports = dbReporter;
conf.js
onPrepare: async () => {
//require the dpReporter file
let dbReporter = require('../src/functions/db-reporter');
//Declare a global variable that will contain all the asynchronous upload actions (promises)
global.testResultsUploadQueue = [];
//initialize the dbreporer
await jasmine.getEnv().addReporter(new dbReporter());
}),
onComplete: async() => {
//Wait for all uploads to resolve before completing
let testRulesUploadValue = await Promise.all(testResultsUploadQueue);
console.log(` ${testRulesUploadValue.length} result files uploaded to dynamoDB`);
}
规范文件中不需要更改
约束
了解钩子的执行顺序以了解解决方案很重要。
--- beforeLaunch
--- onPrepare
--- jasmineStarted (set in jasmine reporter)
--- beforeAll
--- suiteStarted (set in jasmine reporter)
--- specStarted (set in jasmine reporter)
--- beforeEach
+++ afterEach
+++ specDone (set in jasmine reporter)
+++ suiteDone (set in jasmine reporter)
+++ afterAll
+++ jasmineDone (set in jasmine reporter)
+++ onComplete
+++ afterLaunch