Search code examples
javascriptchaiintern

test not failing using chai assert with intern


I am using intern for UI test automation. I have a test where entering invalid user name results in the test failing. However, my test is not failing when it should.

Steps i want to automate:

  1. enter username
  2. click next button
  3. check if password textbox is shown ( password text box is only shown if username is valid else remain on the same page)

Here is My Code:

Page Object script:

   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
    },

Test Script:

       '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
                });

            })

Can someone please explain what is not working here and how to make it work properly?


Solution

  • You need to return the loginPage promise chain:

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