javascriptjasmineprotractorreportportal

Manually resolve promise for getPromiseFinishAllItems


I'm using a combination of protractor, selenium, jasmine and report portal for automated testing. The tests all run fine but when it comes to the last test it always hangs and it eventually fails, looking into it, it seems to come down to what is used in the afterAll function in my protractor.conf.js file.

jasmineEnv.afterAll(async (done) => {
    await agent.getPromiseFinishAllItems(agent.tempLaunchId);

    done();
});

Now the function it calls comes from the node modules reportportal-agent.js :

getPromiseFinishAllItems(launchTempId){
    return this.client.getPromiseFinishAllItems(launchTempId)
}

I've noticed that written above this function is the comment

/*
 * This method is used for frameworks as Jasmine and other. There is problems when
 * it doesn't wait for promise resolve and stop the process. So it better to call
 * this method at the spec's function as @afterAll() and manually resolve this promise.
 *
 * @return a promise
 */

I'm wondering is there a solution for how to properly resolve this promise? I have tried looking online but not found anything of any significance

EDIT -

protractor.conf.js

const ReportportalAgent = require('agent-js-jasmine');
const { SpecReporter } = require('jasmine-spec-reporter');
const suiteSettings = require('./suiteSettings');
const settings = require('./settings');
const logger = require('./tests/helpers/logger');

// This is a temporary solution because we have issues if instances=nodes. For now balance between nodes and instances that instances < 3
const nodeReduceCount = 5;
let isBrowserOpen = false;

exports.config = {
    framework: 'jasmine',
    seleniumAddress: settings.seleniumHubHost,
    capabilities: {
        'shardTestFiles': true,
        'maxInstances': Math.max(settings.countOfStreams - nodeReduceCount, 1),
        'browserName': settings.browser,
        'loggingPrefs': {
            performance: 'INFO',
        },
        'moz:firefoxOptions': getFirefoxOptions(),
        'goog:chromeOptions': getChromeOptions(),
    },
    suites: [
        suiteSettings.suite,
    ],
    jasmineNodeOpts: {
        defaultTimeoutInterval: settings.jasmineTimeout,
        isVerbose: false,
        includeStackTrace: true,
        realtimeFailure: false,
    },
    onPrepare: async () => {
        const jasmineEnv = jasmine.getEnv();
        const capabilities = await browser.getCapabilities();
        const config = await browser.getProcessedConfig();

        global.consoleReporter = [];

        console.log(capabilities);

        if (!settings.useReportPortal) {
            registerReporter(jasmineEnv);
        } else {
            registerConsoleReporter(jasmineEnv);
        }

        jasmineEnv.beforeEach(async () => {
            jasmine.DEFAULT_TIMEOUT_INTERVAL = settings.jasmineTimeout;

            const criticalCheck = String(config.specs);

            if (criticalCheck.includes('critical')) {
                process.env.RUN_WITH_SERVICE_WORKER = 'true';
            } else {
                process.env.RUN_WITH_SERVICE_WORKER = '';
            }

            if (isBrowserOpen) {
                browser.restart();
            }

            await browser.driver.manage().window().setSize(settings.viewPort.width, settings.viewPort.height);

            isBrowserOpen = true;

            await logger.logMessage(`Opening Link ${settings.newPlanUrl()}`);

            await browser.waitForAngularEnabled(false);
            await browser.get(settings.newPlanUrl());
        });
    },
};

function registerReporter(jasmineEnv) {
    jasmineEnv.addReporter(new SpecReporter({
        spec: {
            displayStacktrace: true,
        },
    }));

    const config = {
        id: browser.params.id,
        ...settings.reportPortal,
    };
    const agent = new ReportportalAgent(config);
    const reporter = agent.getJasmineReporter();

    jasmineEnv.afterAll(async (done) => {
        await agent.getPromiseFinishAllItems(agent.tempLaunchId);

        done();
    });

    global.reporter = reporter;
    jasmineEnv.addReporter(reporter);

    return agent;
}

function registerConsoleReporter(jasmineEnv) {
    jasmineEnv.afterEach(async () => {
        await browser.takeScreenshot().then((png) => {
            const testSuite = settings.currentSuite;
            const date = new Date();
            const currentDay = `(Time-${date.getHours()}-${date.getMinutes()}-${date.getSeconds()})`;
            logger.writeScreenShot(png, `screenshots/${currentDay}_${testSuite}.png`);
        });
    });
    jasmineEnv.afterAll(async () => {
        await console.log('\n---------------------------------');
        await console.log('Test Results');
        await global.consoleReporter.forEach((testResult) => {
            console.log(testResult);
        });
        await console.log('---------------------------------');
    });
}

function getFirefoxOptions() {
    const options = {};

    if (settings.headless) {
        options.args = ['--headless'];
    }

    return options;
}

function getChromeOptions() {
    const options = {
        args: [
            '--disable-gpu',
            '--no-sandbox',
            '--disable-extensions',
            '--disable-dev-shm-usage',
            '--disable-infobars',
        ],
    };

    if (settings.headless) {
        options.args.push('--headless');

        options.perfLoggingPrefs = {
            enableNetwork: true,
        };
    }

    return options;
}

Edit:

So the error I had before was due to adding:

agent.getExitPromise.

But I've noticed after removing that and running my test suite again to see if jenkins would log anything useful when it comes to the test that gets interrupted, it says:

13:43:26  Cancelling nested steps due to timeout
13:43:26  ...Sending interrupt signal to process
13:43:31  npm ERR! path /app
13:43:31  npm ERR! command failed
13:43:31  npm ERR! signal SIGTERM
13:43:31  npm ERR! command sh -c node generateTests.js && node start.js

does anyone have any idea what the cause of this could be?


Solution

  • Okay so I finally found out what the issue was, we had files that were in the incorrect directory. That was it, once these were moved to the correct place, the issue stopped happening and the last test no longer gets hung up. So for anyone else that comes across this issue, this is something to check