Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
};
like image 706
Kirsty Meredith Avatar asked Dec 05 '25 09:12

Kirsty Meredith


1 Answers

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'));
like image 117
yong Avatar answered Dec 07 '25 00:12

yong