Can anyone help get me started on how to use RobotFramework to validate json responses via a json-schema?
Ideally, the json-schema is externally referenced via an http request: Example http://api-bl-uk.northeurope.cloudapp.azure.com/api/v1/crm/schemas/contact
Progress so far:
pip install robotframework pip install robotframework-jsonvalidator pip install robotframework-jsonschemalibrary robot .\mytest.robot
Where mytest.robot is:
Library JsonValidator
Library JSONSchemaLibrary schemas
*** Test Cases ***
My Test Case:
Validate Json service.schema.json {"foo": "bar"}
I have a schema in the subdirectory schemas called service.json
When I run the test I get...
$ robot .\mytest.robot ============================================================================== Mytest ============================================================================== My Test Case: | FAIL | No keyword with name 'Validate Json' found. ------------------------------------------------------------------------------ Mytest | FAIL | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed ============================================================================== Output: E:\GitLab\customer-api\test\output.xml Log: E:\GitLab\customer-api\test\log.html Report: E:\GitLab\customer-api\test\report.html
So it seems I'm missing a fairly basic piece of the puzzle:
No keyword with name 'Validate Json' found
UPDATE
The problems of blindly following 'sample code'
The problem was I was missing the *** Settings *** header prior to the Library statements, plus the name of the schema to use was wrong (easy to solve after the header was fixed).
Full example:
*** Settings ***
Library JSONSchemaLibrary schemas
*** Test Cases ***
My Test Case:
Validate Json service.json {"foo": "bar"}
Now... How do I use external referenced schema files? The quest continues!
:)
JsonValidatorcommented - it has a method_validate_json, which might cause a conflict with the method/keywordvalidate_jsonyou're trying to call from the other library. Don't know will that fix it, trying a lucky shot after checking the libs sources.