首页 > 解决方案 > E2E Protractor:页面对象映射找不到模块

问题描述

目前,我正在尝试使用页面对象进行 e2e 测试以减少维护工作,并且我能够编写如下内容:

Test1-声明登录页面字段

var xxxx_Page_Mdemo = function () {

    var companycode = element(by.id('company-code'));
    var username = element(by.id('username'));
    var password = element(by.id('password'));
    var signclick = element(by.css('section>form>button'));

    this.get = function () {
        browser.get('https://xxxx.com');
    };

    this.setCompanycode = function (ccode) {
        companycode.sendKeys(ccode);
    };

    this.setUsername = function (uname) {
        username.sendKeys(uname);
    };

    this.setPassword = function (pasword) {
        password.sendKeys(pasword);
    };

    this.setsignclick = function (signin) {
        signclick.click(signin);
    };
};

module.exports = new xxxx_Page_Mdemo();

测试2

var xxxxlogin_Page_Mdemo = require('./PageAdminuserlogsuper.js');

describe('xxlogin page', function () {

    beforeEach(function () {
        browser.waitForAngularEnabled(false);
    });

    afterEach(function () {
        browser.executeScript('window.sessionStorage.clear();');
        browser.executeScript('window.localStorage.clear();');
        browser.restart();
    });

    it('should login to thexxx dashboard', function () {
        login_Page_Mdemo.get();
        var EC = protractor.ExpectedConditions;
        browser.wait(EC.visibilityOf($('#company-code')))
            .then(function () {
                login_Page_Mdemo.setCompanycode('cc90');
                login_Page_Mdemo.setUsername('xxxx.com');
                xxxx_Page_Mdemo.setPassword('pass');
                xxxx_Page_Mdemo.setsignclick();
                browser.wait(EC.urlContains('https://.xxx.com/#/xxx/index'), 100000).then(function () {
                     console.log('xxxx');
                     browser.sleep(4000);
                });
           });
     });
});

从那里我能够登录到特定页面,我的问题是我必须在登录后导航到应用程序内的其他字段并在单独的页面上执行一些点击。我已经为此创建了相同的页面对象,我无法将登录功能链接到我收到此错误。任何意见?

    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
[09:25:28] E/launcher - Process exited with error code 100

Process finished with exit code 4
Empty test suite.

我的 conf 文件是这样的:

'./tests/MainObjects/PageAdminuserlogsuper.js',
'./tests/MainObjects/AdminuserlogPageobjectadopt.js',

'./tests/MainObjects/PageEmployeetemplatesuper.js',
'./tests/MainObjects/QE35CustomizeEmptemplate.js'

标签: objectdesign-patternsprotractor

解决方案


推荐阅读