首页 > 解决方案 > 如何使用 nightwatch.js 依次运行一系列“功能”测试

问题描述

我有一个非常长的功能测试,从我的 Web 应用程序的登录面板开始,一直到更深层次的功能。这是我第一次使用 nightwatch.js - 我想知道是否有办法将这个庞大的函数分解为多个分段的函数,并按顺序运行。我尝试过,从字面上将其分解为单独的函数,就像我的主要的大型函数一样,我也尝试将每个单独的函数包装在两者之间'browser''browser.end();'但这也不起作用 - 发生的是,它们没有按顺序运行 - 所以当然他们没有找到下一个基础元素等,因为它重新开始。有什么建议吗?

    this.LoginScreen = function(browser) {
            browser
                    .url(Data.urls.home)
                    .waitForElementVisible('#login', 1000, false)
                    .click('#login')
                    .waitForElementVisible('div.side-panel.open', 4000, false)
                    // Ton more here, i'd like to modulate 

        Errors.checkForErrors(browser);

        browser.end();
};

标签: javascriptnightwatch.js

解决方案


这非常简单,可以在 Nightwatch 入门页面http://nightwatchjs.org/gettingstarted中找到

module.exports = {
 'Verify Added customer': function (browser) {
// In above first function with name 'Verify Added customer'
    browser
    .click(rc.registeredCustomers)
    .pause(t.averagePauseLimit)

},

'Verify Email Button Present': function (browser) {
// in above there is second function
    browser
        .click(rc.registeredCustomers)
        .pause(t.averagePauseLimit)
        .getText(rc.primaryEmail, function (result) {
            this.assert.equal(result.value, 'Primary : ' + email)
        })
        .pause(t.minimumPauseLimit)
        .click(rc.verifyCustomer)
        .pause(1000)
        .assert.elementNotPresent(rc.verifyEmail, 'Verify Email is not present')


},

推荐阅读