Search code examples
javascriptseleniumselenium-webdriverjasminejasmine-node

Jasmine-node assertions within promises not shown


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.


Solution

  • 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.