how to return object from protractor

310 Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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, e.g. 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']);