Search code examples
jasmineprotractorkarma-runnerkarma-jasminekarma-mocha

how to get the text of bootstrap alert message for testing with protractor


this is my spec

 it('should save edited majorObject', function () {
        var description = element(by.id('objectDescription'));
        description.clear();
        description.sendKeys('edited');
        var add = element(by.id('saveObject'));
        add.click().then(function () {
            expect(element(by.css('.alert-success')).isDisplayed()).toBe(true);
         expect(element(by.css('.alert-success')).toText()).toBe("Saved Successfully");

        })

    });

i used
expect(element(by.css('.alert-success')).toText()).toBe("Saved Successfully");

But it is showing undefined and is their any alternative way to do this?


Solution

  • You meant to use getText() instead of toText():

    expect(element(by.css('.alert-success')).getText()).toBe("Saved Successfully");