Nightwatch: Difference between expect().text.to.contain() and assert.containsText()

Created on 4 May 2017  Â·  10Comments  Â·  Source: nightwatchjs/nightwatch

Node.js v 7.5,
Nightwatch v ^0.9.15
Selenium-standalone v ^6.0.1

I encountered this problem when using expect.text.to.contain() instead of assert.containsText(). If I entered an empty string, expect will fail the test but assert will pass the test in the same conditions, is this a bug or I misunderstand the behavior of expect and assert.

```
client.expect.element('div.feature-icon.testrunner').text.to.contain("");
✖ Expected element text to contain: "" - expected "contain ''" but got: ""

client.assert.containsText('div.feature-icon.testrunner', "");
✔ Testing if element contains text: "".
```
Thank you in advance, this selectors are from the nightwatch page.

stale

Most helpful comment

@beatfactor it is the exact same bug. Why should I create a new issue? If anything this issue better documents the bug because it contains more testimonials.

All 10 comments

Running into same problem with text.to.contain() when text is a empty string

Ran into the same weirdness with expect.element.text.to.contain failing with expected contain "" but got "" yet assert.containsText works.

Also getting this issue, code and results below:

docs.expect.element('.whats-new').text.to.be("Whats's new");

error:
Expected element <.whats-new> text to equal: "Whats's new" - expected "equal 'Whats's new'" but got: "What's new"

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

This problem still exists with nightwatch 1.0.19

Fails :
browser.expect.element('.title__block > h2').text.to.contain('BOUYGUES')

Pass :
browser.assert.containsText('.title__block > h2', "BOUYGUES")

I am having this issue when using browser.expect.element(selector).text.to.contain(text). The failures do not happen every time - they are intermittent and appear to be random. In my case the strings are not empty, but they are identical and the test still fails sometimes.

The error message logged by Nightwatch makes it look like the strings are different: expected "contain 'string'" but got "string ". This is wrong - the strings are identical. This is clearly a bug in Nightwatch.

I am going to try the suggestion posted in the above comment by @Samuelfaure.

We are using Nightwatch version 1.2.4.

@davidjpfeiffer please open a separate issue.

@beatfactor it is the exact same bug. Why should I create a new issue? If anything this issue better documents the bug because it contains more testimonials.

Same problem here. Has this been fixed?
browser.expect.element(selector).text.to.equal(value) adds an extra 'equal ' to the selected element's value it is comparing to.
Example error: expected "equal '2020'" but got: "2020"

Having kind of similar issue
when i pass string variable to contains it always says undefined
can someone help . ?

example
ids =[
'b9bab3a117e14ef499c8a930ce884e17',
'cd824c74a3f8449088caa38074c62b30'
]

const [first] = ids;
//console.log(first); ----- > prints the first string
workflow.expect.element('@revisionTitleText').text.to.contains( first )

error
expected "contain 'undefined '" but got: "Admin1Last | b9bab3a117e14ef499c8a930ce884e17"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidlinse picture davidlinse  Â·  4Comments

manjero picture manjero  Â·  4Comments

maxgalbu picture maxgalbu  Â·  3Comments

antogyn picture antogyn  Â·  4Comments

jvlaar picture jvlaar  Â·  4Comments