[英]AngularJS Protractor: randomly fail in headless mode (Firefox)
這是我的配置文件。
exports.config = {
rootElement: '[ng-app="myapp"]',
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./web/assets/e2e/**/*protractor.js'],
SELENIUM_PROMISE_MANAGER: false,
baseUrl: 'https://localhost',
capabilities: {
browserName: 'firefox',
marionette: true,
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: ['--headless'],
},
}
}
因此,使用此配置,我的測試會隨機失敗,並顯示以下錯誤
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
但! 當我注釋掉以下幾行時
'moz:firefoxOptions': {
args: ['--headless'],
},
它代表無頭模式,並觀看firefox如何運行我的測試-測試永不失敗,並且花費的時間減少了3倍。
下面是一個測試示例,由於我上面提到的錯誤而失敗了幾次。
it('- should test add button open a form', async () => {
await ClientListPageDriver.openAddClientForm();
await FormDriver.toBeShown('Add New Client');
await FormDriver.pressClose();
});
這是我引用的驅動程序中的方法
this.openAddClientForm = async () => {
const button = await $('button[ng-click="$ctrl.addClient()"]');
await button.click();
};
this.toBeShown = async (title) => {
const modalElement = await $('#form').element(by.cssContainingText('.form-header h2', title))
const awaitSeconds = 6;
return await browser.wait(
protractor.ExpectedConditions.presenceOf(modalElement),
awaitSeconds * 1000,
`Form should be shown within ${awaitSeconds} sec`,
);
};
this.pressClose = async () => {
const button = await $('button[ng-click="$ctrl.closeForm()"]');
await button.click();
};
我的問題是-我做錯了什么,我可能丟失了什么以及如何解決? 謝謝!
將以下代碼添加到您的配置中
allScriptsTimeout: 20000,
jasmineNodeOpts: {
defaultTimeoutInterval: 100000
}
根據測試執行時間調整超時間隔。 有關更多信息,請參閱https://www.theoldschoolhouse.com/reviews_client/node_modules/protractor/docs/timeouts.md
希望對你有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.