Using the Environments Override When The HOST doesn't determine the environment
Hey!
This is a little confusing - so I'm going to try and be as clear as I can - I'll add visual aids :)
Within my ReadyAPI! project I have maybe 18 REST Services with various resources, methods and requests.
I have 3 different environments - dev, test and integration (see screenshot entitled Capture4.png), so rather than duplicate the tests (1 copy of the tests for each environment) I'm using the Environments override which allows you to specify which host is peculiar to which environment.
My MS Dynamics CRM has 3 instances - 1 for dev, 1 for test, 1 for integration - see below:
https://whatevs-dev-exp.crm4.dynamics.com/ = dev https://whatevs-test-exp.crm4.dynamics.com/ = test https://whatevs-integration-exp.crm4.dynamics.com/ = integration
This is fine and works great for 17 of the 18 REST Services - but doesn't work for 1 of them. The 1 relevant REST Service is not used to test - but it's a setup testcase to generate the access token my actual tests need to get through the authorization/authentication.
The 1 REST service that is my setup service (to generate the access token to hit the CRM's via the webAPI (to hit the CRMs listed above)) is described below and the request (both host and the URI string) is identical for each environment - e.g.
https://login.microsoftonline.com/someGUIDvalue/oauth2/token
So - rather than the 'host' (or even the URI string) determining what environment is being used - its the content of the payload (e.g. resource, client_id and client_secret) that provides the details allowing the actual tests to hit the CRM successfully.
The https://login.microsoftonline.com/someGUIDvalue/oauth2/token request's payload for the 'test' environment is as follows:
resource=https://whatevs-test-exp.crm4.dynamics.com &client_id=d86d999-f520-4708-946a-e013d5f12ff0 &client_secret=Cep6ZhZoYV%2F385ia%2FGCJWWW9X7ryu8u3p7GWDr%2BwCww%3D &grant_type=client_credentials
At the moment - I have 3 different testsuites with a single test cases (1 for dev, 1 for test, 1 for integration) containing a single REST request with the above payload (see screenshot entitled Capture.png).
Currently, depending on which environment I'm testing, I disable 2 of the 3 Generate Access Token test cases because I pass the Access Token generated from these environment specific requests to a single Project level property and all the tests in my project point to this single Project property for the Authorization header value in my requests (see screenshots entitled Capture2.png & Capture3.png)
I was wondering if anyone knew how to configure the request in my project so I can use this via the Environments override, but rather than the host determining which environment is being hit, instead its the content of the request determining the environment?
I understand that part of the problem is that I've setup the saving of the Access_Token to a single Project level 'Authorization' property, so when my setup test executes to generate the token - it overwrites the previous token value and all my tests point to that single project level property meaning that I always have the latest token (as long as I execute the correct environment specific setup testcase to generate the token).
I did consider having the 3 environment specific Access Token generation tests writing to 3 individual project level properties (e.g. CRM_Token_Test, CRM_Token_Dev and CRM_Token_Integration) - 1 for each environment - but I can't see an efficient way of pointing my tests to the correct access token property. (remember - each of my tests has a POST which needs the correct access token value)
Have any of you come across something like this before where it was the payload that provided the project specific detail and so no easy way to use the Environments override? If I enable all 3 access token test cases - the last one in the sequence will overwrite the others - so that won't work.
I need to get this ReadyAPI! project into a CI/CD pipeline sooner or later - so I need everything to be automated as possible - I can't be manually changing things (like enabling and disabling testcase/testsuites) each execution run to pick the correct testsuite to run depending on which environment I need to execute the tests in.
I'd welcome any thoughts anyone has on this, cos I just cant see a way forward. Strictly speaking I can see why this doesn't work for this access token request - the request runs in all environments - the request isn't environment specific - its just the payload of the request that determines the environment specific token and my problem is that I only have 1 project level property - I just can't see a more efficient way of doing this.
I hope I've been clear..... :)
cheers,
rich
Provide payload as below
resource=${#Project#RESOURCE} &client_id=${#Project#CLIENT_ID} &client_secret=${#Project#CLIENT_SECRET} &grant_type=client_crendentials
You can define property file as show below, and create a file for each enrionment.
dev.properties
RESOURCE=<dev-resource> CLIENT_ID=<dev-client-id> CLIENT_SECRET=<dev-client-secret>
And import the above file at project level, refer below documentation
https://www.soapui.org/scripting-properties/working-with-properties.html
So, you can similarly, use properties for END POINTS / other varying values per environment into property file and use them in the project as mentioned in the payload content.
Now all you need is single project, common test cases. No separate test suites / test cases per environment any more, just use appropriate property file, import them into project before running the tests.
If you are running the tests command line, even properties can be directly loaded runtime without even modifying the existing values in the project.