Protractor 如何使用量角器访问ng栅格元素?
我想为使用ng网格的页面编写一个量角器测试。 我没有看到任何关于如何做到这一点的文档。在我的页面上,我看到一个包含数据的网格,html如下所示:Protractor 如何使用量角器访问ng栅格元素?,protractor,ng-grid,angularjs-e2e,Protractor,Ng Grid,Angularjs E2e,我想为使用ng网格的页面编写一个量角器测试。 我没有看到任何关于如何做到这一点的文档。在我的页面上,我看到一个包含数据的网格,html如下所示: 如何从量角器中找到该网格上的元素?考虑以下控制器: var-app=angular.module('angularE2EExamples'); app.controller('GridCustomerController',函数($scope,$http){ $scope.customers=[{id:1,名称:'Lissa Montrose',电
如何从量角器中找到该网格上的元素?考虑以下控制器:
var-app=angular.module('angularE2EExamples');
app.controller('GridCustomerController',函数($scope,$http){
$scope.customers=[{id:1,名称:'Lissa Montrose',电子邮件:'lissa@company.com,城市:'华盛顿',评论:'},
{id:2,姓名:'Karri Lanze',电子邮件:'karri@company.com,城市:“达拉斯”,评论:'},
{id:3,姓名:'Michael Smith',电子邮件:'michael@company.com,城市:'伯克利',评论:'},
{id:4,姓名:'Fred Tyler',电子邮件:'fred@company.com,城市:'华盛顿',评论:'}
];
$scope.gridCustomers={
数据:“客户”,
columnDefs:[{field:'id',displayName:'id',width:30},
{字段:'name',显示名称:'name'},
{字段:'email',显示名称:'email'},
{字段:'城市',显示名称:'城市'},
{字段:'注释',显示名称:'注释',
单元格模板:“”
],
enableCellSelection:true,
enableRowSelection:false,
enableCellEdit:true,
enableColumnResize:true,
enableColumnReordering:true,
多选:错,
宽度:“自动”
};
});
以及以下HTML:
访问ng grid组件中不同元素的一种非常有用的方法是使用by.binding('row.entity')
,其中“字段
”是数据模型的键。您需要定义一个测试用例,如下所示:
description('Customer test cases'),function(){
它('应该迭代所有网格元素',函数(){
browser.get('http://localhost:9000/customers');
元素.all(by.binding('row.entity.id')).each(函数(单元格){
浏览器睡眠(500);
单元格。单击();
cell.getText().then(函数(文本){
console.log('Id:'+文本);
});
});
元素.all(按.binding('row.entity.name')).each(函数(单元格){
浏览器睡眠(500);
单元格。单击();
cell.getText().then(函数(名称){
console.log('Name:'+Name);
});
});
element.all(by.model('row.entity.comment')).each(函数(单元格){
浏览器睡眠(500);
单元格。单击();
cell.sendKeys(“新客户”);
});
《睡眠》(2000年);
});
});
在中找到控制器的源代码和HTML内容
在本例中,我为最后一列定义了一个自定义模板。因此,我使用by.model('row.entity')
来访问相应的元素
中提供了给定e2e测试的完整可运行示例
希望能有帮助