Closed sqilz closed 6 years ago
You can use JSON Schema keyword pattern
for testing if a JSON string contains something:
*** Settings ***
Library REST
*** Test Cases ***
Use JSON Schema keyword pattern to test JSON string for substrings
[Setup] GET https://jsonplaceholder.typicode.com/users/1
# matches "Leanne Graham" as a substring:
String response body name pattern="anne Grah"
# quotes are not necessary, it is still read as a string by the library:
String response body name pattern=anne Grah
# pattern supports regular expressions:
String response body name pattern=(sqilz|Leanne Graham)
# checking that 'name' does not contain the word:
String response body name pattern=^((?!asyrjasalo).)*$
(pattern ref: http://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5.2.3)
Closing this issue. Please open a new issue if this did not answer the use case, or I missed something. Also apologies for a (very likely) late reply.
wow, that's a cool feature!
seems that it is not documented anywhere in this repo (besides in this issue) ... I just found it by chance because I wanted to check existing issues before filing a new one that I have with the String
keyword.
this pattern feature is definitely worth to be documented ;-)
Written in Robot Framework
The /users/1 name field contains "Leanne Graham"
In a test case