Forum Discussion
Hi Redde,
Thanks for your reply. I gave try with the below code. I created a new test case at last and added a test step as a groovy script. During the execution using the test suite editor, groovy script also executed. But it is not retrieving all the test case details. It is leaving around 4 to 5 and displaying test step name, test case name. We are not getting request and response.
- Fri Oct 23 12:36:25 EDT 2020:INFO:Test Step1
- Fri Oct 23 12:36:25 EDT 2020:INFO: --NO Request
- Fri Oct 23 12:36:25 EDT 2020:INFO: --NO Response
- Fri Oct 23 12:36:25 EDT 2020:INFO:TestStep2
- I have modified the code to display response also.
- def res=context.expand('${V6GetPackageAttributeList#Response}')
- log.info(res)
- But it is not displaying the request as well as response.
Thanks.
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.
- ChrisA4 years agoContributor
Hi,
Have another look at PrathapR reply, he mentions....
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.
Your error is what PrathapR warned about...
No signature of method: com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfersTestStep.getTestRequest() is applicable for argument types: () values: []]
You can easily work out what the class is. Here is an isolated example that runs through a test suite that prints what type the step is and then a message indicating whether it is a step you want to write (or not).
testSuite.testCaseList.each { it.testStepList.each { log.info(it.toString()); // This shows us the class name of the step. if (it.toString().contains("wsdl.teststeps.WsdlTestRequestStep")){ log.info("Got a test request. Write this one down"); // Do your stuff here..... } else { log.info("Not a test request step, ignore...."); } } }
In short, you're not far off. Look at the above then see where to apply the 'if' in your script.
- ChrisA4 years agoContributor
Hi,
Maybe for your purposes, you need to test whether the step is 'RestTestRequestStep'. I knocked up the example in a SOAP, not REST project. I think 'RestTestRequestStep' are the ones you're looking for.
As for property transfer steps, I've never used them, but I don't think they are typical request/response like steps. They just help the test 'move' values from one step to another.
- PrathapR4 years agoFrequent Contributor
Thank you for your compliment ChrisA,.
PFB the code. I hope this solve all issues. Let me know, if you see any other issues.
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{
if (it.toString().contains("wsdl.teststeps.RestTestRequestStep")){
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 {
}
}
} - Sirisha20204 years agoContributor
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
- Sirisha20204 years agoContributor
Redde,
Good day. I am not getting the test suite level requests and responses. As I mentioned earlier , it is running only for 1st test case and 1st test step. Could you please look into the code in my previous reply.
Thanks,
- Sirisha20204 years agoContributor
Hi Chris,
Thanks for your help on this. I ran the below script. I am getting below response in script log:
- Mon Oct 26 07:56:49 EDT 2020:INFO:com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep@2a51a550
- Mon Oct 26 07:56:49 EDT 2020:INFO:Not a test request step, ignore....
- Mon Oct 26 07:56:49 EDT 2020:INFO:com.eviware.soapui.impl.wsdl.teststeps.PropertyTransfersTestStep@39d045f1
- Mon Oct 26 07:56:49 EDT 2020:INFO:Not a test request step, ignore....
- Mon Oct 26 07:56:49 EDT 2020:INFO:com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep@4719db1
- Mon Oct 26 07:56:49 EDT 2020:INFO:Not a test request step, ignore....
- Is there any way to get the request and response for Property Transfers test step. We have dependency on this test step to proceed further.
- Thanks a lot Chris and Redde for helping me on this.
- Sirisha20204 years agoContributor
Hi Redde,
I am still facing some issues. We have test suite having around 100 + test cases. In which request and response is generating for 7 test cases. It is not generating for the remaining test cases. I tried to remove failed test cases to verify whether the script works fine for pass test cases. But no luck. it is not creating the test cases after 7 test cases. I am attaching the SOAP UI Log, error log as well as request type details( REST request which the other day Chris has asked me to check the type of request by providing the code). Please look into this.
Please find the errors as below:
Tue Oct 27 06:51:55 EDT 2020:ERROR:nu.xom.MalformedURIException: Double slash (//) in path
nu.xom.MalformedURIException: Double slash (//) in path
Tue Oct 27 06:54:47 EDT 2020:ERROR:java.lang.NullPointerException: Cannot invoke method getRawRequestData() on null object
Please find logs in the attached docs.
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{
if (it.toString().contains("wsdl.teststeps.RestTestRequestStep"))
{
def request = new String (it.getTestRequest().getResponse().getRawRequestData())
def response = it.getProperty('Response').getValue()
def requestFile = new File(testCaseFolder+"/"+it.name+"request.doc")
def responseFile = new File(testCaseFolder+"/"+it.name+"response.doc")
requestFile.write(request)
responseFile.write(response)}
else {
}
}
}I have removed "//" in the path. I did not change anything apart from this. As I was getting the error Double slash (//) in path.
Thanks.
Related Content
- 6 years agopankajmalinda
- 7 years agoKate
- 7 years agomoolickj
- 9 years agomaximojo