【问题标题】:Protractor: counting all elements in a virtual list量角器:计算虚拟列表中的所有元素
【发布时间】:2019-02-25 10:26:51
【问题描述】:

我很难计算所有元素。它一次只显示 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

【问题讨论】:

  • 你能发布你得到的错误输出吗?列表的 html sn-p 也会很有用

标签: javascript protractor e2e-testing angular-cdk-virtual-scroll


【解决方案1】:

试试下面的函数来获取计数

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

希望对你有帮助

【讨论】:

  • 添加 html 和结果终端以更好地查看 pblm
  • 我收到了一个意外的令牌“:”。当我删除它时,我得到了一个意外的令牌“)”。
  • 有人能帮帮我吗?
  • @Mankaryouz 如果您可以发布列表中的一些 HTML,我们可以提供更多帮助
猜你喜欢
  • 2018-07-25
  • 2021-03-09
  • 2015-03-04
  • 1970-01-01
  • 1970-01-01
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
  • 2012-01-05
相关资源
最近更新 更多