【问题标题】:Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL in the protractor在量角器中 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时内未调用异步回调
【发布时间】:2020-04-29 20:43:17
【问题描述】:

我正在使用量角器和 ECMAScript 6 来开发端到端测试。但是当测试完成时,我看到了错误:

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

我尝试了在 StackOverflow 和 GitHub 上找到的所有解决方案。例如,将 jasmineNodsOption 添加到配置文件,将参数 done 添加到测试函数,将超时添加到函数没有任何帮助。

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

【问题讨论】:

    标签: javascript ecmascript-6 jasmine protractor


    【解决方案1】:

    我在想 isDisplayedwaitToBeVisible 是异步的并且卡在某个地方。

    试试:

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

    一旦您对卡在哪里有了一个很好的了解,您就可以更好地了解它为什么卡在那里。

    【讨论】:

    • 感谢您的回复。我发现配置 js 文件 if (done.status === "failed") { browser.takeScreenshot().then((png) => { allure.createAttachment('Screenshot', () => new Buffer(png, 'base64'), 'image/png')(); done(); }); } 中存在问题。在if 条件上堆叠。
    猜你喜欢
    • 2016-09-10
    • 2021-03-31
    • 2017-11-26
    • 2016-04-21
    • 1970-01-01
    • 2018-07-30
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多