简体   繁体   English

如何在 Protractor 测试中验证 Angular 网格的第一列中的文本?

[英]How to verify text within first column of Angular Grid in Protractor test?

As part of a Protractor test on my Angular app, I am trying to validate the text within the cells in the first column of an Angular Grid.作为对我的 Angular 应用程序进行 Protractor 测试的一部分,我正在尝试验证Angular 网格第一列中单元格内的文本。

The below code validates the text of each cell of the grid:下面的代码验证网格的每个单元格的文本:

element.all(by.css('div.ag-cell'))
  .map(function (cell) {
      return cell.getText();
      })
    .then(function (cellValues) {
        expect(cellValues).toEqual(["Toyota", "Ford", "Porsche"]);
        });

When ran against the below table, this code will check "Toyota", "Celica", "35000", "Ford", "Mondeo", etc. (ie each cell)当针对下表运行时,此代码将检查“Toyota”、“Celica”、“35000”、“Ford”、“Mondeo”等(即每个单元格)

However, I want the test to only validate "Toyota", "Ford", & "Porsche" (ie the first column of this Angular Grid ) :但是,我希望测试仅验证“Toyota”、“Ford”和“Porsche” (即此Angular Grid的第一列)

桌子

Can someone please tell me what changes I need to make for this?有人可以告诉我为此我需要做些什么改变吗?

Note: If aria-colindex="1" left: 0px;" can be used as a selector, then I think I would be able to use that.注意:如果aria-colindex="1" left: 0px;"可以用作选择器,那么我想我可以使用它。

I would use col-id instead of aria-colindex , and for you I would assume col-id would be make but I will first show you using aria-colindex .我会使用col-id而不是aria-colindex ,对你来说,我会假设col-id会被make ,但我会首先向你展示使用aria-colindex

element.all(by.css('div.ag-cell[aria-colindex="1"]'))
  .map(function (cell) {
      return cell.getText();
      })
    .then(function (cellValues) {
        expect(cellValues).toEqual(["Toyota", "Ford", "Porsche"]);
        });

Using col-id使用col-id

element.all(by.css('div.ag-cell[col-id="make"]'))
  .map(function (cell) {
      return cell.getText();
      })
    .then(function (cellValues) {
        expect(cellValues).toEqual(["Toyota", "Ford", "Porsche"]);
        });

Check out CSS attribute selectors: https://www.w3schools.com/css/css_attribute_selectors.asp查看 CSS 属性选择器: https://www.w3schools.com/css/css_attribute_selectors.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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