Forum Discussion
What I did understand from your initial question, you have one test suite, under that two testcases, so trying to store requests and responses from both testcases into respective folders in local directory and at test suite level.
I didn't get what exactly you mean to say saving request and responses at suite level.
As per my understand, your REST project structure(Just an example) looks like below(Correct me if I'm wrong)
Project
TestSuite
TestCase(Customer)
RESTRequest1
Groovy1
RESTRequest2
Groovy2
TestCase(salesrep)
RESTRequestsr1
Groovysr1
RESTRequestsr2
Groovysr2
If my understanding is correct, below code helps to store request and responses from all testcases to respective folders. And I would suggest to keep this in test suite teardown script, so it automatically store after completion of testcases execution(Please refer attached image)
Code:
def testSuiteFolder = "C:/Users/SS/Desktop/proj/"+ testSuite.name + '_' + System.currentTimeMillis() + File.separator
new File(testSuiteFolder).mkdirs()
testSuite.testCaseList.each {
def testCaseFolder =testSuiteFolder+"//"+"${it.name}"
new File(testCaseFolder).mkdirs()
if(it.name == "Customer"){
it.testStepList.each {
def request = new String (it.getTestRequest().getResponse().getRawRequestData())
def response = it.getProperty('Response').getValue()
def requestFile = new File(testCaseFolder+"//"+it.name+"request.txt")
def responseFile = new File(testCaseFolder+"//"+it.name+"response.json")
requestFile.write(request)
responseFile.write(response)
}
}else if(it.name == "SalesRep"){
it.testStepList.each {
def request = new String (it.getTestRequest().getResponse().getRawRequestData())
def response = it.getProperty('Response').getValue()
def requestFile = new File(testCaseFolder+"//"+it.name+"request.txt")
def responseFile = new File(testCaseFolder+"//"+it.name+"response.json")
requestFile.write(request)
responseFile.write(response)
}
}
}
Note: It will work perfectly, if all test steps are REST Requests , if testcases have any other steps(EX:Groovy script, data source, data source loop, etc..) it might throw error, because code looks for request and response of each test step. If we have any other steps have to handle with test step type condition.
Hi Redde,
Thanks for your help. Now I am able to retrieve the request. I modified the below code and want to verify whether all the requests and responses are generating for all the test cases. In the below script I removed if -else statement and as per your suggestion i have placed it on test suite level tear down script.
Code :
def testSuiteFolder = "C://Users//sreddy40//Desktop//proj//"+testSuite.name + '_' + System.currentTimeMillis() + File.separator
new File(testSuiteFolder).mkdirs()
testSuite.testCaseList.each
{
def testCaseFolder =testSuiteFolder+"//"+"${it.name}"
new File(testCaseFolder).mkdirs()
it.testStepList.each
{
def request = new String (it.getTestRequest().getResponse().getRawRequestData())
def response = it.getProperty('Response').getValue()
def requestFile = new File(testCaseFolder+"//"+it.name+"request.txt")
def responseFile = new File(testCaseFolder+"//"+it.name+"response.json")
requestFile.write(request)
responseFile.write(response)
}
}
I am getting request and response for the first test case and first test step. Am i doing anything wrong please let me.
For your information we have project structure as below :
Project
Test suite
customer testcase1
test step1(REST request)
test step2 (REST req)
customer testcase2
test step1(REST req)
test step2 etc (REST req)
Sales test case1
test step1 (REST req)
test step 2 (REST req)
We have REST requests as below:
POST,GET,PATCH,DELETE,
I verified soapui the below error message is displaying :
Sat Oct 24 04:03:01 EDT 2020:ERROR:An error occurred [No signature of method: com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfersTestStep.getTestRequest() is applicable for argument types: () values: []], see error log for details
I am getting below error in error log:
Sat Oct 24 06:14:09 EDT 2020:ERROR:An error occurred [No signature of method: com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfersTestStep.getTestRequest() is applicable for argument types: () values: []], see error log for details
Related Content
- 6 years agopankajmalinda
- 7 years agoKate
- 7 years agomoolickj
- 9 years agomaximojo
Recent Discussions
- 4 days agominhng