Forum Discussion
johny2010_1
15 years agoContributor
Hi Allen,
To get response body of a test, I need some help.
by using the method described in the help, I can get the response body of any request in the task
For getting response of the test results, the help gives a script example code as below
I need the definitions of Sender, User here. Where they come from and How will I sue them ?
I created some event helper, and next what I have to do in order to run this script ? Any idea?
function GeneralEvents_OnLoadTestingResponse(Sender, User, Request)
{
var FileName, BaseLineName;
// Checks whether the event is generated for the desired request
if(Request.RequestID == 2)
{
// Make up the name of the file that will hold the response contents
FileName = "C:\\Response_User" + User.Name +
"_Request" + aqConvert.VarToStr(Request.RequestID)+ "_" + _
aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%Y%m%d%H%M%S") + ".dat"
// Saving the response contents to a file
Request.ResponseBody.SaveToFile(FileName);
// Comparing files
BaseLineName = Files.NameByFileName("C:\\ResponseToCheck.dat");
if(! Files.Compare(BaseLineName, FileName))
{
// Report about an error
Log.File(FileName, "The response to the request " + _
aqConvert.VarToStr(Request.RequestID) + " for the user '" + User.Name +_
"' is invalid.", "File name: " + FileName, 500);
}
else
// Delete the file if the response is correct
aqFile.Delete(FileName);
}
}
----------
Best Regards,
To get response body of a test, I need some help.
by using the method described in the help, I can get the response body of any request in the task
For getting response of the test results, the help gives a script example code as below
I need the definitions of Sender, User here. Where they come from and How will I sue them ?
I created some event helper, and next what I have to do in order to run this script ? Any idea?
function GeneralEvents_OnLoadTestingResponse(Sender, User, Request)
{
var FileName, BaseLineName;
// Checks whether the event is generated for the desired request
if(Request.RequestID == 2)
{
// Make up the name of the file that will hold the response contents
FileName = "C:\\Response_User" + User.Name +
"_Request" + aqConvert.VarToStr(Request.RequestID)+ "_" + _
aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%Y%m%d%H%M%S") + ".dat"
// Saving the response contents to a file
Request.ResponseBody.SaveToFile(FileName);
// Comparing files
BaseLineName = Files.NameByFileName("C:\\ResponseToCheck.dat");
if(! Files.Compare(BaseLineName, FileName))
{
// Report about an error
Log.File(FileName, "The response to the request " + _
aqConvert.VarToStr(Request.RequestID) + " for the user '" + User.Name +_
"' is invalid.", "File name: " + FileName, 500);
}
else
// Delete the file if the response is correct
aqFile.Delete(FileName);
}
}
----------
Best Regards,