当使用 'shardTestFiles' 共享测试时,protractor-jasmine2-html-reporter 不会合并所有测试的结果:conf 文件中的 true [英] protractor-jasmine2-html-reporter doesn't consolidate results for all test when tests are shared using 'shardTestFiles': true in conf file

查看:12
本文介绍了当使用 'shardTestFiles' 共享测试时,protractor-jasmine2-html-reporter 不会合并所有测试的结果:conf 文件中的 true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我们已将 e2e 测试配置为在 Jenkins 和很快我们意识到我们必须使用共享测试文件:真正的选项作为完整的套件运行需要很长时间,我们每天要花 9 到 10 个小时来查看.但是当我们在 conf 文件中配置以下两个选项时.测试运行良好,但最终报告仅在保存路径中显示最后的规范运行结果.合并所有选项不会提供完整的报告.

请查看我们的 conf 文件详细信息.任何帮助将不胜感激.

根据 Aditya 提供的解决方案编辑 conf 文件.请帮忙

 var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');var log4js = require('log4js');var 参数 = process.argv;var args = process.argv.slice(3);出口.config = {//seleniumServerJar: './node_modules/gulp-protractor/node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',seleniumAddress: 'http://localhost:4444/wd/hub',allScriptsTimeout: 100000,框架:'jasmine2',onPrepare: 函数 () {返回新的承诺(功能(履行,拒绝){browser.getCapabilities().then(函数(值) {reportName = value.get(Math.random(8,2)) + '_' + value.get('browserName') + '_' + Math.floor(Math.random() * 1E16);jasmine.getEnv().addReporter(新的 Jasmine2HtmlReporter({//cleanDestination: false,savePath: __dirname+'/target',//docTitle: 'Web UI 测试报告',screenshotsFolder: '图片',//截图:真,takeScreenshotsOnlyOnFailures:真,巩固:真,巩固所有:真,保留目录:真,//fixedScreenshotName: true,文件前缀:reportName + ".html"}));实现();});});//browser.manage().timeouts().implicitlyWait(11000);变量宽度 = 768;变量高度 = 1366;browser.driver.manage().window().setSize(768, 1366);browser.ignoreSynchronization = false;},afterLaunch: 函数 afterLaunch() {var fs = 需要('fs');变量输出 = '';fs.readdirSync('target/').forEach(function (file) {if (!(fs.lstatSync('target/' + file).isDirectory()))输出 = 输出 + fs.readFileSync('目标/' + 文件);});fs.writeFileSync('target/ConsolidatedReport.html', output, 'utf8');},套房:{示例:['./test/e2e/specs/**/*Spec.js',]},/* 能力:{浏览器名称":铬"},*/多能力:[{浏览器名称":铬"},{浏览器名称":火狐"}],resultJsonOutputFile:'./results.json',//传递给 Jasmine-node 的选项.茉莉花节点选择:{显示颜色:真,默认超时间隔:100000}};

解决方案

限制在于Jasmine2HtmlReporter",因为它会在测试并行运行时覆盖 html 报告文件.但避免这种情况绝对是可能的,并且有几种方法可以做到这一点.根据您的方便选择正确的方式

1) 修补 Jasmine2HtmlReporter 的index.js"以追加文件而不是使用 PhantomJs 覆盖其使用

2) 通过 onPrepare() 函数配置 Jasmine2HTML 报告器生成唯一的 HTML 报告,并在以后合并所有报告

解决方案1:Jasmine2HtmlReporter的当前代码库 - index.js 使用两个函数 - phantomWrite() &nodeWrite() 写入数据.参考

我们用来命名 HTML 报告的sessionID"是 webdriver 远程 sessionID,如果您怀疑它可能不会在多个会话中保持唯一性,只需为各个 HTML 报告生成一个随机数并稍后合并

我已经修改了上面的代码

Recently we have configured our e2e-tests to be on Jenkins & soon we realized that we have to use shared test files: true options as complete suite run is taking very long time for us peeking 9-10hrs on daily basis. but when we configured below two options in conf file. tests are running fine but final report displays only the last specs run results in save path. consolidate all options is not giving the full reports.

please find our conf file details. any help will be appreciated.

Edit the conf file as per solution provide by Aditya. please help

   var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var log4js = require('log4js');
var params = process.argv;
var args = process.argv.slice(3);

exports.config = {
  //seleniumServerJar: './node_modules/gulp-protractor/node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  allScriptsTimeout: 100000,
  framework: 'jasmine2',

  onPrepare: function () {

    return new Promise(function(fulfill, reject) {
      browser.getCapabilities().then(function(value) {
        reportName = value.get(Math.random(8,2)) + '_' + value.get('browserName') + '_' + Math.floor(Math.random() * 1E16);
        jasmine.getEnv().addReporter(
          new Jasmine2HtmlReporter({
            //cleanDestination: false,
            savePath: __dirname+'/target',
            //docTitle: 'Web UI Test Report',
            screenshotsFolder: 'image',
            //takeScreenshots: true,
            takeScreenshotsOnlyOnFailures: true,
            consolidate: true,
            consolidateAll: true,
             preserveDirectory: true,
            //fixedScreenshotName: true,
            filePrefix: reportName + ".html"
          })
        );
        fulfill();
      });
    });

    // browser.manage().timeouts().implicitlyWait(11000);
    var width = 768;
    var height = 1366;
    browser.driver.manage().window().setSize(768, 1366);
    browser.ignoreSynchronization = false; 
  },

  afterLaunch: function afterLaunch() {
    var fs = require('fs');
    var output = '';
    fs.readdirSync('target/').forEach(function (file) {
      if (!(fs.lstatSync('target/' + file).isDirectory()))
        output = output + fs.readFileSync('target/' + file);
    });
    fs.writeFileSync('target/ConsolidatedReport.html', output, 'utf8');

  },

  suites:{

    example:['./test/e2e/specs/**/*Spec.js',]
  },


  /*  capabilities: {
      'browserName': 'chrome'
    },*/

  multiCapabilities: [
    {
      'browserName': 'chrome'
    },
    {
      'browserName': 'firefox'
    }
  ],


  resultJsonOutputFile:'./results.json',

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 100000
  }
};

解决方案

The limitation is with the 'Jasmine2HtmlReporter' as it overwrites the html report file when tests run in parallel. But avoiding this is definitely possible and there are couple of ways of doing it. Pick up the right way based on your convenience

1) Tinker with 'index.js' of Jasmine2HtmlReporter to append file instead of PhantomJs overwrite its using

2) Generate unique HTML reports by configuring Jasmine2HTML reporter from onPrepare() function and consolidate all the reports later

SOLUTION 1: The current code base of Jasmine2HtmlReporter - index.js uses two functions - phantomWrite() & nodeWrite() to write data. Refer here

I have created a new function - appendwrite() to append instead of overwriting and have modified code to pickup this function Check out my github code forked out of protractor-jasmine2-html-reporter

        function appendwrite(path, filename, text){
            var fs = require("fs");
            var nodejs_path = require("path");
            require("mkdirp").sync(path); // make sure the path exists
            var filepath = nodejs_path.join(path, filename);
            fs.appendFileSync(filepath,text)
            return;
        }

And modify the self.writeFile function in 'node_modules/protractor-jasmine2-html-reporter/index.js' to pickup the new function

        try {
            appendwrite(path, filename, text);
            //phantomWrite(path, filename, text);
            return;
        } catch (e) { errors.push('  PhantomJs attempt: ' + e.message); }
        try {
            nodeWrite(path, filename, text);
            return;
        } catch (f) { errors.push('  NodeJS attempt: ' + f.message); }

And Comment the below code which cleans reports on new run so that you dont see any error cleanup error - CleanUpCode

    rmdir(self.savePath);

SOLUTION 2: Generate separate reports based on sessionID for parallel instances by configuring the Jasmine reporter in OnPrepare function

onPrepare: function() {
        return new Promise(function (fulfill, reject) {
            browser.getCapabilities().then(function (value) {
                reportName = value.get('webdriver.remote.sessionid') + '_' + value.get('browserName') + '_' + Math.floor(Math.random()*1E16);
                jasmine.getEnv().addReporter(
                    new Jasmine2HtmlReporter({
                        savePath: 'target/',
                        screenshotsFolder: 'images',
                        consolidate: true,
                        consolidateAll: true,
                        filePrefix: reportName + ".html"
                    })
                );
                fulfill();
            })
        });
    },

Step 2: Consolidate the reports generated across parallel instances in afterLaunch() method after complete tests are done and all webdriver sessions are closed

afterLaunch: function afterLaunch() {
        var fs = require('fs');
        var output = '';
       fs.readdirSync('target/').forEach(function(file){
           if(!(fs.lstatSync('target/' + file).isDirectory()))
            output = output + fs.readFileSync('target/' + file);
       });
        fs.writeFileSync('target/ConsolidatedReport.html', output, 'utf8');
    },

You will see reports generated something like below with one ConsolidatedReport also PS: Please ignore any typo and syntax errors. this is just to serve as an example and can be customized

EDIT1: The 'sessionID' we are using to name the HTML report is the webdriver remote sessionID and if you have doubt that it may not remain unique through multiple sessions, Just generate a random number for the individual HTML reports and consolidate later

I have modified the code above

这篇关于当使用 'shardTestFiles' 共享测试时,protractor-jasmine2-html-reporter 不会合并所有测试的结果:conf 文件中的 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆