带页面对象模型的量角器(打字稿错误)

时间:2018-10-29 13:26:22

标签: javascript typescript jasmine protractor automated-tests

我试图在量角器中为一个测试创建一个POM,但是我总是收到以下错误:Page未定义这是我在POM中的代码:`

'use strict';

Object.defineProperty(exports, "__esModule", { value: true });


class MainMenuPage {
    constructor() {

this.get = function() {    

    browser.get('http://localhost:5000');

  }

this.browserSleep = function () {
    return browser.sleep(1000);
}

this.getUploadButtonText = function()  {
    return element(by.css('.mat-button-wrapper')).getText();
}


this.getBrowserTitle = function() {
    return browser.getTitle();
} 

this.getNavBarText = function() {
    return element(by.css('.navbar-brand')).getText();
}

this.getNavBarUrl = function() {
    return element(by.css('.navbar-brand')).browser.getCurrentUrl();
}

this.getHomeBtnText = function() {
    return element(by.css('.link-active a')).getText(); 
}

this.getHomeBtnUrl = function() {
    return element(by.css('.link-active a')).browser.getCurrentUrl();
}

this.getPageTitleText = function() {
    return element(by.css('div.col-sm-10.body-content > app-management-overview > h1')).getText();
}

this.getUploadSisBtnText = function() {
    return element(by.css('.mat-button-wrapper')).getText();
}

this.clickUploadSisBtn = function() {
    return element(by.css('.mat-button-wrapper')).click();
}

this.getAddFilesBtnText = function() {
    return element(by.css('.add-files-btn')).getText();
}

this.getUploadSisDialogCancelBtnText = function() {
    return element(by.css('button.mat-button.ng-star-inserted')).getText();
}

this.getUploadSisDialogUploadBtnText = function() {
    return element(by.css('button.mat-raised-button.mat-primary')).getText();
}

this.clickUploadSisDialogCancelBtn = function() {
    return element(by.css('button.mat-button.ng-star-inserted')).click();
};

this.uploadPackageonUploadSisDialog = function() {
    return element(by.css('.add-files-btn'));
};

this.clickOnUploadBtnInUploadSisDialog = function() {
    return element(by.css('button.mat-raised-button.mat-primary')).click();
};

this.getNamesOfTheHeadRowTableText = function() {
    return element.all(by.css('.table th'))
    .then(function(resultH) {
            var H00 = (resultH[0]);
            var H01 = (resultH[1]);
            var H02 = (resultH[2]);
            var H03 = (resultH[3]);
            var H04 = (resultH[4]);

    });
};

this.getNamesOfBodyRowTableText = function() {
   element.all(by.css('.table td'))
    .then(function(resultB) {
           var B00 = (resultB[0]);
           var B01 = (resultB[1]);
           var B02 = (resultB[2]);
           var B03 = (resultB[3]);
           var B04 = (resultB[4]);
           return element.all(by.css('.table app-provision button'))
    }).then(function(resultB04Btn) {
                B04B0 = (resultB04Btn[0]);
                B04B1 = (resultB04Btn[1]);
                return element.all(by.css('.table option'))
    }).then(function(resultB02) {
                B02S0 = (resultB02[0]);     
                B02S1 = (resultB02[1]); 

    });
  }
 }
}

exports.MainMenuPage = MainMenuPage; 

and this is my Spec file: `
'use strict';

`Object.defineProperty(exports, "__esModule", { value: true });

var Page = require('../Pages/Ks.Sis.ServiceApp.Po.js');

let MainMenuPage1 = new Page();




describe('it should test Ks.Sis.AppStore.Web automatically ', function() {

        MainMenuPage1.get();

        it('Should check if the Name of the Title is correct',function() {
            expect(MainMenuPage1.getBrowserTitle()).toBe("Ks.Sis.AppStore.Web");
        });   

        it('should check if the name of the Navbar is correct', function(){
            expect(MainMenuPage1.getNavBarText()).toBe("Ks.Sis.ServiceApp")

        });

        it('should check if the Url of Navbar is correct ',function() {
            var NavBar = element(by.css('.navbar-brand'));
                 return expect(browser.getCurrentUrl(NavBar)).toEqual("http://localhost:5000/app-management");
            //expect(getNavBarUrl()).toEqual("http://localhost:5000/app-management")

        });

        it('should check if the name of Homebtn is correct', function() {
            expect(MainMenuPage1.getHomeBtnText()).toBe("Applications")

        });        

        it("should check if the Url of the Homebtn is correct", function() {
            var HomeBtnUrl = element(by.css('.link-active a')); 
                return expect(browser.getCurrentUrl(HomeBtnUrl)).toEqual("http://localhost:5000/app-management");

            //expect(getHomeBtnUrl()).toEqual("http://localhost:5000/app-management")

        });

        it('should check if the name of the Home page Overview is correct', function() {
            expect(MainMenuPage1.getPageTitleText()).toEqual("Application Management")

        });

        it('should check if the name of the UploadSisBtn is correct', function() {
            expect(MainMenuPage1.getUploadSisBtnText()).toBe("Upload Sis Package")
        }); 

        it('should check if the name of the Add Files Btn is correct', function() {
            MainMenuPage1.clickUploadSisBtn()
            MainMenuPage1.browserSleep()
            MainMenuPage1.expect(getAddFilesBtnText()).toBe("Add Files")

        });

        it('Should check if the name of UploadDialogCancelBtn is correct',function() {
            MainMenuPage1.clickUploadSisBtn()
            MainMenuPage1.browserSleep()
            MainMenuPage1.expect(getUploadSisDialogCancelBtnText()).toBe('Cancel');
        });

        it('Should check if the name of UploadDialogUploadBtn is correct',function() {
            MainMenuPage1.clickUploadSisBtn()
            MainMenuPage1.browserSleep()
            MainMenuPage1.expect(getUploadSisDialogUploadBtnText()).toBe('Upload');
        });

        it('Should open the UploadSisDialog and close it with CancelBtn',function() {
            MainMenuPage1.clickUploadSisBtn()
            MainMenuPage1.browserSleep()
            MainMenuPage1.clickUploadSisDialogCancelBtn()
            MainMenuPage1.browserSleep()

        });

        it('Should open the UploadSisDialog and upload a package',function() {
            var path = require('path');
            var fileToUpload = 'C:\App-Store\Application1Type.1.0.0.nupkg';
                absolutePath = path.resolve(__dirname, fileToUpload);
            MainMenuPage1.clickUploadSisBtn();
            MainMenuPage1.browserSleep();
            MainMenuPage1.uploadPackageonUploadSisDialog().sendKeys(absolutePath);
            MainMenuPage1.browserSleep();
            MainMenuPage1.clickOnUploadBtnInUploadSisDialog();
            MainMenuPage1.browserSleep();

        });


        it('should check if the names of the HeadRow Table are correct', function() {

            MainMenuPage1.getNamesOfTheHeadRowTableText()
            return element.all(by.css('.table th'))
    .then(function(resultH) {
            var H00 = (resultH[0]);
            var H01 = (resultH[1]);
            var H02 = (resultH[2]);
            var H03 = (resultH[3]);
            var H04 = (resultH[4]);


            expect(H00.getText()).toEqual("Applications");
            expect(H01.getText()).toEqual("Installed");
            expect(H02.getText()).toEqual("Package");
            expect(H03.getText()).toEqual("Dependencies");
            expect(H04.getText()).toEqual("Provision");
        });
    });

        it('should check if names of the BodyRows table are correct', function () {

            MainMenuPage1.getNamesOfBodyRowTableText()
            return element.all(by.css('.table td'))
            .then(function(resultB) {
                   var B00 = (resultB[0]);
                   var B01 = (resultB[1]);
                   var B02 = (resultB[2]);
                   var B03 = (resultB[3]);
                   var B04 = (resultB[4]);
                   expect(B00.getText()).toEqual("Application1Type");
                   expect(B01.getText()).toEqual(""); 
                   expect(B03.getText()).toEqual("Show");
                   return element.all(by.css('.table app-provision button'))
            })
            .then(function(resultB04Btn) {
                    B04B0 = (resultB04Btn[0]);
                    B04B1 = (resultB04Btn[1]);
                    expect(B04B0.getText()).toEqual("install");
                    expect(B04B1.getText()).toEqual("uninstall");
                    return element.all(by.css('.table option'))
            })
            .then(function(resultB02) {
                    B02S0 = (resultB02[0]);     
                    B02S1 = (resultB02[1]); 
                    expect(B02S0.getText()).toEqual("1.0.0");
                    expect(B02S1.getText()).toEqual("1.1.0");



            });
        })        

});

这是我得到的错误,

  

[chrome#11] [14:02:04]我/托管-在以下位置使用硒服务器   http://localhost:4444/wd/hub [chrome#11] [14:02:06] I / runnerCli-   页面不是构造函数

有什么帮助吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您正在为MainMenuPage使用命名导出,但是您的测试正在将其导入,就好像它是通过分配给module.exports本身(module.exports = MainMenuPage)导出的一样。这将导致上述错误。

在测试中正确导入

var Page = require('../Pages/Ks.Sis.ServiceApp.Po.js');

let MainMenuPage1 = new Page.MainMenuPage();