【问题标题】:test not failing using chai assert with intern使用 chai assert 和实习生测试没有失败
【发布时间】:2017-01-18 19:15:19
【问题描述】:

我正在使用实习生进行 UI 测试自动化。我有一个测试,输入无效的用户名会导致测试失败。但是,我的测试并没有在应该失败的时候失败。

我想自动化的步骤:

  1. 输入用户名
  2. 点击下一步按钮
  3. 检查是否显示密码文本框(仅当用户名有效时才会显示密码文本框,否则留在同一页面上)

这是我的代码:

页面对象脚本:

   enterLoginName: function (username) {
        console.log('entering username');
        return this.remote
            .findById(this.locator.uname).clearValue().sleep(1000)
            .type(username)
            .end().then(function () {
                console.log('username entered ');
            })
            .findById(this.locator.nextbtn).sleep(1000)
            .click().end(); // enter login name and click next button
    },
    isValidUsername:function() {
        console.log('checking if password textbox is displayed');
        return this.remote
            .findDisplayedById(this.locator.pwd).isDisplayed();
             //passowd test box is only shown if username is valid
    },

测试脚本:

       'correct login name lands to password page': function () {

            loginPage.enterLoginName('ss').then(function () {
                loginPage.isValidUsername().then(function (pass) {
                    console.log(pass);

                }, function (fail) {
                 // code reaches here since password test box is not displayed
                    console.log('user name uas valid , enter password panel not was shown');
                    assert.fail(0, 1, 'Exception not thrown');// test not failing
                });

            })

谁能解释一下这里有什么不工作以及如何让它正常工作?

【问题讨论】:

    标签: javascript chai intern


    【解决方案1】:

    你需要返回loginPage承诺链:

    return loginPage.enterLoginName('ss')...
    

    【讨论】:

    • 我不明白。你能解释一下吗??
    • 在您的测试脚本中,您正在调用异步函数并返回 Promise(或类似 Promise 的对象),例如 loginPage.enterLoginName。在测试中使用 Promise 时,您需要 1) 返回 Promise 链的末尾,以便 Intern 可以判断异步操作何时完成,以及 2) 确保返回在 then 回调中生成的任何 Promise 以确保 所有异步操作被观察到。所以你需要return loginPage.enterLoginName在外层,return loginPage.isValidUsernamethen回调中。
    猜你喜欢
    • 2016-04-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    相关资源
    最近更新 更多