I have faced with the strange assertions problem so even successful assertions are marked as failed, like this:
this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eventually.be.true.and.notify(next);
and in the console I have:
1 scenario (1 passed) 4 steps (4 passed) 0m03.618s [17:06:38] E/launcher - expected [ true ] to be true [17:06:38] E/launcher - AssertionError: expected [ true ] to be true
As you see in this case test marked as successful despite of failed assertion, but in case when after 'failed' assertion there is another one the whole thing will be failed.
I'm using the last versions of protractor and chai.
It seems like this.getWidget('contacts').isNamesDisplayed()
is returning an array value [true]
instead of true
. you need to change your expect statement as below.
this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eql([true]).and.notify(next);
The accepted answer is great. The accepted answer reiterates the complaint from Protractor, which is frustrating but very clear:
... returning an array value [true]...
Apparently that is the behavior of the OP's function isNamesDisplayed
. But there may be other reasons:
In my case, I accidentally used $$
, instead of $
, and I was expect($$('div.to-test').isDisplayed()).toBe(true)
. $$
is a "Shorthand function for finding arrays of elements by css" .
So be aware that one character, $
, could be the cause of (and solution to) all life's problems: expect($('div.to-test').isDisplayed()).toBe(true)
,
(or as the accepted answer says, you could just... "change your expectations" :) )
expect($$('div.to-test').isDisplayed()).toBe([true]);
Maybe makes more sense for something you actually expect to repeat,for example the <li>
list items in a <ul>
expect($$('ul.to-test li').isDisplayed()).toBe([true, true, true]);
来源:https://stackoverflow.com/questions/39575594/assertionerror-expected-true-to-be-true