Protractor Page Object Model causes error message - "is not a function"

时间:2017-06-15 10:25:57

标签: javascript angularjs function protractor pageobjects

I am trying to use the Page Object model for my browser automation testing. The below code works, but it is contained within the it(){} block which is not what I want.

describe('"Re Submit Staging" button should create a pop-up within the', () => {
  it('products tab', ()=>{
    browser.sleep(base.sleepAmount()); 
    expect(managementProductsPage.returnPreviewHeaderText().isPresent()).toBe(false);

    managementProductsPage.clickReSubmitStagingButton();

    browser.wait(function(){
        return element(by.css('.bs-callout.bs-callout-danger')).isPresent();//wait for the growl to appear
    },10000).then(function(){//waiting 10 seconds for the growl to appear
        this.getReSubmitNotificationText = element(by.css('.bs-callout.bs-callout-danger')).getText();
        expect(this.getReSubmitNotificationText).toContain('Resubmit Reference Document');
        browser.sleep(base.sleepAmount());
    });
  });

When I attempt to use the Page Object model, and run the code (below), protractor throws the following error: "Failed: managementProductsPage.getReSubmitNotificationText is not a function".

browser.wait(function(){
        return managementProductsPage.getReSubmitNotificationText().isPresent();//wait for the growl to appear
    },10000).then(function(){//waiting 10 seconds for the growl to appear
        this.getReSubmitNotificationText = managementProductsPage.getReSubmitNotificationText();
        this.getReSubmitNotificationText1 = this.getReSubmitNotificationText.getText();
        expect(this.getReSubmitNotificationText1).toContain('Resubmit Reference Document');
        browser.sleep(base.sleepAmount());
    });

The above functions are contained within a separate .js page as follows:

class ManagementProductsPage extends NavbarManagementPage{
constructor(){
    super();

    this.getReSubmitNotificationText = element(by.css('.bs-callout.bs-callout-danger'));
}

getReSubmitNotificationText() {
    return this.getReSubmitNotificationText;
}
}

module.exports = ManagementProductsPage

This function is then called in my test.js file with the following: var ManagementProductsPage = require('../pages/managementProducts.page.js');

describe('Dashboard management page', () => {
var managementProductsPage = new ManagementProductsPage();

I do not understand why this would not work? Also, I am not using waitForAngular as the website has some trouble and tends to 'hang', causing protractor to timeout.

0 个答案:

没有答案
相关问题