How to validate the grid table value in protractor

2019-08-01 18:36发布

问题:

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

The grid looks like this:

回答1:

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")
})


回答2:

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