Protractor 如何在量角器中返回承诺值

Protractor 如何在量角器中返回承诺值,protractor,Protractor,我遇到以下错误: 失败:无法读取未定义的属性“then” 我不知道我做错了什么,如果能在这方面提供帮助,我将不胜感激。 提前谢谢 函数getIncSummary不返回任何内容。如果希望获取给定定位器/索引的文本,请使用.get(): //面板属性对象: this.IncSummary=element.all(by.css('#incidentList h5'); //通用功能: exports.getIncSummary=函数(索引){ return Panel.IncSummary.get(i

我遇到以下错误:

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

我不知道我做错了什么,如果能在这方面提供帮助,我将不胜感激。
提前谢谢

函数
getIncSummary
不返回任何内容。如果希望获取给定定位器/索引的文本,请使用
.get()

//面板属性对象:
this.IncSummary=element.all(by.css('#incidentList h5');
//通用功能:
exports.getIncSummary=函数(索引){
return Panel.IncSummary.get(index.getText();
};
//在我的测试中使用此功能:
它('比较摘要文本',函数(){
CommonFun.getIncSummary(0).then(函数(文本){
console.log(文本);
});
});

函数
getIncSummary
不返回任何内容。如果希望获取给定定位器/索引的文本,请使用
.get()

//面板属性对象:
this.IncSummary=element.all(by.css('#incidentList h5');
//通用功能:
exports.getIncSummary=函数(索引){
return Panel.IncSummary.get(index.getText();
};
//在我的测试中使用此功能:
它('比较摘要文本',函数(){
CommonFun.getIncSummary(0).then(函数(文本){
console.log(文本);
});
});

我尝试返回Panel.IncSummary.get(index.getText();但它仍然显示失败:无法读取CommonFun.getIncSummary(0)的未定义属性“then”。then(函数(文本)行号。我在这个例子中得到了预期的结果。您的问题可能在代码的其他地方。谢谢,@Florent it worked,以前是从返回的,因此它返回的是未定义的
exports.getIncSummary=function(IncId){Panel.IncSummary.then(function(items){});return Panel.IncSummary.get(index.getText();});}将其更改为
exports.getIncSummary=function(IncId){Panel.IncSummary.then(function(items){});return Panel.IncSummary.get(index.getText();}成功了:)我尝试返回Panel.IncSummary.get(index.getText();但它仍然显示失败:无法读取CommonFun.getIncSummary(0)的未定义属性“then”。then(函数(文本)行号。我在这个例子中得到了预期的结果。您的问题可能在代码的其他地方。谢谢,@Florent it worked,以前是从返回的,因此它返回的是未定义的
exports.getIncSummary=function(IncId){Panel.IncSummary.then(function(items){});return Panel.IncSummary.get(index.getText();});}将其更改为
exports.getIncSummary=function(IncId){Panel.IncSummary.then(function(items){});return Panel.IncSummary.get(index.getText();}成功:)这只是js脚本中的基本代码。这只是js脚本中的基本代码。
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);
                });             
  });