javascript - nightwatch.js 在测试套件结束时暂停

标签 javascript node.js selenium 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
};

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

最佳答案

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

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

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

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

然后在./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);
        }
    }
};

关于javascript - nightwatch.js 在测试套件结束时暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33409800/

相关文章:

node.js - 带有 CORS 的独立 Selenium

python - 使用 Python 和 Selenium 进行抓取 - 如果元素不存在,我应该如何返回 'null'

selenium - Webdriver 单击列表中的第二个元素

c# - 驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置 - Selenium 错误

javascript - Accordion 内复选框的两种方式绑定(bind)不起作用

javascript - 使用 jQuery 在单击时切换 CSS 类不起作用

php - 无法从 Nest 服务器获取访问 token

javascript - 在渲染模板中创建按钮

javascript - 无法从 html 按钮调用 js 函数

javascript - 比较两个包含对象的数组,包括其他对象、数组等