protractor-jasmine2-screenshot-reporter不在所需文件夹中生成屏幕截图

时间:2018-03-16 05:24:08

标签: node.js angular jasmine protractor screenshot

我的protractor.conf.js具有以下内容。我无法在这里发现什么是错的。我在angular-cli的根文件夹中手动创建了目标/屏幕截图。当我运行量角器conf.js时,量角器会在浏览器窗口中进行测试,但屏幕截图并未生成。任何人都可以帮我解决这个问题吗?

// Protractor configuration file

const { SpecReporter } = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var fs = require('fs');

var reporter = new HtmlScreenshotReporter({
  dest: 'target/screenshots',
  filename: 'my-report.html',
  cleanDestination: false,
  showSummary: true,
  showConfiguration: false,
  reportTitle: null,
  ignoreSkippedSpecs: false,
  captureOnlyFailedSpecs: false,
  reportOnlyFailedSpecs: false
});

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: false,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  chromeOnly: true,
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(reporter);  
  },
  afterLaunch: function(exitCode) {
    return new Promise(function(resolve){
      reporter.afterLaunch(resolve.bind(this, exitCode));
    });
  }
};

提前致谢!

2 个答案:

答案 0 :(得分:0)

protractor-jasmine2-screenshot-reporterjasmine2兼容,因此请更改为conf.js中的framework: 'jasmine2'

您需要使用更高版本的Protractor,其中包含jasmine2

我用你的conf进行了快速测试(做了一点改动)并且它有效。

<强> conf.js

var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
// var fs = require('fs');

var reporter = new HtmlScreenshotReporter({
  dest: 'target/screenshots',
  filename: 'my-report.html',
  cleanDestination: false,
  showSummary: true,
  showConfiguration: false,
  reportTitle: null,
  ignoreSkippedSpecs: false,
  captureOnlyFailedSpecs: false,
  reportOnlyFailedSpecs: false
});

exports.config = {
  allScriptsTimeout: 11000,
//   specs: [
//     './e2e/**/*.e2e-spec.ts'
//   ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: false,
//   baseUrl: 'http://localhost:4200/',
  framework: 'jasmine2',
//   chromeOnly: true,
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    jasmine.getEnv().addReporter(reporter);  
  },
  afterLaunch: function(exitCode) {
    return new Promise(function(resolve){
      reporter.afterLaunch(resolve.bind(this, exitCode));
    });
  }
};

<强> spec.js

   describe('xxx', function(){

        it('yyy', function(){

            browser.get('https://angular.io/');
        });
    });

目标/屏幕截图文件夹和 HTML 报告, (我跑两次,所以有两个截图。)

  • 点击yyy将打开屏幕截图
  • 如果不存在,
  • protractor-jasmine2-screenshot-reporter将创建target/screenshots文件夹,无需提前创建。 enter image description here

我使用的版本

protractor 5.3.0
protractor-jasmine2-screenshot-reporter  0.5.0

答案 1 :(得分:0)

您可以添加'protractor-screenshoter-plugin'

进行检查
plugins: [{
    package: 'protractor-screenshoter-plugin',
    screenshotPath: <specify the path>,
    screenshotOnExpect: 'failure',
    screenshotOnSpec: 'failure+success',
    withLogs: 'true',
    writeReportFreq: 'asap',
    imageToAscii: 'failure',
    htmlReport:'true',
    verbose:'info',
    clearFoldersBeforeTest: true,
    failTestOnErrorLog: {
        failTestOnErrorLogLevel: 900
    }
},

还可以查看https://www.npmjs.com/package/protractor-screenshoter-plugin