How create a single test suite to support multiple environment with assertion
Hi all, I am new to API automation with ReadyAPI. Great if anyone could advice me on below scenario with the industry best practices.
I have a requirement to create an API regression test suite which will supports multiple environments(Dev, UAT, Pre-Prod etc).
My question is, is that possible to create a single test suite which can be executed in different environments with assertions according to the environment if not what is the best approach?
Ex: There is an API to retrieve person data. I want same to be executed in different environments and also assert the data based on the environment and also change the request data automatically when the environment is changed.
Thanks in advanced 🙂
Solved! Go to Solution.
However, IMO, the test request and response and assertions would be the same.
Would you please provide the use case with the details how it is different ?
Thanks Rao for the reply.
I have tried the Environment feature but what it does is change the your base URL and I couldn't find a way to change the test data and assertions based on the selected environment.
There is an API to retrieve person data. I wanted to run the same in Dev, UAT and pre-prod environments. But the databases are different(dev person id- 100 is different with UAT person id- 100(two different persons)). As a result of it , the name I wanted to assert in dev is different with the name in UAT.
Therefore I just wanted to know whether it is feasible to do this with a single Test suite or I need multiple suites for each environment since the databases are different.
Yes this is totally feasible and in fact is the way i build all my readyapi projects now.
The way i do this is that i create a ptoperties file that contains my environment specific static data, such as URLS, token values, username/password values and within this properties file i have placeholder property names (without the values populated) for all my dynamic data that is environment specific such as GUIDs etc.
I create one of these properties files for each environment.
Before execution i determine which environment is being tested and i then load in the properties file (which creates custom project level properties....as i already stated...the static data properties and values specific to the environment and empty/blank custom project level property placeholder names).
Once the file is loaded in, i then have some disabled testsuites that execute queries against the environment to populate those dynamic data values (that are environment specific).
Within my project i then create my normal functional testsuites (that are enabled) to exercise my tests, but the first testcase includes a single "Run Testcase/teststep" that executes the disabled testcase that generates the dynamic data (this wa the dynamic testdata never has the chance to expire). The remainder o my testcases are normal testcases except they alwaya reference the custom level project level properties for the all environment specific detail.
The above works really well and do it or every single readyapi project i create now. Alas i cant take credit for this approach. It was @nmrao who showed me how to do this and it works like a charm.
Obviously this cant be the only way of doing this, but this approach works so well for me, ive never bothered using any other or even learning any other approach.
@richie Thanks for your detail explanation.
Could you please let me know how the assertions are implemented in your case?
Thanks in advanced.
Regarding data difference on different environments, have a follow up question.
Isn't that you create data, then query it? If you do so, then the same suite can be used with same assertions.
Also understand that it may not be allowed or not possible to create or update while data can be queried. Is it your use case?
Still there is possibility to use single suite. Here I can think of data (including request/response along with data to be verified) separation into different data files per environment. Use a property for the data file name, read that data and used these values for sending request and in the assertions as well.
NOTE: the above approach doesn't require to use Environments feature yet it is simple and flexible.