Protractor/Jasmine2 -未在指定超时内调用异步回调
Protractor/Jasmine2 - async callback not invoked within specified timeout
我的e2e测试在selenium网格上运行时遇到了问题。有时由于
导致测试失败Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
试图以某种方式解决它,将defaultTimeoutInterval
更改为protracotr.conf.js中的更高值,但结果等待时间更长,但错误相同。
exports.config = {
chromeOnly: true,
chromeDriver: '../node_modules/.bin/chromedriver',
framework: 'jasmine2',
capabilities: {
'browserName': 'chrome',
shardTestFiles: true,
maxInstances: 3
},
specs: ['../e2e/protractor/spec/*.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
includeStackTrace: true,
},
我的示例规格与失败的测试:
var LoginPage = require('../pages/login_page.js');
var UsersPage = require('../pages/users_page.js');
var WelcomePage = require('../pages/welcome_page.js');
describe('Test -> my test', function () {
var loginPage;
var EC = protractor.ExpectedConditions;
var waitTimeout = 30000;
function logIn() {
loginPage.setUser('user');
loginPage.setPassword('password');
loginPage.login();
}
var clickOn = function (element) {
browser.wait(EC.visibilityOf(element), waitTimeout).then(function () {
element.click();
});
};
beforeEach(function () {
browser.ignoreSynchronization = true;
loginPage = new LoginPage();
browser.wait(EC.presenceOf(loginPage.userLogin), waitTimeout);
logIn();
var welcomePage = new WelcomePage;
clickOn(welcomePage.usersButton);
});
afterEach(function () {
var welcomePage = new WelcomePage();
welcomePage.loginButton.click();
welcomePage.logoutButton.click();
});
it('verifies counter on active tab', function () {
var usersPage = new UsersPage();
browser.wait(EC.visibilityOf(usersPage.firstRow), waitTimeout);
usersPage.rowsCount.count().then(function (count) {
expect(usersPage.activeTab.getText()).toContain('Active' + ' (' + count + ')');
});
});
谁能提供合理的解决方案如何处理/避免它,并解释为什么会发生?
我建议在it
块中有一个回调函数,这将确保在此之前执行所有异步代码。例如:
it('verifies counter on active tab', function (done) {
var usersPage = new UsersPage();
browser.wait(EC.visibilityOf(usersPage.firstRow), waitTimeout);
usersPage.rowsCount.count()
.then(function (count) {
var text = usersPage.activeTab.getText();
expect(text).toContain('Active' + ' (' + count + ')');
done();
});
});
实际上,如果返回承诺,效果会更好。当您在测试中进行异步工作时,您就脱离了对代码的顺序期望。基本上,你的代码块将被执行,并结束对它的调用,但不会有对仍在后台执行的承诺的引用。这样,量角器就不能等待它完成(但它知道它需要等待),所以测试失败。不需要手动执行done(),只需添加
return usersPage.rowsCount.count().then(function (count) {
expect(usersPage.activeTab.getText()).toContain('Active' + ' (' + count + ')');
});
我在使用量角器进行e2e测试时遇到了同样的问题,但我试图改变protractor.conf.js,它对我有效。
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 180000,
print: function() {}
},
如果我们增加defaultTimeOutInterval大于完成测试用例执行所需的时间,这种方法可能会起作用
相关文章:
- jasmine 2-在jasmine指定的超时时间内未调用异步回调.DEFAULT_TIMEOUT_INTERVAL
- setTimeout() 函数在超时持续时间之前调用
- 导致ajax调用超时错误的原因
- window.set同步处理异步调用的超时
- 条件设置超时调用
- 为接收事件的函数调用设置超时不适用于 IE7
- 具有超时的地理位置会导致错误处理程序被调用两次
- 承诺与函数调用/设置超时
- 量角器根据条件单击嵌套元素,错误 - 在指定的超时内未调用异步回调
- 画布计时器的设置超时调用函数
- 如何在角度 js $http调用中显示超时错误
- 多个设置超时调用的时间段计数
- 如何在函数调用之间设置超时
- jQuery 超时函数从未在 mouseEnter mouseleave 上调用过
- Response.重定向不能在会话超时的页面回调中调用
- Javascript中来自客户端的Web服务调用超时
- 超时后调用函数数组-JavaScript
- 超时函数完成后如何调用函数
- 为什么我的函数在setTimeout()超时之前被调用
- 有条件地基于超时调用jquery事件