protractor-jasmine2-screenshot-reporter创建报告,但结果为'0',没有截图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了protractor-jasmine2-screenshot-reporter创建报告,但结果为'0',没有截图相关的知识,希望对你有一定的参考价值。

我一直在尝试使用“protractor-jasmine2-screenshot-reporter”获取我的执行结果的html报告和截图,但HTML报告是使用类似内容创建的

报告

摘要

测试的总规格:0

总失败:0

并且该位置没有保存屏幕截图。

HTML报告截图在这里

我的配置文件如下

    var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
    var reporter = new HtmlScreenshotReporter({
    dest: 'target/screenshots',
    filename: 'my-report.html'
    });
    exports.config = {

    directConnect: true,
    //seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {'browserName': 'chrome'},
    framework: 'jasmine',
    specs: ['Login_spec3.js'],
    allScriptsTimeout: 180000,
    getPageTimeout: 180000,
    jasmineNodeOpts: {
     defaultTimeoutInterval: 180000
    },

   // Setup the report before any tests start
   beforeLaunch: function() {
     return new Promise(function(resolve){
     reporter.beforeLaunch(resolve);
   });
   },

   // Assign the test reporter to each running instance
   onPrepare: function() {
     jasmine.getEnv().addReporter(reporter);
     afterAll(function(done) {
       process.nextTick(done);
     })
   },
    // Close the report after all tests finish
     afterLaunch: function(exitCode) {
       return new Promise(function(resolve){
     reporter.afterLaunch(resolve.bind(this, exitCode));
     });
   },
   onPrepare: function() {
     var width = 1300;
     var height = 1200;
    browser.driver.manage().window().setSize(width,height);
    }
   };

其他详细信息如下:protractor@3.2.2,nodeVersion:4.2.4,npmVersion:2.14.12,jasmine:2.4.1,selenium-webdriver:2.52.0

任何人都可以建议我解决方案吗?

答案

@Sonal:遇到问题,你正在使用2个onPrepare函数,这些函数是冲突的,只使用一个,所以修改后的工作配置将是:

  var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
  var reporter = new HtmlScreenshotReporter({
  dest: 'target/screenshots'
, filename: 'my-report.html'
});
exports.config = {

directConnect: true, //seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
    'browserName': 'chrome'
}
, framework: 'jasmine'
, specs: ['spec.js']
, allScriptsTimeout: 180000
, getPageTimeout: 180000
, jasmineNodeOpts: {
    defaultTimeoutInterval: 180000
},

// Setup the report before any tests start
beforeLaunch: function () {
    return new Promise(function (resolve) {
        reporter.beforeLaunch(resolve);
    });
},

// Close the report after all tests finish
afterLaunch: function (exitCode) {
    return new Promise(function (resolve) {
        reporter.afterLaunch(resolve.bind(this, exitCode));
    });
}
, onPrepare: function () {
    var width = 1300;
    var height = 1200;
    browser.driver.manage().window().setSize(width, height);
    jasmine.getEnv().addReporter(reporter);
    afterAll(function (done) {
        process.nextTick(done);
    })
}
};

我在我的系统中对它进行了测试,结果非常好;)

以上是关于protractor-jasmine2-screenshot-reporter创建报告,但结果为'0',没有截图的主要内容,如果未能解决你的问题,请参考以下文章