如何在Protractor中返回promise值

时间:2016-06-02 16:28:23

标签: 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);
                });             
  });

我收到以下错误:

失败:无法读取未定义的属性“然后”

不确定我做错了什么,不胜感激任何帮助。 提前致谢。

1 个答案:

答案 0 :(得分:2)

函数getIncSummary不会返回任何内容。如果您希望获取给定定位器/索引的文本,请使用.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);
  });
});