How to validate the grid table value in protractor

2019-08-01 18:07发布

In protractor, I want to verify whether added value is displaying in the grid. How do I validate it?

The grid looks like this:

grid

2条回答
等我变得足够好
2楼-- · 2019-08-01 18:52

Try it at your end and let me know it works:

var a  = element(by.xpath("//div[contains(text(), 'test_protractor')]")).getText().then(function(msg){
  console.log(msg)
  expect(msg).toEqual("test_protractor")
})

If there are multiple and you want to get only first row then

var a  = element.all(by.xpath("//div[contains(text(), 'test_protractor')]")).get(1).getText().then(function(msg){
  console.log(msg)
  expect(msg).toEqual("test_protractor")
})
查看更多
够拽才男人
3楼-- · 2019-08-01 18:54

Let me assume you have created a new row with below details,

var newRow = {
  "obligation_name" : "sudharsan",
  "status" : "",
  "module" : "Test Module"
}

If you want to verify that the newly entered row is displayed,You can try the below code,

var rowList = element.all(by.repeater("(colRenderIndex, col) in colContainer.renderedColumns"));
var expectedRow = rowList.filter(function(rowElement,index) {
  var columnList = rowElement.all(by.css("div.ui-grid-cell-contents"));
  return columnList.getText().then(function(columnValues) {
    return (columnValues[0]== newRow["obligation_name"]) && (columnValues[1] == newRow["status"]) && (columnValues[2] == newRow["module"]);
  });
});
expect(expectedRow.count()).toBeGreaterThan(0);
查看更多
登录 后发表回答