茉莉花获得当前测试结果

茉莉花获得当前测试结果

问题描述:

我正在使用Jasmine-3.3.1,并结合了ProtractorJS.

I am using Jasmine - 3.3.1, with combination of ProtractorJS.

我的要求是存储每个规范的结果(或描述/测试),并使用afterEach()方法在Testrail系统中更新结果.我想将结果存储到变量"testResult"中.

My requirement is to store the result for each spec (or describe / test) and update results in Testrail system using the afterEach() method. I want to store the results into the variable "testResult".

尝试了各种方法-custom_reports.js等,但无法获得我所需要的.

Tried with various methods - custom_reports.js etc, but could not get what I needed.

代码段:

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);
});

我通过创建自己的自定义报告程序获得了类似的效果.我的报告者在每个规范完成后将规范结果(其块)上载到dynamoDB表中,并在所有测试完成后上传套件结果(描述块).所有上传都是异步进行的,但是在onComplete中,所有异步上传操作都在等待中.

I achieved something similar by creating my own custom reporter. My reporter uploads spec results (it blocks) to a dynamoDB table after each spec finishes and uploads suite results (describe blocks) after all tests have finished. All uploads occur asynchronously but in the onComplete all of the async upload actions are awaited.

很显然,我使用的是异步/等待方法,而不是您看到的SELENIUM_PROMISE_MANAGER.我建议进行更改.

Obviously I am using the async / await approach as opposed to the SELENIUM_PROMISE_MANAGER you appear to. I would recommend making that change over.

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`);
}

规范文件中不需要更改

约束

  1. 我在处理与记者的异步操作时遇到很多问题,这就是为什么我选择使用队列方法.我不知道如何解决这个问题,但是这种方法确实有效.
  2. 您的TestRail操作必须返回一个诺言

了解钩子的执行顺序以了解解决方案很重要.

It is important to understand the execution order of the hooks in order to understand the solution.

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