0

The below code all functions correctly with the exception of the assertion. When the test is run Jasmine reports 0 assertions. How can I keep my assertions within the promises and have them be recognized?

it("should open save NTP server modal", function (done) {
    var addModal = driver.findElement(By.className('modal-dialog'));
    driver.wait(until.stalenessOf(addModal), 5000).then(function () {
        return     driver.wait(until.elementIsEnabled(driver.findElement(By.id('saveButton'))), 5000).then(function (element){ 
            return element.click();
        });
    });

    driver.findElement(By.className("modal-body")).then(function (element) {
        return expect(element.isDisplayed()).toBeTruthy();
    });

    done();
});

I know that in this specific case(my best example test) I could just catch the element and then do the expect outside of a promise:

var element = driver.findElement(By.className("modal-body"));
expect(element.isDisplayed()).toBeTruthy();

Unfortunately I have other cases where I cannot determine a way to do the exception outside of a promise.

dittmanc
  • 25
  • 2

1 Answers1

0

You have to put your "done" method inside the final callback.

driver.findElement(By.className("modal-body")).then(function (element) {
    expect(element.isDisplayed()).toBeTruthy();
    done();
});

You can also look into Chai promises library, which is meant for handling async expects.

appu
  • 36
  • 1
  • 6
  • Also if you have asserts waiting for multiple promise objects to resolve then it would be better to use libraries like async.js to properly call the "done" callback. – appu Mar 10 '17 at 19:50
  • This was the issue thanks! I'll take a look at using mocha/chai again and see if it would be better. – dittmanc Mar 10 '17 at 20:58