Ad

Async Callback Was Not Invoked Within Timeout Specified By Jasmine.DEFAULT_TIMEOUT_INTERVAL In The Protractor

I am using a protractor and ECMAScript 6 to develop end to end tests. But when the test is finished I see the error:

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

I tried all solutions that I find on the StackOverflow and GitHub. For example, an add jasmineNodsOption to the config file, add parameters done to the test function, add timeouts to the functions nothing help.

test.js

import { doubleClick, isDisplayed, waitToBeVisible } from '../page_objects/base_page';
import HairLossPage from '../page_objects/HairLossPage';
import CartComponent from '../page_objects/components/CartComponent';

/*global expect describe beforeAll it browser*/
describe('Hair-loss. Question pages', () => {
    const heirLoss = new HairLossPage();
    const cartComponent = new CartComponent();

    beforeAll(() => {
        browser.waitForAngularEnabled(false);
        heirLoss.get();
    });

    it('Check the "CheckOut" button in the mini-cart with product', () => {
        doubleClick(heirLoss.header.card);

        waitToBeVisible(cartComponent.header.title);
        expect(isDisplayed(cartComponent.header.title)).toBe(true);

        expect(isDisplayed(cartComponent.content.shopHair)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopEd)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopSkin)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopDailyHealt)).toBe(true);
    });
});

config.js

require("@babel/register");
require("protractor");
exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['./src/tests/**.e2e.js'],
    multiCapabilities: [{
        browserName: 'chrome'
    }],

    //Global configuration
    baseUrl: 'https:/facebook.com/',

    //Allure configuration
    /*global jasmine browser allure*/
    onPrepare: () => {
        browser.manage().window().maximize();
        var AllureReporter = require('jasmine-allure-reporter');
        jasmine.getEnv().addReporter(new AllureReporter());
        jasmine.getEnv().afterEach((done) => {
            if (done.status === "failed") {
                browser.takeScreenshot().then((png) => {
                    allure.createAttachment('Screenshot', () => new Buffer(png, 'base64'), 'image/png')();
                    done();
                });
            }
        });
    }
};
Ad

Answer

I am thinking isDisplayed and waitToBeVisible are asynchronous and are getting stuck somewhere.

Try:

 beforeAll(() => {
        console.log('Before waiting for angular enabled');
        browser.waitForAngularEnabled(false);
        console.log('After waiting for angular enabled, before heirLoss.get');
        heirLoss.get();
        console.log('After heirLoss.get');
    });

    it('Check the "CheckOut" button in the mini-cart with product', () => {
        console.log('before doubleClick');
        doubleClick(heirLoss.header.card);
        console.log('after doubleClick, before waitToBeVisible');

        waitToBeVisible(cartComponent.header.title);
        console.log('after waitToBeVisible, before first isDisplayed');
        expect(isDisplayed(cartComponent.header.title)).toBe(true);

        console.log('after first isDisplayed, before 2nd isDisplayed');
        // keep adding console.log before and after these assertions and see where it gets stuck.
        expect(isDisplayed(cartComponent.content.shopHair)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopEd)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopSkin)).toBe(true);
        expect(isDisplayed(cartComponent.content.shopDailyHealt)).toBe(true);
    });

Once you have a good idea of where it gets stuck, you can have a better idea of why it's getting stuck there.

Ad
source: stackoverflow.com
Ad