在protractors源代码中:https://github.com/angular/protractor/blob/master/lib/browser.ts
你会发现broswer.get()在解决之前等待angular1完成引导。但是角度2 +没有实现:
.then((angularVersion) => {
// Load Angular Mocks
if (angularVersion === 1) {
// At this point, Angular will pause for us until angular.resumeBootstrap is called.
let moduleNames: string[] = [];
let modulePromise: wdpromise.Promise<void> = wdpromise.when(null);
for (const {name, script, args} of this.mockModules_) {
moduleNames.push(name);
let executeScriptArgs = [script, msg('add mock module ' + name), ...args];
modulePromise = modulePromise.then(
() => this.executeScriptWithDescription.apply(this, executeScriptArgs)
.then(null, (err: Error) => {
throw new Error(
'Error while running module script ' + name + ': ' + err.message);
}));
}
return modulePromise.then(
() => this.executeScriptWithDescription(
'window.__TESTABILITY__NG1_APP_ROOT_INJECTOR__ = ' +
'angular.resumeBootstrap(arguments[0]);',
msg('resume bootstrap'), moduleNames));
} else {
// TODO: support mock modules in Angular2. For now, error if someone
// has tried to use one.
if (this.mockModules_.length > 1) {
throw 'Trying to load mock modules on an Angular v2+ app is not yet supported.';
}
}
我要问的问题是:在解决承诺之前,量角器如何知道页面(angular5)已完成加载?我怎样才能确保页面完成加载以在我的e2e测试中具有某种一致性。
(我正在使用await / async并禁用此处描述的控制流: https://github.com/angular/protractor/blob/master/docs/control-flow.md, 但是因为承诺在没有检查引导的情况下解决,我可以等待我想要的所有内容,这将永远是一个时间问题)
答案 0 :(得分:0)
查看量角器Expected Conditions
您可以在browser.get()之后使用browser.wait()来强制量角器等到您定义的条件得到满足。
例如:
var EC = protractor.ExpectedConditions;
var timeout = 15000;
browser.get(yourUrl);
browser.wait(EC.presenceOf(yourElement),timeout)
这将转到你的网址,然后等到指定的元素出现后再继续,否则它会在15000ms(15秒)后超时