无法使用量角器

时间:2018-01-04 03:54:01

标签: protractor

我无法使用量角器一次为多个浏览器拍摄测试报告。

我试过下面的代码

 var Jasmine2HtmlReporter  = require('C:/Users/agudla/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
  exports.config = {
  allScriptsTimeout: 11000,
   seleniumAddress : 'http://localhost:4444/wd/hub',
  multiCapabilities : [
                            {'browserName' : 'firefox'},
                            {'browserName' : 'chrome'}
                       ],
      suites : {
                    jobs : [
                       'e2e/Jobs/Manage Jobs/ApplyJobs/ApplyJobs.e2e-spec.ts',]
               },


     baseUrl : 'http://localhost:4200/',
        framework : 'jasmine2',
  jasmineNodeOpts : {
                      showColors: true,
                      defaultTimeoutInterval: 30000,
                      print: function() {}
                    },

    onPrepare() {

                    //jasmine.getEnv().addReporter(reporter);

                   browser.getProcessedConfig().then(function(config){

                            var capabilities = config.capabilities;
                            jasmine.getEnv().addReporter(

                                    new Jasmine2HtmlReporter({

                                            savePath : '',
                                            fileName : 'protractor-report-'+capabilities.platform+'-'+capabilities.browserName,
                         takeScreenshotOnlyOnFailure : true

                                    })
                            );
                    });


                     require('ts-node').register({
                              project: 'e2e/tsconfig.e2e.json'
                    });
                },

我运行" selenium webdriver服务器"从命令提示符处运行测试脚本。 Jasmine html报告始终显示最新的浏览器结果,在这种情况下,它始终显示" firefox"与浏览器相关的测试报告。

我想接受来自"铬和火狐的测试报告"浏览器一次。谁能建议我怎么做?

1 个答案:

答案 0 :(得分:0)

使用以下代码进行多功能报告。你可以在github上推荐我的回购以获取更多细节。 点击here

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: 10000,
  framework: 'jasmine2',

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

  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',]
  },

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

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