Sudeepthi
Sudeepthi

Reputation: 494

Want a new line(\n) element in Assert.AreEqual()

When I haven't entered any username and password and click on login, I'll get message:

The username field is required.

The password field is required.

They are in unorderedlist in HTML.

In the code I'm using

Assert.AreEqual("The Username field is required.\nThe Password field is required.",
        loginPage.ValidationMsgText,
        "Error at Validaion message with no credentials");

but it is always failing the test case.

I also tried

Assert.IsTrue(loginPage.ValidationMsgText
        .Contains("The Username field is required.The Password field is required."));

but it didn't work. I'm new to automation and need some help.

My HTML:

<div class="validation-summary-errors" data-valmsg-summary="true">
    <ul>
        <li>The Username field is required.</li>
       <li>The Password field is required.</li>
    </ul>
</div>

Is there a better way?

Upvotes: 2

Views: 2322

Answers (1)

Piotroslav
Piotroslav

Reputation: 262

Assert.IsTrue(
loginPage.ValidationMsgText.Contains("The Username field is required.") &&
loginPage.ValidationMsgText.Contains("The Password field is required.")
);

Also, while debugging, you can verify actual value of ValidationMsgText and use the corresponding char. (Maybe instead of /n it would be better to use Environment.NewLine)

Upvotes: 2

Related Questions