Use of Expected Conditions on Non Angular Site with Protractor Leads to “Type Error: Cannot read property 'bind' of undefined”

别来无恙 提交于 2019-12-09 04:03:28

Your page object should be defined as a function:

var Page = function () {
    this.login = element(by.model('credentials.username'));
    this.password = element(by.model('credentials.password'));
    this.user = "Email";
    this.passwd = "Password";
    this.goButton = $('input.btn.btn-primary');

    this.EC = protractor.ExpectedConditions;

    this.go = function() {
        browser.get("Application URL", 30000);
        browser.wait(this.EC.elementToBeClickable(this.login), 30000);
    };
};

module.exports = new Page();

Thanks for the suggestion, I agree it should work the way you mentioned, however, it’s strange that we still get into unrecognized types issue.

We are a bit new to the node js and this stack. I tried multiple options including the one you mentioned, by wrapping everything into a function, by individually exposing the elements/functions as module exports etc..

Finally, I found the following one to be working for me, using prototyping.

var AngularPage = function () {

  };
AngularPage.prototype.login     = element(by.model('credentials.username'));
AngularPage.prototype.password  = element(by.model('credentials.password'));
AngularPage.prototype.goButton  = $('input.btn.btn-primary');

AngularPage.prototype.user      = "username";
AngularPage.prototype.passwd    = "password";
AngularPage.prototype.EC        = protractor.ExpectedConditions;

AngularPage.prototype.go        = function(){
    browser.get("Application URL",30000)
                                    .then(browser.wait(this.EC.elementToBeClickable(this.login),30000));
                                    expect(browser.getTitle()).toContain(‘String’);
     };
AngularPage.prototype.loginMethod = function(){
    console.log("Login started");
     this.login.sendKeys(this.user);
this.password.sendKeys(this.passwd);
this.goButton.click(); 
    browser.wait(this.EC.elementToBeClickable(this.compute));
    };
module.exports = AngularPage;

In the test file, this is how, I was able to import and call it, a sample snippet.

var page = require('./LoginPage_Export_As_Prototype.js');
var LoginPage = new page();
LoginPage.go();
LoginPage.loginMethod();

Thanks, Prakash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!