APITesting with OpenApi Specification file

Hello,

What is the best library to API testing given the fact you want to use OpenApiSpecification files? (in yaml format in a specific scenario)

Do you use Open Api Driver? GitHub - MarketSquare/robotframework-openapidriver
Do you combine it with RestInstance or requestsLibrary?
Or do you just import the yaml file in the settings session as Variables file.yaml to use the datas in it?

Thank you

@robinmackaij

What the OpenApiDriver library will do is, based on the information in the openapi document, generate a test case for each endpoint + method + status_code. For each of these, it will automatically generated the required data (a valid url, valid parameters, valid body) based on the schema in the openapi document and then perform the operation.

If you want to get a feel for what’s happening “in the background”, what you could do is to use the Test Endpoint keyword in your Test Template and just let it run without ignoring any endpoints. In the logs, you’ll be able to dig down into the keywords. If you set the log level to TRACE , the Robot Framework will also log incoming parameters and return values for all keyword calls, so what you’re trying to Log in your Execute Get keyword, is already being logged at TRACE level by the framework.

Since this is a data-driven scenario, combining it with RESTinstance / RequestLibrary does not make much sense, since whatever you do with those libraries, will repeated for each generated test case.

Directly importing the openapi.json / openapi.yaml is not possible, Robot Framework won’t be able to interpret it. You could use a package like prance to parse it to a dictionary (like I do in OpenApiDriver) but you’ll still only have a dictionary that you’d need to do something with. You could look at the keyword documentation / implementation of OpenApiDriver to get an idea about what’s possible.


To add to that, I’m in the process of extracting the generation logic from the library to release that as a core that other libraries can build on. That will allow for libraries like RESTinstance / RequestLibrary specifically for OpenAPI that can do request based on only partial information passed by the person writing the test cases (since missing information can be generated based on the information in the openapi document).

3 Likes