How to verify a string on webpage?

I am testing login. Along with the HTTP response I also want to test that the page after successful login has “Welcome” string.
Which check statement should I use for the same?

You can use a regex. E.g.:


Just make sure it’s a string that isn’t also on your login page, or failed logins will still pass.

I am testing invalid login. After trying to login with invalid login credentials, I am getting following text on the login page:

Invalid User Name/Password credentials.

I am checking it with following check:
.check(regex("Invalid User Name/Password credentials.")))

However, the check is failing. What can be wrong here?

Are you sure this text message is actually in the login response, and not already in the page, displayed by some javascript?