In the below code ‘ScenarioName’ represents the test case name and ‘DeviceID’ as input parameter, while fetching response. Now I need to crosscheck each field of the response data with the field that are given in the input csv. So if it gets matched then only we will say the result is pass or else fail..
Code as of now:(It just hit the service and write the response in result CSV. But before writing it in resultant CSV, we need to validate whether all the field in the response are gets matched corresponding to the value for that particular scenario specified in the input CSV, only then we would come to a conclusion. whether the test case is pass or fail. )
Beanshell post processor code:
scenario = vars.get("ScenarioName");
deviceid = vars.get("DeviceID");
eventname = vars.get("C_EventName");
eventtype = vars.get("C_EventType");
areaName = vars.get("C_AreaName");
n = vars.get("counter");
filename = "C:\\RestService\\"+ n +".csv";
f = new FileOutputStream(filename, true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print( scenario + ", " + etrTimestamp + ", " + eventname + ", " + eventtype + ", " + areaName + ", " + areaType + ", " + additionalInfo + ", " + resultStatusCode + ", " + resultStatusMessage);
f.close();
Now My input file:
ScenarioName DeviceID Execution
Validate event 52226406 Yes
invalid ID 11501233 Yes
But input file should be:
ScenarioName DeviceID Execution EVENTNAME REsultCODE
Validate event 52226406 Yes Hurricane 200
invalid ID 11501233 Yes Tornado 404
Now my Output is:
ScenarioName DeviceID Execution EVENTNAME REsultCODE
Validate event 52226406 Yes Hurricane 200
invalid ID 11501233 Yes Tsunami 404
But It should be:
ScenarioName DeviceID EVENTNAME REsultCODE Result
Validate event 52226406 Hurricane Event Pass
invalid ID 11501233 Tsunami 404 Fail
So let’s say for DeviceID 52226406 if we are validating the test case, then we would say the result as pass only if all the fields exactly match with data present in the input csv….But For DeviceID 11501233 Event type should be Tornado But in response we are getting as Tsunami so it should fail(After we match with the input CSV) What should my code and how?