无法从量角器图像比较中读取属性

时间:2018-08-06 08:00:33

标签: javascript angular configuration protractor automated-tests

我是前端世界的新手,我想使用量角器图像比较编写一些测试。我遵循了https://github.com/wswebcreation/protractor-image-comparison中的安装说明。我也根据此页面进行配置。 当我尝试使用此库形式的函数时,出现以下错误:“ TypeError:无法读取未定义的属性'checkFullPageScreen'。我在下面的protractor.conf.js中感到担忧

const protractorImageComparison = require('protractor-image-comparison');
  

“找不到模块的声明文件   “量角器图像比较”。   '/home/rafa/repos/example/src/example/node_modules/protractor-image-comparison/index.js'   隐式地具有“ any”类型。尝试npm install @types/protractor-image-comparison(如果存在)或添加新的   包含declare module 'protractor-image-comparison';

的声明(.d.ts)文件

因此,我做了一个简单的* .d.ts文件,其中带有“声明模块protractor-image-comparison”,但仅警告消失后它并不能解决问题。这很可能是配置问题,但我无法处理,或者我声明了错误。这是我的配置文件:

//量角器配置文件,请参阅链接以获取更多信息 // https://github.com/angular/protractor/blob/master/lib/config.ts

const reporter = require("cucumber-html-reporter");
const path = require("path");

const jsonReports = path.join(process.cwd(), "/reports/json");
const htmlReports = path.join(process.cwd(), "/reports/html");
const targetJson = jsonReports + "/cucumber_report.json";



const cucumberReporterOptions = {
  jsonFile: targetJson,
  output: htmlReports + "/cucumber_reporter.html",
  reportSuiteAsScenarios: true,
  theme: "bootstrap",
};

exports.config = {
  allScriptsTimeout: 110000,

  restartBrowserBetweenTests: true,

  //SELENIUM_PROMISE_MANAGER: false,

  specs: [
    './e2e/**/login.feature'
  ],

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


  directConnect: true,

  baseUrl: 'http://localhost:4200/',

  framework: 'custom',

  frameworkPath: require.resolve('protractor-cucumber-framework'),

  cucumberOpts: {
    format: "json:" + targetJson,
    require: ['./e2e/steps/*.ts', "./e2e/timeout.ts"], 
  },

  useAllAngular2AppRoots: true,

  onPrepare: () => {
    browser.ignoreSynchronization = true;

    const protractorImageComparison = require('protractor-image-comparison');
    browser.protractorImageComparison = new protractorImageComparison(
      {
                baselineFolder: "report/screens/baseline",
                screenshotPath: "report/screens/actual"
      }
    );
  },

  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e'
    });
  },

  onComplete: () => {
    reporter.generate(cucumberReporterOptions);
}
};

1 个答案:

答案 0 :(得分:0)

好,我解决了。我收到此TypeError的原因是,我午餐了几个测试方案,而onPrepare仅在开始时就午餐了。我将量角器图像比较的配置移到黄瓜前,然后一切正常。