Transcavator / Jasmine2 - asynchronous callback is not called within the specified timeout

I ran into a problem while running my e2e tests on a selenium grid. Sometimes tests fail because of

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. 

I tried to somehow solve this problem by changing defaultTimeoutInterval to a higher value in protracotr.conf.js , but as a result, the wait is longer, but the error is the same.

 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, }, 

My sample specification with a failed test:

 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 + ')'); }); }); 

Can anyone suggest any reasonable solution on how to handle this / avoid it and explain why this is happening?

+6
source share
2 answers

I suggest having a callback function in the it block that will ensure that all asynchronous codes are executed before that. For instance:

 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(); }); }); 
+6
source

In fact, it will work better if you return the promise. Since you are doing asynchronous work in your test, you are breaking away from successive code expectations. Basically, your code block will be executed and will end with its call, but there will be no references to the promise, which is still being executed in the background. At the same time, the protractor cannot wait for completion (but he knows that he needs to wait), so the test fails. Instead of doing done () manually just add

 return usersPage.rowsCount.count().then(function (count) { expect(usersPage.activeTab.getText()).toContain('Active' + ' (' + count + ')'); }); 
+2
source

All Articles