Skip to content
Advertisement

Selenium web driver assert webelement contains text and display actual vs expected

I have a demo selenium cucumber project that just runs some maths expressions in google search box and validates the results.

I want the reports to show the actual value vs expected when it fails.

I’m storing the returned text as string with ..

JavaScript

and then asserting against expected which gets passed from my feature files with …

JavaScript

but the reports show …

JavaScript

I want it to display the actual expected result vs actual i.e.

JavaScript

I’ve also tried …

JavaScript

I’m using … org.testng.Assert

Thanks

Advertisement

Answer

With the assertion you can use your customized error text. Something like this:

JavaScript

Or this

JavaScript

In case of non-equal parameters it will present you output like this for the first case:

java.lang.AssertionError: Expected: expectedResult but found resultText
Expected :expectedResult
Actual :resultText

And for the second case:

java.lang.AssertionError: Expected: expectedResult but found resultText
Expected :true
Actual :false

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement