2016-11-23 4 views
1

[email protected]:~/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 inTypeError: Не удается прочитать свойство «конструктор» неопределенной

/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)

Это мой класс, где ошибка

'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, где ошибка is lin 2965

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

Я также схожу с ума е вернуть что-то, но sitll же

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(); 

Что я могу сделать для этого?

+0

Знаете ли вы, что '# loginTextLocator.isPresent' (в методе' CommonPageObject # isLoggedIn')? Я думаю, что это связано с обещанием ошибиться? – Hydro

+0

да, возможно, isElementDisplayed, я изменил это на! IsElementDisplayed, и он не дал этих ошибок. – mark

+0

, но вывод изменен на пользователя, который уже вошел в систему, как и ожидалось (он не вошел в систему, но я поставил «!». Так что это похоже на wrking – mark

ответ

1

Я изменил к этой функции вызывающей

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

, и она работала. прежде чем я попытался вызвать как переменную.

Смежные вопросы