How to validate the grid table value in protractor?

送分小仙女□ 提交于 2019-12-11 07:13:43

问题


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


来源:https://stackoverflow.com/questions/43108617/how-to-validate-the-grid-table-value-in-protractor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!