Jasmine 茉莉花得到了最新的测试结果

Jasmine 茉莉花得到了最新的测试结果,jasmine,protractor,Jasmine,Protractor,我使用的是Jasmine-3.3.1,并结合了量角器JS 我的要求是存储每个规范(或描述/测试)的结果,并使用afterEach()方法在Testrail系统中更新结果。我想将结果存储到变量“testResult”中 尝试了各种方法-custom_reports.js等,但无法得到我需要的 代码段: var testResult; describe('1st scenario', function () { it('1st Test', function () { e

我使用的是Jasmine-3.3.1,并结合了量角器JS

我的要求是存储每个规范(或描述/测试)的结果,并使用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);
});

我通过创建自己的定制reporter实现了类似的功能。我的reporter在每个规范完成后将规范结果(it块)上传到dynamoDB表,并在所有测试完成后上传套件结果(描述块)。所有上载都是异步进行的,但在onComplete中,所有异步上载操作都将等待

很明显,我使用的是异步/等待方法,而不是您看起来使用的SELENIUM\u PROMISE\u管理器。我建议把这个改变改一下

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;
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`);
}
conf.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;
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`);
}
不需要对规范文件进行任何更改

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;
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`);
}
约束条件

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;
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`);
}
  • 我与reporter处理异步操作时遇到很多问题,这就是我选择使用队列方法的原因。我不知道如何绕过这个问题,但这种方法确实有效
  • 您的TestRail操作必须返回一个承诺
  • 理解钩子的执行顺序对于理解解决方案非常重要

    --- 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
    

    谢谢你花时间给我详细的答复,这对我帮助很大。没问题,我花了一个星期的时间想知道如何让它表现出我所需要的样子。它非常高兴地接受了这些信息,说“帮助了我”低估了你的帮助——你把我从许多挣扎和挫折中拯救了出来。这是分配给我的一项任务,以展示我的能力,否则这些软件公司会给我很差的评价(很抱歉这么说,但这是现实——我们无法逃避现实)。谢谢你无价的帮助!很高兴听到这个消息,当我可以的时候总是很乐意帮忙:)祝你的项目好运