Wake Up! Wake Up! Wake Up!
Hi everyone,
Here is another batch of scripts you can implement within our API Summer 2018. Let me remind you that you can get 2 points for creating new topics where you implement any of these scripts, or for topics where you share your use cases, instructions on how you work with frameworks, or useful advice for testing. So, don’t miss the chance to get 2 points for sharing your ready scripts with the ReadyAPI community!
Enabling/disabling TestCases depending on tags values
Currently, you can pass the -T argument to force TestRunner to run only TestSuites or TestCases with specific tags. At that, if you pass several tags, the items containing all these tags (e.g. tag1 AND tag2 AND tagN) will be run.
Your task is to run TestCases and TestSuites which contain tag1 OR tag2 OR tagN.
For this, create a Project Setup script -
- which checks the values of the TestCaseTags and TestSuiteTags Global Properties (they are passed as command-line arguments and their format is "tag1,tag2,tagN");
- and which disables the corresponding items, which don't contain any of the listed tags.
Dispatching based on the value of Query Parameters
Create a REST virtual service with the "GET /login" resource and add a dispatching script, which returns different responses based on the values of query parameters (grant_type, username and password).
A sample request:
http://localhost:<VIRT_PORT>/login?grant_type=password&username=test&password=Test123!
The dispatching condition:
- If grant_type is not equal to "password", the virt returns the "Unsupported Grant Type" response (HTTP status code is 401, body is {"error": "Unsupported Grant Type"}).
- If grant_type is equal to "password", but the username is not equal to "test" OR the password doesn't comply with the strength requirements (the minimal length is 8 characters, the password contains at least one uppercase letter, one lowercase letter, one number and one symbol) the virt returns the "Invalid Login Info" response (HTTP status code is 401, body is {"error": "Invalid Username or Password"}).
- If some parameters are missing, the virt returns the "Bad Request" response (HTTP state code is 400, body is {"error":"required parameters are missed"})
- If all the parameters have valid values, the virt returns the "OK" response (HTTP status code is 200, body is {"result":"ok"}).
Note: the script should work correctly independently of the parameters order and the existence of any additional query parameters in the request.
Our moderators will review your topics, and, if they add a TechCorner label to them, this will give you 2 points to your API Summer score!
I’m looking forward to your new topics!