Kirsty Meredith
Kirsty Meredith

Reputation: 113

Failed: Cannot read property 'bind' of undefined Protractor

Getting a Failed: Cannot read property 'bind' of undefined

Page Object class:

this.popupToastIP = function(){
element.all(by.className('toast-success toast ng-trigger ng-trigger-
flyInOut')).then(function(){
element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut')).getText(); 
});

Test spec:

browser.wait(EC.visibilityOf(publisher_whitelist_page.popupToastIP),5000);
expect(publisher_whitelist_page.popupToastIP.toEqual('Ip address removed'));  

Have tried removing the 'all' but to no avail - still with same error (followed advice of post undefined property 'bind' when using expected conditions

Any help would be greatly appreciated!

Thanks!

Kirsty

EDIT

Tried adding bind but again to no avail.

this.popupToastIP = function(){
element.all(by.className('toast-success toast ng-trigger ng-trigger-
flyInOut')).then(function(){
element(by.className('toast-success toast ng-trigger ng-trigger-
flyInOut')).getText();
}).bind(this);
};

Upvotes: 3

Views: 5569

Answers (2)

yong
yong

Reputation: 13712

You code is wrong, it dose no matter with protractor or other stuff. Another thing could you indent your code for others easy to read.

1) What the final pupose of this function, to get text from an element or to find an element?

this.popupToastIP = function(){
    element.all(by.className('toast-success toast ng-trigger ng-trigger-flyInOut'))
    .then(function(){
        element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut'))
        .getText(); 
    });
}

Issue 1
why you find element by same class name twice, the element.all(xxx) is redundant, because you no use its result in the following then().

Issue 2
you not return value for function, but your code in Test Spec require it has return value.

2) Your code in Test Spec as below, require popupToastIP return an element and the text of element, they are conflict already.

browser.wait(EC.visibilityOf(publisher_whitelist_page.popupToastIP),5000); // require return an element
expect(publisher_whitelist_page.popupToastIP.toEqual('Ip address removed')); // require return text of element

Issue 1
you decleared the popupToastIP as a function, you missed () behind it. It's no possbile for a function will be visible on page and equal to 'Ip address removed'

try below code

// Page Object
this.popupToastIP = element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut'));

// Test Spec
browser.wait(EC.visibilityOf(publisher_whitelist_page.popupToastIP),5000);
expect(publisher_whitelist_page.popupToastIP.getText()).toEqual('Ip address removed'));

Upvotes: 1

dev_khan
dev_khan

Reputation: 717

So the issue may be because bind is not available under the Protractor.js file. You have to provide definition of bind before writing your test case in the same file like this.

if (!Function.prototype.bind) {
  Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
    // closest thing possible to the ECMAScript 5
    // internal IsCallable function
    throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}

var aArgs   = Array.prototype.slice.call(arguments, 1),
    fToBind = this,
    fNOP    = function() {},
    fBound  = function() {
      return fToBind.apply(this instanceof fNOP
             ? this
             : oThis,
             aArgs.concat(Array.prototype.slice.call(arguments)));
    };

if (this.prototype) {
  // Function.prototype doesn't have a prototype property
  fNOP.prototype = this.prototype; 
}
fBound.prototype = new fNOP();

return fBound;

}; }

Upvotes: 0

Related Questions