Wizard
Wizard

Reputation: 7

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

My Protractor test fails with below error

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

This is my spec file.

let common=require('./Objects/common.js') describe('Cloud testing', function() {

it('Cloudtest1', function() {

  let EC=protractor.ExpectedConditions;    
  browser.waitForAngularEnabled(false);

  browser.get(common.loginURL);
  common.txtUserName.sendKeys('[email protected]');
  common.txtPword.sendKeys('asdasd@#$');
  common.btnLogin.click();

   
  browser.wait(EC.visibilityOf(element(by.xpath("//a[@class='btn btn-success']"))));
 
  element(by.xpath("//a[@class='btn btn-success']")).click();
  
  common.btnCrtPcr.click();

  

});

});

Any help is appreciated, I tried answers to similar questions posted here but nothing works for me. I'm running the latest Protractor and Chrome versions.

Upvotes: 0

Views: 865

Answers (2)

Ashish Chamoli
Ashish Chamoli

Reputation: 93

Your callback was later than your Jasmins default timout time. You might want to use async/await in your it block even though you have used expected condition.

it('Cloudtest1', async () => {

  let EC=protractor.ExpectedConditions;    
  browser.waitForAngularEnabled(false);

  browser.get(common.loginURL);
  await  common.txtUserName.sendKeys('[email protected]');
  await  common.txtPword.sendKeys('asdasd@#$');
  await  common.btnLogin.click();

   
  browser.wait(EC.visibilityOf(element(by.xpath("//a[@class='btn btn-success']"))));
 
  element(by.xpath("//a[@class='btn btn-success']")).click();
  
  await common.btnCrtPcr.click();

});

Suggestion: Perform action in page object or before each/all. Use it block for expect statement. example:

describe('When user logged Into account ', () => {
    beforeAll(async () => {
      await browser.waitForAngularEnabled(false);
      await loginPO.login();
      
    });
    it('Browser title should be displayed.', async () => {
      expect(await browser.getTitle()).toBe('test');
    });
  }); 

Upvotes: 0

HelloWorld
HelloWorld

Reputation: 382

Have you tried by asyn test? Sometimes even backend response or browser performance may affect the test cases.

Refer: https://jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support

describe("Your module", function() {
    var originalTimeout;
    beforeEach(function() {
      originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
      jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
    });

    it("takes a long time", function(done) {
        let EC=protractor.ExpectedConditions;    
        browser.waitForAngularEnabled(false);

        browser.get(common.loginURL);
        common.txtUserName.sendKeys('[email protected]');
        common.txtPword.sendKeys('asdasd@#$');
        common.btnLogin.click();
   
        browser.wait(EC.visibilityOf(element(by.xpath("//a[@class='btn btn-success']"))));

        element(by.xpath("//a[@class='btn btn-success']")).click();
        common.btnCrtPcr.click();
    });

    afterEach(function() {
      jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
    });
  });

Upvotes: 0

Related Questions