这是我的配置文件。
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'],
},
它代表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();
};
我的问题是-我做错了什么,我可能遗漏了什么,我该如何修复它?谢谢!