量角器:计算虚拟列表中的所有元素

问题描述 投票:0回答:1

我很难计算所有元素。它一次只显示11个元素。向下滚动时,第一个被下一个元素替换。

这就是我所拥有的:

element.all(by.css('.task-virtual-scroll')).click()
browser.actions().keyDown(protractor.Key.CONTROL).sendKeys(protractor.Key.END).perform();

function StringtoNumber(promiseOrValue) {
  if (!protractor.promise.isPromise(promiseOrValue)) { 
    // If it isn't a promise, then convert a value
    return parseInt(promiseOrValue, 10);
  }

  return promiseOrValue.then(function(stringNumber) { 
    // If it is a promise, then convert the result to a number
    return parseInt(stringNumber, 10);
  });
}

expect(element.all(by.css('mat-card>mat-card>mat-card-header')).count())
     .toEqual((StringtoNumber(element(by.css('#mat-badge-content-1')).getText()))); 
// Expect that the notifications are equal to the notification in the badge
javascript protractor e2e-testing angular-cdk-virtual-scroll
1个回答
0
投票

尝试以下功能来计算

async function getCount(){
ele = element.all(by.css('mat-card>mat-card>mat-card-header'));
let counter:number =0;
for(i=0;i<200;i++){
await browser.sleep(2000) // Adjust the wait time based on the time taken by the page to load the next set of items
if(ele.get(i).isPresent()){
 await browser.executeScript('arguments[0].scrollIntoView()', ele.get(i));
 await browser.sleep(2000);
 counter++;
 }else{
    await console.log('Counted all the items');
    break;
    }
    }

使用上述功能获取项目计数

删除:browser.actions().keyDown(protractor.Key.CONTROL).sendKeys(protractor.Key.END).perform();

希望它能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.