If Env-Variable drawingmanage
equals false
the value gets assigned successfully(else
block) whereas if it is true
the value doesn't assign(if
block)
if(pm.variables.get("drawingmanage") == 'true'){
var stat=true;
modelid.map((data)=>{
data.models.map((modeldata)=>{
checkContainsdrawing(data.projectID,modeldata.modelID).then((datas)=>{
if(datas.json()._isSucceed && stat){
console.log(data)
pm.collectionVariables.set('projectid',data.projectID);
pm.collectionVariables.set('projectname',data.projectName);
pm.collectionVariables.set('modelid',data.models[0].modelID);
pm.collectionVariables.set('modelName',data.models[0].name);
stat=false;
}
}).catch((err)=>{
console.log('failed');
})
})
})
}else{
pm.test("Get Project ID and Project Name", function () {
console.log('No drawing management selected');
pm.collectionVariables.set('projectid',modelid[0].projectID);
pm.collectionVariables.set('projectname',modelid[0].projectName);
});
pm.test("Get Model ID and Model Name", function () {
pm.collectionVariables.set('modelid',modelid[0].models[0].modelID);
pm.collectionVariables.set('modelName',modelid[0].models[0].name);
});
}
checkContainsdrawing Function
let checkContainsdrawing=(projectid,modelid)=>{
const urldata=(projectid,modelid)=>{
return {
url:`${pm.variables.get("url")}api/blm/pdm/drawing?pid=${projectid}&mid=${modelid}`,
method:'GET',
header: {
Authorization: pm.collectionVariables.get('authtoken')
}
}
}
return new Promise((resolve,reject)=>{
pm.sendRequest(urldata(projectid,modelid),(err,res)=>{
if(err){
reject(err);
}
resolve(res);
})
})
}
My test scenario
My main aim is to run the API automation without any testdata so i am using API parameritizing same pattern as the website works coming to explain this test scenario below
- This API lists all the project where the user has access
- Project may or may not contains model
- So here i want to filter the projects which has model
- And again to the model i want to validate whether the model contains a note sheet
- For this i am making request to an API to check whether there is an note sheet to that particular project and model if there i am assigning to a collection variables which will be used in all Test
if
block