How to use Rest Assured Framework in aiTest
How to use Rest Assured Automation Framework in aiTest.
Knowledge Base for aiTest
Efficiency: Postman collections automate the testing process, allowing for frequent and consistent execution of tests.Early Issue Identification: By testing URLs and APIs early in the development cycle, issues can be identified and resolved promptly.Security Testing: aiTest helps identify security vulnerabilities and risks in the application, leading to improved security measures.Workspaces.

Workspaces option.

Collection option, click on it you will see ‘ + ‘ icon.
Click on “ + “ icon, it will create collection with name “New collection”, you can update it as per your collection name.Add request option in list.

Add request, it will open new drawer to configure request.


Run collection option in list. Select it and configure Run configuration details and Run Collection.Before running the Script in collection, Set following Collection Variables
cognitoClientId :< client id >;authorizationCode :**-4978-99b7-**;congnitoRedirectUri :http://localhost:8080/;cognitoTokenUrl :https://login-marxeed-dev.auth.us-east-1.amazoncognito.com/oauth2/token;cognitoClientSecret :None;cognitoRefreshToken :None;cognitoIdToken :None;cognitoAccessTokenExpiry :None;cognitoAccessToken :None;Cognito option in the serach bar and click on Cognito option.App Integration option.View Hosted UI option.Authorization Code from address bar.cognitoClientId, authorizationCode, cognitoTokenUrl & congnitoRedirectUri with your values.cognitoIdToken variable as value for Bearer Token in Authorization section of each
request in collection.Authorization Code in Collection variable named as authorizationCode.Pre-request Script
var cognitoClientId = pm.collectionVariables.get("cognitoClientId");
var authorizationCode = pm.collectionVariables.get("authorizationCode");
var congnitoRedirectUri = pm.collectionVariables.get("congnitoRedirectUri");
var cognitoRefreshToken = pm.collectionVariables.get("cognitoRefreshToken");
var cognitoIdToken = pm.collectionVariables.get("cognitoIdToken");
var cognitoTokenUrl = pm.collectionVariables.get("cognitoTokenUrl");
console.log(authorizationCode)
console.log(cognitoTokenUrl)
const postRequestwithCode = {
url: cognitoTokenUrl,
method: 'POST',
timeout: 0,
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: {
mode: 'urlencoded',
urlencoded: [{
key: "grant_type",
value: "authorization_code"
},
{
key: "redirect_uri",
value: congnitoRedirectUri
},
{
key: "client_id",
value: cognitoClientId
},
{
key: "code",
value: authorizationCode
},
]
}
};
const postRequestwithRefreshToken = {
url: cognitoTokenUrl,
method: 'POST',
timeout: 0,
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: {
mode: 'urlencoded',
urlencoded: [{
key: "grant_type",
value: "refresh_token"
},
{
key: "redirect_uri",
value: congnitoRedirectUri
},
{
key: "client_id",
value: cognitoClientId
},
{
key: "refresh_token",
value: cognitoRefreshToken
},
]
}
};
console.log(cognitoIdToken)
if (!cognitoIdToken || cognitoIdToken == "null") {
console.log('Tokens are missing from env getting token with code')
pm.sendRequest(postRequestwithCode, function (err, res) {
console.log(err ? err : res.json());
var responseJson = res.json();
console.log(typeof responseJson);
if ( 'error' in responseJson) {
console.log('Error while getting access token by using authorization code', responseJson);
}
else
{
console.log(responseJson);
pm.collectionVariables.set('cognitoIdToken', responseJson['id_token']);
pm.collectionVariables.set('cognitoAccessToken', responseJson['access_token']);
pm.collectionVariables.set('cognitoRefreshToken', responseJson['refresh_token']);
var expiryDate = new Date();
expiryDate.setSeconds(expiryDate.getSeconds() + responseJson.expires_in);
pm.collectionVariables.set('cognitoAccessTokenExpiry', expiryDate.getTime());
}
});
} else if (pm.collectionVariables.get('cognitoAccessTokenExpiry') <= (new Date()).getTime()) {
console.log('Token Expired , getting new id token with refresh token')
pm.sendRequest(postRequestwithRefreshToken, function (err, res) {
console.log(err ? err : res.json());
var responseJson = res.json();
if ( 'error' in responseJson) {
console.log('Error while getting access token by using existing access token', responseJson);
}
else
{
console.log(responseJson);
pm.collectionVariables.set('cognitoIdToken', responseJson['id_token']);
pm.collectionVariables.set('cognitoAccessToken', responseJson['access_token']);
pm.collectionVariables.set('cognitoRefreshToken', responseJson['refresh_token']);
var expiryDate = new Date();
expiryDate.setSeconds(expiryDate.getSeconds() + responseJson.expires_in);
pm.collectionVariables.set('cognitoAccessTokenExpiry', expiryDate.getTime());
}
})
} else {
console.log('Token is valid, using it ')
}