Mahendra Seervi
Mahendra Seervi

Reputation: 15

How to Assert or Verify Multiple Required Error message at the time on selenium webdriver

Problem Description:

I want to verify a Blank Input field Required Error message should be displayed or not. Example like that. I have Web Element

<div _ngcontent-c4="" class="red-text text-darken-4 fs-0--8">First Name is required</div>
<div _ngcontent-c4="" class="red-text text-darken-4 fs-0--8">Last Name is required</div>
<div _ngcontent-c4="" class="red-text text-darken-4 fs-0--8">Phone Name is required</div>

These Error message I want to verify at the time all message assert or not.

Can you please help me how to assert all error message at the time using selenium web driver.

Upvotes: 0

Views: 2717

Answers (2)

Devdun
Devdun

Reputation: 767

If you want to test all assert at once then you have to add softAssert in your code this will give you final results after check all the fields. If not when assert failed happens (Assume First name error is invalid) system will throw assertion error after it.

        SoftAssert softAssert = new SoftAssert();
        String ActualErrorMEssage = firstNameerrorXpath.getText;
        String ActualErrorMEssage2 = secondNameNameerrorXpath.getText;
        softAssert.assertEquals(ActualErrorMEssage,ExpectedErrorMEssage);
        softAssert.assertEquals(ActualErrorMEssage2,ExpectedErrorMEssage);
        softAssert.assertAll();

Upvotes: 3

Kaushik
Kaushik

Reputation: 150

If you can see all the error messages, when you don't enter anything into the text boxes and click on submit or register, you can get text of all this error messages and assert them. But, if your website functionality is like let's say when you don't enter anything it shows only error for the first name field and all the other UI error's are not being shown, then you can't verify all the error messages at a time.

If all the error messages are shown at once, you can take them into a arraylist and by using Assert.assertEquals(expectedArray,actualArray), you can assert everything at once.

Upvotes: 0

Related Questions