如何 return 反对量角器
how to return object from protractor
我已将以下代码写入 table 中的 return 文本。
现在,我想要的是:dnassgn
是页面名称,但在调用该函数后,return 值变为空白。请指出我错在哪里。
fetch_text_from_cell_in_table: function(col_val){
var name_var="";
var km = 0;
var dm = 0;
pointer1 = element.all(by.repeater('row in renderedRows')).then(function(posts) {
for (ni = 0; ni < posts.length; ni++)
name_var= posts[ni].element(by.className(col_val)).getText().then(function(name){
//console.log(valdation_value);
console.log(col_val);
console.log(name);
var name_var = name.trim();
return name;
});
});
return name_var;
},
var dn_num=dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe('Not Found');
首先,您的函数没有返回任何内容。
此外,据我了解,您需要过滤 table 并获取特定列中单元格的文本值(具有特定 class 名称的单元格,例如 colt0
).使用 map()
:
function fetch_text_from_cell_in_table (col_val) {
return element.all(by.repeater('row in renderedRows')).map(function(post) {
return post.element(by.className(col_val)).getText();
});
});
用法:
var dn_num = dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe(['Not Found']);
我已将以下代码写入 table 中的 return 文本。
现在,我想要的是:dnassgn
是页面名称,但在调用该函数后,return 值变为空白。请指出我错在哪里。
fetch_text_from_cell_in_table: function(col_val){
var name_var="";
var km = 0;
var dm = 0;
pointer1 = element.all(by.repeater('row in renderedRows')).then(function(posts) {
for (ni = 0; ni < posts.length; ni++)
name_var= posts[ni].element(by.className(col_val)).getText().then(function(name){
//console.log(valdation_value);
console.log(col_val);
console.log(name);
var name_var = name.trim();
return name;
});
});
return name_var;
},
var dn_num=dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe('Not Found');
首先,您的函数没有返回任何内容。
此外,据我了解,您需要过滤 table 并获取特定列中单元格的文本值(具有特定 class 名称的单元格,例如 colt0
).使用 map()
:
function fetch_text_from_cell_in_table (col_val) {
return element.all(by.repeater('row in renderedRows')).map(function(post) {
return post.element(by.className(col_val)).getText();
});
});
用法:
var dn_num = dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe(['Not Found']);