nightwatch.js在测试套件的末尾暂停

Coo*_*ace 5 javascript selenium node.js nightwatch.js

我一直在nightwatch.js用于功能测试自动化.问题是测试套件完成后测试暂停.它并没有结束这个过程.代码如下所示:

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
};
Run Code Online (Sandbox Code Playgroud)

我也尝试添加done();afterSuite,但仍然没有成功.提前致谢!

Jos*_*art 6

一种方法是注册一个全局reporter函数,该函数在所有测试完成后运行并相应地退出该过程,即.如果测试失败或错误exit 1,否则exit 0.

例如.http://nightwatchjs.org/guide#external-globals

在您的nightwatch.json配置中添加:

{
  "globals_path": "./config/global.js"
}
Run Code Online (Sandbox Code Playgroud)

然后进去 ./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);
        }
    }
};
Run Code Online (Sandbox Code Playgroud)