我有一个角度组件,它基本上显示了一个数据库对象列表。由于它们可以处于不同的状态,因此它显示为角度的选项卡视图,其中每个选项卡包含处于特定状态的所有对象。每个对象都有来自后端的id与id=1
相关联。如果对象的状态发生变化,则对象会从一个选项卡移动到另一个选项卡。
html的结构看起来像this。
这是使用轮询实现的,并且在角度区域(because of this issue)之外运行:
function startPollingObjects() {
this.ngZone.runOutsideAngular(() =>
setInterval(() => {
this.refreshObjects();
}, this.pollingFrequency)
);
}
function refreshObjects() {
// async call to the backend
api.getNewObjects.then( data =>
this.ngZone.run(() => {
// Run inside zone as the inputs are changed here
// so change detection is triggered
// change data accordingly
this.list = [];
for (const row of data) {
if (!this.list[row.objectState]) {
this.list[row.objectState] = [];
}
this.list[row.objectState].push(row);
}
});
)
}
我现在要测试的是,对象是否会改变其状态并从一个标签移动到另一个标签。
state1
)遍历state1选项卡以查找id最大的对象(这是最新创建的对象)*
等待对象出现在另一个标签中(state2
)**
*
let lastCreatedObjectId = 0;
await element.all(by.xpath(`//div[@id = 'state1']/*`)).then( async elements => {
for (const object of elements) {
await object.getAttribute('id').then( objectId => {
lastCreatedObjectId = objectId > lastCreatedObjectId ? objectId : lastCreatedObjectId;
});
}
return null; // required as I'm getting this error otherwise https://pastebin.com/AasAZrVY
});
**
import { by, element, ExpectedConditions as until } from 'protractor';
const object = element(by.xpath(`//div[@id = 'state2' and ObjectAngularComponent/@id = '${lastCreatedObjectId}']`));
// clicks on the tab to select it
listObjectStatePage.selectTab(ObjectState.State2);
browser.wait(until.visibilityOf(object), 20 * 1000).then( () => {
expect(object).toBeTruthy();
return null; // required as I'm getting this error otherwise https://pastebin.com/AasAZrVY
});
- 现在事情变得有趣了 -
只要元素出现在列表中,proctractor就会抛出以下错误。
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at Timeout._onTimeout (/path/to/project/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4281:23)
at ontimeout (timers.js:466:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:267:5)
修改:return null; // required as I'm getting this error otherwise
https://pastebin.com/AasAZrVY