API Architecture - GeekyAnts/ga-wdio GitHub Wiki
- The design contains
/src/
which contains all the necessary files for the boilerplate, and this folder contains directories like constants, containers & libraries. -
src/api.js
file is the main app our runner looks for fetching all the necessary configurations & list of API(s) details. -
src/constants/
folder is the main folder where the project's source configurations are located. -
src/containers/
folder keeps containers, meaning all of the APIs. -
src/libraries/
folder will have all the helper modules & store details files.
└── src
├── constants
│ └── index.js
├── containers
│ └── employee (sample)
│ ├── index.js (sample)
│ ├── list.js (sample)
│ └── single.js (sample)
├── libraries
│ └── store.js
└── api.js
Based on API Object Model, meaning it is based on API by API test execution & therefore we have divided things into sub-folders for easy test management.
-
The API needs two details to execute the tests, and those are domains & apis.
-
domains
- Domains object is actually a key-value paired, where we require default index & you can add more indexes into the same object
api.domains = { default: "https://geekyants.com/", // DEFAULT index is REQUIRED! download: "https://dl.geekyants.com/" // OPTIONAL indexes... };
-
apis
- Requires an array of API container modules that would be tested, and the sequence of apis given would be the sequence of their execution.
api.apis = [ require("path/to/containers/api"), require("path/to/containers/api") ];
-
store
// How it works? // Step #1: Create a Store (Object returning file) if not exists // Step #2: Register store into the api.js file api.store = { token: undefined // undefined is just a default value! }; // Step #3: Capture the variable (for eg. token) from response's body expected.store = { token: "body.data.jwtToken" }; // Step #4: How to use the store variable now? // // I am using the token in the headers of index API below & to access // that token you have to use special syntax ie. [<index-name>]. // Note: token is same as given in the Step #2 while registering the API app. index.headers = { "Content-Type": "application/json", "Authorization": "Bearer [token]" };
-
Index | Is Required | Comment |
---|---|---|
name | No | Name of your API, just for the reporting purpose |
domain | No | Domain for your API, incase you don't provide this index we will use the default domain given in api.domains |
uri | Yes | URI for the API request |
method | Yes | The HTTP protocol method for the API |
query | No | Can be used only with the GET/HEAD method request |
body | No | Can be used only with the POST/PUT/PATCH method request |
timeout | No | Max API request timeout |
headers | No | Request headers that would override our default request headers |
expected | No | To check the response with the expected set of rules |
expected.headers | No | To check the response's headers & their value |
expected.body | No | To check the response's body indexes |
expected.store | No | To store something from the response's body into the store that you can use in other API |