Search code examples
testingautomated-testse2e-testingtestcafeassertion

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?


Solution

  • 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")