我正在尝试简单地计算我的旋转木马e2e组件测试
原文链接:https://www.f2er.com/angularjs/141918.htmlcarousel.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; ??
有任何想法吗?