【问题标题】:TypeError: Cannot read property 'constructor' of undefinedTypeError:无法读取未定义的属性“构造函数”
【发布时间】:2016-11-23 20:30:50
【问题描述】:

vegan@vegan:~/hb-x/gateway$ 吞咽量角器 [14:44:36] 使用 gulpfile ~/hb-x/gateway/gulpfile.js [14:44:36] 启动“量角器”...直接使用 ChromeDriver... [启动器] 开始运行 1 个 WebDriver 实例 - 用户未登录,因此尝试登录 x- 用户未登录,因此尝试登录 xy- 用户未登录,因此尝试登录

/home/vegan/hb-x/gateway/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2965 return fn.constructor.name === 'GeneratorFunction'; ^ 类型错误:无法读取未定义的属性“构造函数” 在 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)

这是我的错误所在的班级

'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;

这个类叫它

'use strict';


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

describe(
    'Logout module', function () {

        var logoutPageObject = new LogoutPageObject();

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

这是来自 promise.js 的错误是 lin 2965

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

我也返回了一些东西,但还是一样

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;
    };

可能是因为这个

this.isLoggedIn = commonPageObject.isLoggedIn();

我能做些什么呢?

【问题讨论】:

  • 你知道#loginTextLocator.isPresentCommonPageObject#isLoggedIn 方法)的作用吗?我认为这与promise err有关?
  • 是的,也许 isElementDisplayed 我将其更改为 !isElementDisplayed 并且它没有给出这些错误。
  • 但输出更改为用户已按预期登录(未登录但我输入了“!”。所以它似乎正在工作
  • 不,我说的是#loginTextLocator.isPresent。你可以展示它
  • 这是一个库方法,我没有定义。量角器法。在类里面,就像 ElementFinder.prototype.isPresent = function() {

标签: javascript angularjs selenium protractor


【解决方案1】:

我改成了这个调用函数

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

它奏效了。在我试图像变量一样调用之前。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多