我正在使用Protractor和Cucumber测试一个Ionic应用程序,并且我正在重用之前测试中使用的页面对象,但是当我在这种情况下使用它时,会出现script timeout
错误:
[14:40:32] E/launcher - script timeout: result was not received in 11 seconds
(Session info: chrome=70.0.3538.77)
(Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
[14:40:32] E/launcher - ScriptTimeoutError: script timeout: result was not received in 11 seconds
(Session info: chrome=70.0.3538.77)
(Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
at Object.checkLegacyResponse (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
From: Task: Protractor.waitForAngular()
at thenableWebDriverProxy.schedule (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
at ProtractorBrowser.executeAsyncScript_ (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/protractor/built/browser.js:425:28)
at angularAppRoot.then (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/protractor/built/browser.js:456:33)
at ManagedPromise.invokeCallback_ (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/selenium-webdriver/lib/promise.js:668:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
这是我的黄瓜步骤:
Given('a visit is scheduled for me', function(callback) {
var world = this;
casesPage.get()
.then(() => {
return casesPage.isLoaded()
})
.then(() => {
return casesPage.clickOnCaseWithName(world.case.people[0].lastName);
})
.then(() => {
return casePage.isLoaded();
})
.then(() => {
return casePage.clickScheduleVisitButton();
})
.then(() => {
return scheduleVisitPage.isLoaded();
})
.then(() => {
return scheduleVisitPage.addAgenda();
})
.then(() => {
return scheduleVisitPage.saveVisit();
})
.then(() => {
return scheduleVisitPage.clickBackButton();
})
.then(callback);
})
这是我的页面对象:
import { browser, $, ElementFinder, ExpectedConditions } from 'protractor';
export class CasePage {
caseHeader: ElementFinder
visitNoteButton: ElementFinder
scheduleVisitButton: ElementFinder
nextVisit: ElementFinder;
backdrop: ElementFinder;
private initializePromise: Promise<void>;
async initialize(): Promise<void> {
if(!this.initializePromise) {
return this.initializePromise = new Promise<void>(async (resolve) => {
this.caseHeader = $('h2.family-name');
this.visitNoteButton = $('button.start-visit-note');
this.scheduleVisitButton = $('ion-col.schedule-visit button');
this.nextVisit = $('div.next-visit');
this.backdrop = $('ion-backdrop')
return resolve();
});
}
}
async startVisitNote(): Promise<void> {
await this.initialize();
return browser.wait(ExpectedConditions.presenceOf(this.visitNoteButton), 1000).then(() => {
return this.visitNoteButton.click();
});
}
async clickScheduleVisitButton(): Promise<void> {
await this.initialize();
return browser.wait(ExpectedConditions.presenceOf(this.scheduleVisitButton), 5000).then(() => {
return this.scheduleVisitButton.click();
});
}
async isLoaded(): Promise<boolean> {
await this.initialize();
return await this.caseHeader.isPresent();
}
async familyName(): Promise<string> {
await this.initialize();
return await this.caseHeader.getText();
}
async nextVisitPresent(): Promise<boolean> {
await this.initialize();
return await this.nextVisit.isPresent();
}
}
有什么想法可能会出错吗?
答案 0 :(得分:0)
将allScriptsTimeout:timeout_in_millis添加到您的量角器配置文件中。默认值为11秒。而且,如果您的应用不是角度应用,请禁用等待角度。
exports.config = {
allScriptsTimeout: 30000,
...
onPrepare: function() {
browser.waitForAngularEnabled(false)
}
};