简体   繁体   中英

how to return object from protractor

I have written following code to return text from the table.

Now, I want that thing in here: dnassgn is page name, but after calling that function the return value is coming as blank. Please suggest me where I am wrong.

 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');

First of all, you are not returning anything from your function.

Besides, from what I understand, you need to filter the table and get the text values of a cell in a specific column (cell having a specific class name, eg colt0 ). Use 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();
    });
});

Usage:

var dn_num = dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe(['Not Found']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM