最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - TypeError: Cannot read property 'constructor' of undefined - Stack Overflow

matteradmin4PV0评论

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 = monPageObject.isLoggedIn();

what can i do for this?

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 = monPageObject.isLoggedIn();

what can i do for this?

Share edited Nov 23, 2016 at 12:01 mark asked Nov 23, 2016 at 11:49 markmark 7374 gold badges14 silver badges35 bronze badges 5
  • Do you know what #loginTextLocator.isPresent (at the CommonPageObject#isLoggedIn method) does? I think it's related to the promise err? – user5066707 Commented Nov 23, 2016 at 12:14
  • yes maybe isElementDisplayed i changed this to !isElementDisplayed and it did not give those errors. – mark Commented Nov 23, 2016 at 12:15
  • but output changed to User already logged in as expected(it is not logged in but i put "!" . SO it seems it is wrking – mark Commented Nov 23, 2016 at 12:16
  • Nope, i`m talking about #loginTextLocator.isPresent. You could show it – user5066707 Commented Nov 23, 2016 at 12:17
  • 1 it is a library method, i did not define. protractors method. inside class, like that ElementFinder.prototype.isPresent = function() { – mark Commented Nov 23, 2016 at 12:19
Add a ment  | 

1 Answer 1

Reset to default 4

I changed to this caller function

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

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

Post a comment

comment list (0)

  1. No comments so far