ssharma
ssharma

Reputation: 941

how to return a value of promise in Protractor

Panel Property Object:
this.IncSummary = element.all(by.css('#incidentList h5'));

Common function:
//Get the Text of Summary
exports.getIncSummary = function (IncId) {  
console.log("executing getIncSummary function");
Panel.IncSummary.then(function(items){
    console.log("Summary items = " +items);
    (items[IncId].getText()).then(function(txt){
            console.log("summary text = "+ txt);                                
        }); 
    return items[IncId].getText();          
  });
 };


 Using this function in my test:

 it('compare the summary text ', function() {   
  CommonFun.getIncSummary(0).then(function(promis){
                    console.log("promis= "+promis);
                });             
  });

I am getting following error:

Failed: Cannot read property 'then' of undefined

Not sure what I am doing wrong, would appreciate any help on this. Thanks in Advance.

Upvotes: 0

Views: 2124

Answers (1)

Florent B.
Florent B.

Reputation: 42528

The function getIncSummary doesn't return anything. If you wish to get the text for a given locator/index then use .get():

// Panel Property Object:

this.IncSummary = element.all(by.css('#incidentList h5'));


// Common function:

exports.getIncSummary = function (index) {
  return Panel.IncSummary.get(index).getText();
};


// Using this function in my test:

it('compare the summary text ', function() {
  CommonFun.getIncSummary(0).then(function(text){
      console.log(text);
  });
});

Upvotes: 2

Related Questions