Ask a Question

How to get rawrequest and response test step using context or projectrunner variable?

ripplegupta
Contributor

How to get rawrequest and response test step using context or projectrunner variable?

I am iterating through test steps in project event handler and trying to get the raw request for each test step (rest request and jdbc only) with something like below,

 

projectRunner.getResults().each(){
	it.getResults().each() {
	 	it.getResults().each() {
                    it.getTestStep().testRequest.RawRequestData
                }
        }
}

But it is giving me only json body that too with parameterized properties not actual data, after submitting request. I want data that comes up in raw tab . Can somebody suggest what could be the right way?

6 REPLIES 6
ripplegupta
Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

Please anyone help here ?
Radford
Super Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

 

The RawRequest is a test step property, thus accessed via getProperty method. Try something like this:

 

projectRunner.getResults().each(){ testSuiteRunner -> 

	testSuiteRunner.getResults().each() { testCaseRunner ->
		
	 	testCaseRunner.getResults().each() { testStepResult ->
	 	
	 			// Make sure that the test step has properties (not sure if there are any that don't but just being safe).
				if(testStepResult.getTestStep() in com.eviware.soapui.model.TestPropertyHolder){
					log.info('Test step "' + testStepResult.getTestStep().getName() + '" has properties.') 

					// Make sure the test step has a RawRequest property before trying to read it.
					if(testStepResult.getTestStep().hasProperty('RawRequest')){
						log.info('Test step "' + testStepResult.getTestStep().getName() + '" has a RawRequest property.') 
						log.info(testStepResult.getTestStep().getPropertyValue('RawRequest'))
				}
			}
		}
	}
}

 

Regarding the query about parametrised values, the documentation for the rest request test step states:

 

  • RawRequest - Binary request data. The same content you can see in the Raw view of the request editor without headers. Property expansions are converted to expected values.
  • Request - Request data with unconverted property expansions.

 

If you find your experience is different to this I would log a support call with SmartBear

ripplegupta
Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

Thanks Radford, 

 

I will check and get back here with confirmation , thanks for your information.

ripplegupta
Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

Hi thanks Radford, i was able to get raw request with property expansion.

 

but properties like query, header and template are not giving data after property expanison, can you help here ?

 

 

Radford
Super Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

Sorry, never had to do this myself I don't think I can really help further. Try looking at the JavaDocs for the Classes:

 

They may be of some help to you, it's probably where I would start investigating.

 

Please post back here if you find a solution.

ripplegupta
Contributor

Re: How to get rawrequest and response test step using context or projectrunner variable?

Thanks Radford. I was able to solve my last query.

 

Actually i was looking for exact request posted to server for test steps so i looked into junit report collector class which generates report files in xml format having everything. so i used that method which writes to file (i had to create print writer of type string writer to generate string instead of file though)

pw = new PrintWriter( stringWriter )	
		testStepResult.writeTo( pw )

Hope this helps.

cancel
Showing results for 
Search instead for 
Did you mean: