ak0032803
14 years agoContributor
How to get Test Steps names in Scripts
Hi All,
I am trying to save response for my test request into a file.
I have mulitple test requests for which i need to store responses.
e.g. I have two test request in my test cases as
Step 1 - Check Data_Positive_Scenario
Step 2 - Check Data_Negative_Scenario
After running these two request i am storing response in file for each step using following code
Is there any way so that I dont need to put test request name manually?
i am expecting something like when the test case will run for all test requests my sript will store response for each request automatically.
I am trying to save response for my test request into a file.
I have mulitple test requests for which i need to store responses.
e.g. I have two test request in my test cases as
Step 1 - Check Data_Positive_Scenario
Step 2 - Check Data_Negative_Scenario
After running these two request i am storing response in file for each step using following code
def StepNames = "Check Data_Positive_Scenario"
def Path = "C:/.../Test/"
//Call Method to save response
SaveMyResponseToFile(StepNames , Path )
//Save Response to file with current date and time
def SaveMyResponseToFile(StepName, FilePath){
date = new Date()
dateFormat = new java.text.SimpleDateFormat('yyyyMMdd-kkmmss')
shortDate = dateFormat.format(date)
respFilename = shortDate + "-" + StepName + "-response.xml" // implicitely returned
log.info("File Name Generated--" +respFilename)
def file_Name ;
file_Name = FilePath + respFilename
def File = new PrintWriter (file_Name)
log.info("After Filaname" + file_Name)
def response = testRunner.testCase.testSteps[StepName].testRequest.response.contentAsString
log.info("Response Written")
File.println(response)
File.flush()
File.close()
if (log.isInfoEnabled())
log.info("Saved response in file: " + respFilename)
}
Is there any way so that I dont need to put test request name manually?
i am expecting something like when the test case will run for all test requests my sript will store response for each request automatically.