TypeError:protractorImageComparison不是构造函数

时间:2019-05-08 06:53:18

标签: protractor

我尝试运行比较测试并得到错误:TypeError:protractorImageComparison不是构造函数。请指教

同一代码在完整的角度项目中工作,但是我需要从代码中进行测试。 我添加了conf.file和spec文件

    //protractor.conf.js: 

    const { SpecReporter } = require('jasmine-spec-reporter').SpecReporter;

    exports.config = {
        allScriptsTimeout: 15000,
        specs: [
            'src/tests/*.e2e-spec.js'
        ],
        capabilities: {
            'browserName': 'chrome',
            'chromeOptions': {
                'args': ['no-sandbox']
            }
        },
        directConnect: true,
        baseUrl: 'https://localhost:4200/',
        framework: 'jasmine',
        jasmineNodeOpts: {
            showColors: true,
            defaultTimeoutInterval: 30000,
            print: function() {}
        },
        onPrepare: function() {
            require('ts-node').register({
                project: require('path').join(__dirname, './tsconfig.json')
            });
            jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
            const protractorImageComparison =require('protractor-image-comparison');
            browser.driver.manage().window().setSize(1366, 768);
            browser.protractorImageComparison = new protractorImageComparison({

                baselineFolder: '.\\e2e\\src\\screenshots\\baseline',
                screenshotPath: '.\\e2e\\src\\screenshots\\actual_screenshots',
                autoSaveBaseline: true

            });

        },

    };

//test

    import {browser } from 'protractor';
    import {LoginPage} from '../pages/login.po';

    describe('login page', function() {

      beforeEach(function()
      {

        LoginPage.navigateTo();
      });

      it('login page should match the design', () => {
        expect(browser.protractorImageComparison.checkScreen('login_Page')).toEqual(0);
      });
    });

1 个答案:

答案 0 :(得分:0)

如果您正在使用最新的量角器图像比较,则表明您应该将其用作插件。构造函数本身已移至https://github.com/wswebcreation/protractor-image-comparison/blob/master/lib/index.ts#L9,并且不会导出。

应该根据自述文件将插件添加到量角器配置中:

plugins: [
        {
            // The module name
            package: 'protractor-image-comparison',
            // Some options, see the docs for more
            options: {
                baselineFolder: join(process.cwd(), './baseline/'),
                formatImageName: `{tag}-{logName}-{width}x{height}`,
                screenshotPath: join(process.cwd(), '.tmp/'),
                savePerInstance: true,
                // ... more options
            },
        },
    ],