Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nightwatch.js pausing at the end of test suite

I've been using nightwatch.js for functional test automation. The problem is that the test is pausing when the test suite is finished. It doesn't end the process. The code looks like this :

var afterSuite = function(browser) {
    dbFixture.deleteCollectionItemById(companyId, 'cilents');
    dbFixture.deleteCollectionItemById(customerId, 'users');
    dbFixture.deleteCollectionItemById(assetId, 'assets');
    dbFixture.deleteFile(imageId);
    browser.end();
};

var loginTest = function(browser) {
    dbFixture.createCompany(function(company) {
        dbFixture.createCustomer(company._id, function(customer, assetid, imageid) {
            companyId = company._id;
            customerId = customer._id;
            assetId = assetid;
            imageId = imageid;
            goTo.goTo(url.localhost_home + url.login, browser);
            login.loginAsAny(customer.email, browser);
            newCustomerLoginAssert.assertNewCustomerLogin(browser);
        });
    });
};

module.exports = {
    after: afterSuite,
    'As a Customer, I should be able to login to the system once my registration has been approved': loginTest
};

I also tried adding done(); in afterSuite but still no success. Thanks in advance!

like image 334
Cooperisduhace Avatar asked Oct 29 '15 09:10

Cooperisduhace


1 Answers

An approach is to register a global reporter function that is run once all tests have finished and exits the process accordingly ie. if tests have failed or errored, exit 1, otherwise exit 0.

eg. http://nightwatchjs.org/guide#external-globals

In your nightwatch.json config add:

{
  "globals_path": "./config/global.js"
}

Then in ./config/global.js

module.exports = {
    /**
     * After all the tests are run, evaluate if there were errors and exit appropriately.
     *
     * If there were failures or errors, exit 1, else exit 0.
     *
     * @param results
     */
    reporter: function(results) {
        if ((typeof(results.failed) === 'undefined' || results.failed === 0) &&
        (typeof(results.error) === 'undefined' || results.error === 0)) {
            process.exit(0);
        } else {
            process.exit(1);
        }
    }
};
like image 200
Josh Stuart Avatar answered Sep 28 '22 11:09

Josh Stuart