mark
mark

Reputation: 737

TypeError: Cannot read property 'constructor' of undefined

vegan@vegan:~/hb-x/gateway$ gulp protractor [14:44:36] Using gulpfile ~/hb-x/gateway/gulpfile.js [14:44:36] Starting 'protractor'... Using ChromeDriver directly... [launcher] Running 1 instances of WebDriver Started - User not logged in, so trying to log in x- User not logged in, so trying to log in xy- User not logged in, so trying to log in

/home/vegan/hb-x/gateway/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2965 return fn.constructor.name === 'GeneratorFunction'; ^ TypeError: Cannot read property 'constructor' of undefined at Object.promise.ControlFlow.goog.defineClass.goog.defineClass.promise.isGenerator (/home/vegan/hb-x/gateway/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2965:12)

This is my class where error is

'use strict';

var CommonPageObject = function() {

    this.baseUrl = "http://localhost:8080";

    this.product = element.all(by.css('[data-tab-item="product"]')).first();



    this.loginTextLocator = element(by.css('button.layout-align-xs-start-start'));
    this.loginPageHeader = element(by.css('header'));

    this.loginUsername = element(by.model('vm.model.username'));
    this.loginPassword = element(by.model('vm.model.password'));
    this.loginButton = element(by.css('[aria-label="login.button"]'));

    this.isLoggedIn = function () {
        this.get();

        var self = this;

        this.loginTextLocator.isPresent().then(function(isElementDisplayed){
            if(isElementDisplayed){
                console.log('- User not logged in, so trying to log in');

                self.ctaLogin('cta', 'M0ha44bOw-36SMm');
            }
            else{
                console.log('- User already logged in');
            }
        })
    };

    this.get = function() {
        browser.get(this.baseUrl);
    };

    this.ctaLogin = function(name,password) {

        this.get();//necessary?
        browser.driver.wait(protractor.until
            .loginPageHeader);

        this.setName(name);
        this.setPassword(password);

        this.loginButton.click();
    };

    this.setName = function(name) {browser.sleep(5000);console.log('x- User not logged in, so trying to log in');
        this.loginUsername.clear().sendKeys(name);

    };

    this.setPassword = function(password) {browser.sleep(5000);console.log('xy- User not logged in, so trying to log in');
        this.loginPassword.clear().sendKeys(password);

    };

};

module.exports = CommonPageObject;

this class calls it

'use strict';


var LogoutPageObject = require('./logoutControllerPageObject');

describe(
    'Logout module', function () {

        var logoutPageObject = new LogoutPageObject();

        beforeEach(
            function(){
                console.log('Logout Test starting');
                logoutPageObject.isLoggedIn();

this is from promise.js where the error is lin 2965

promise.isGenerator = function(fn) {
  return fn.constructor.name === 'GeneratorFunction';
};

I also made return something but sitll same

this.isLoggedIn = function () {
        this.get();

        var self = this;

        this.loginTextLocator.isPresent().then(function(isElementDisplayed){
            if(isElementDisplayed){
                console.log('- User not logged in, so trying to log in');

                self.ctaLogin('cta', 'M0ha44bOw-36SMm');
            }
            else{
                console.log('- User already logged in');
            }
        });
        return null;
    };

it is probably because of this

this.isLoggedIn = commonPageObject.isLoggedIn();

what can i do for this?

Upvotes: 5

Views: 35990

Answers (1)

mark
mark

Reputation: 737

I changed to this caller function

this.isLoggedIn = function(){
            commonPageObject.isLoggedIn();
       };

and it worked. before i was trying to call like a variable.

Upvotes: 4

Related Questions