ASE
ASE

Reputation: 355

TestCafe assertion fails

I have a problem with .expect method which I cannot find a good solution for. In my test case after a certain step I am clicking on a button. This button-click opens a new page with the error text "Something went wrong". Now I would like to assert on that error text which has the selector body > app > main > div > error-page > div > h1.

But every time this page is opened and the error is shown in the Console I get following error " AssertionError: object tested must be an array, an object, or a string, but undefined given"

I have tested .expect(errorMessage.value).eql('Something went wrong'). I have also tested with .expect(errorMessage.value).contains('Something went wrong') I have also tested .expect(errorMessage.exists).ok() and then "eql"

Any suggestions?

Upvotes: 3

Views: 876

Answers (1)

Marion
Marion

Reputation: 1074

Use Selector to define the errorMessage variable. For example:

const errorMessage = Selector("body > app > main > div > error-page > div > h1") 

or

var errorMessage = Selector("#elementID")

Upvotes: 2

Related Questions