Protractor 涉及两列数据排序的量角器e2e测试
我必须验证两个操作的优先级是否相同,然后它应该作为操作名排序。使用量角器。 我尝试验证优先级排序,但它不起作用Protractor 涉及两列数据排序的量角器e2e测试,protractor,Protractor,我必须验证两个操作的优先级是否相同,然后它应该作为操作名排序。使用量角器。 我尝试验证优先级排序,但它不起作用 this.Then( /^Verify operations in with priority sorting ascending$/, function(callback) { var sorted = [] , unSorted = [],i=0; var OperationPriority = element.all(
this.Then(
/^Verify operations in with priority sorting ascending$/, function(callback) {
var sorted = [] , unSorted = [],i=0;
var OperationPriority = element.all(
by.xpath('//table/tbody/tr//dx-number-box/div/input'));
console.log("count" +OperationPriority.count);
// OperationPriority.each(function(eachName){
OperationPriority.map((eachName) =>{
// eachName.getText().then(function(name){
unSorted[i] = eachName.getText();
i++;
console.log("high");
console.log(unSorted[0]);
});
sorted = unSorted.slice();
sorted.sort();
console.log(sorted);
console.log(unSorted);
// expect(sorted).toEqual(unSorted);
callback();
});
您需要知道所有的量角器API都是异步的并返回承诺 与getText类似,getText不直接返回元素的文本,而是返回一个承诺,该承诺的最终值是元素的文本 Like count不直接返回已找到元素的长度,而是返回一个承诺,其最终值为已找到元素的长度 要使用promise的最终计算价值,您需要在内部使用它们
请正确格式化您的代码!
this.Then(
/^Verify operations in with priority sorting ascending$/,
function(callback) {
var priorities = element.all(
by.xpath('//table/tbody/tr//dx-number-box/div/input'));
// approach 1
// change below priorities.getText() to priorities.getAttribute('value')
// when priority display in an input box
priorities.getText().then(function(unSorted){
var sorted = unSorted.slice().sort();
expect(sorted).toEqual(unSorted);
});
// approach 2
priorities.map(function(item){
// change below item.getText() to item.getAttribute('value') below
// when priority display in an input box
return item.getText();
})
.then(function(unSorted){
var sorted = unSorted.slice().sort();
console.log('unSorted: ' + unSorted);
console.log('sorted : ' + sorted);
expect(sorted).toEqual(unSorted);
});
callback();
});