How to customize the error message when an assert fails

340 views
Skip to first unread message

sagdeoa

unread,
Aug 18, 2021, 6:50:46 AM8/18/21
to robotframework-users
Hi,

I am trying to test API using the REST library.

To verify the response code I use
Integer              response status            201

When my assert fails it gives an error message which is not very user-friendly.

Is there any way that I can customize the error message?

Regards
A.

Tatu Aalto

unread,
Aug 19, 2021, 12:56:17 AM8/19/21
to sag...@gmail.com, robotframework-users
Hi

In some library keywords it's possible to provide custom error message as an argument to the keyword. But if you don't see that in the keyword documentation, then it's not easily possible. 

-Tatu
Send from my mobile

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/a542cb67-66c4-4c75-9cf4-5b4fd239d1a9n%40googlegroups.com.

Arundhati Sagdeo

unread,
Aug 19, 2021, 1:00:23 AM8/19/21
to Tatu Aalto, robotframework-users
Thanks for your response. 

Dave Amies

unread,
Aug 21, 2021, 10:37:43 PM8/21/21
to robotframework-users
you could always wrap the library keyword with your own that uses the builtin keywords to return a custom error:

- Use Run Keyword And Return Status to run the library keyword and detect if it passed or failed 
- then use either Run Keyword If or Run Keyword Unless to call Fail which will let you set your custom error

A bit of effort for a custom error message, but if its that important it's always possible.

Hope that helps,

Dave.

Reply all
Reply to author
Forward
0 new messages