加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular:量角器 – count()没有解析并导致超时

发布时间:2020-12-17 07:25:06 所属栏目:安全 来源:网络整理
导读:我正在尝试简单地计算我的旋转木马e2e组件测试 carousel.po.ts import { browser,element,by,Key } from 'protractor';export class CarouselDemoPage { navigateTo() { return browser.get('/design/carousel'); } getCarouselComponent(index: number) { r
我正在尝试简单地计算我的旋转木马e2e组件测试

carousel.po.ts

import { browser,element,by,Key } from 'protractor';

export class CarouselDemoPage {
  navigateTo() {
    return browser.get('/design/carousel');
  }


  getCarouselComponent(index: number) {
     return element.all(by.css('cfc-carousel')).get(index);
  }



  getCarouselIndicators(index: number) {
    return this.getCarouselComponent(index).element(by.css('.indicators')).all(by.repeater('item in items'));
  }
}

我的spec文件:

import { CarouselDemoPage } from './carousel.po';


describe('Carousel component',() => {
  let page: CarouselDemoPage;

  beforeEach(() => {
    page = new CarouselDemoPage();
    page.navigateTo();
  });

  it('At least one carousel component should exist',() => {
    expect<any>(page.getCarouselComponent(0)).toBeDefined();
  });

  it('Check correct number of indicators displayed',() => {
    expect<any>(page.getCarouselIndicators(0).count()).toEqual(4);
  });
});

我有最新的或接近最新的至少包

“@angular/core”: “^5.0.0-beta.7”,
“jasmine-core”: “~2.8.0”,
“protractor”: “~5.1.2”

第一次测试运行正常,第二次测试结束时间

1)轮播组件检查显示的正确指示器数量
– 失败:超时等待异步Angular任务在20秒后完成.这可能是因为当前页面不是Angular应用程序.有关详细信息,请参阅常见问题解答:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular

在等待带定位符的元素时 – Locator:By(css selector,cfc-custom-select)

放弃
我在ngAfterViewInit()中有setTimeout
这里:

ngAfterViewInit() {
    // Needs the timeout to avoid the "expression has changed" bug
    setTimeout(() => {
      this.items = this.viewItems.toArray().concat(this.contentItems.toArray());
      this.totalItems = this.items.length;
      this._first = this.items[0];
      this._last = this.items[this.totalItems - 1];

      this._setItemsOrder(this.currentFrame);
      this._setInterval();
    },0);
  }

因此,我尝试了

browser.ignoreSynchronization = true;

browser.driver.sleep(50);

browser.waitForAngular();

但后来我把数量计算为0

所以经过一些调试后我发现我的轮播组件中的setInterval会破坏测试

我应该使用browser.ignoreSynchronization = true; ??

有任何想法吗?

因此,由于carousel组件中的setInterval和其他超时功能,我需要添加
browser.ignoreSynchronization = true;

我稍微修改了我的getCarouselIndicators函数
成为:

getCarouselIndicators(index: number) {
    browser.ignoreSynchronization = true;
    return this.getCarouselComponent(index).all(by.css('.indicators li'));
}

现在测试解决并完美运行!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读