Ask a Question

context values saved to a data sink

BF_14Corp
New Contributor

context values saved to a data sink

I would like to post the value of context parameters requestURI and httpresponseProperties to a data sink for a GET request. 

When I try the below groovy code I get null. any suggestions.

String therequestUri = new String(context.getProperty("requestUri").toString())

 

6 REPLIES 6
mattb
Staff

Hi,

I would use the DataSink Test Step. After you add a property and name you can right click in the data sink value field toDatasink.PNG "get data" and pass properties very easily. 


Data Sink Test Step: https://support.smartbear.com/readyapi/docs/functional/steps/data-sink.html 
Get Data Dialog: https://support.smartbear.com/readyapi/docs/testing/properties/get-data.html 

I have used data sink for many of my projects but cannot find a way to use get data for context, project or environment variables. 

ChrisAdams
Champion Level 2

Hi,

 

You should be able to use a Groovy script to access context and environment variables.  Then, in your datasink, you should be able to call the Groovy script step to pull in the values of interest.

 

Do you have any specific examples?  If so, I can try and find a way.

ChrisAdams
Champion Level 2

In the meantime, here's some examples.  Note these are in a Groovy script step..

 

log.info("Current Environment - ${context.testCase.testSuite.project.activeEnvironment.name}")
log.info("Get the value for Test Case Property called 'TestCaseProp' - ${context.expand( '${#TestCase#TestCaseProp}' )}")
log.info("Get the value for Test Suite Property called 'TestSuiteProp' - ${context.expand( '${#TestSuite#TestSuiteProp}' )}")
log.info("Get the response status code for a named service call - ${testRunner.testCase.testSteps["REST Request"].testRequest.response.responseHeaders["#status#"];}");

 

 

Apologies for several messages.  I can't edit replies anymore.

log.info("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
log.info("Current Environment - ${context.testCase.testSuite.project.activeEnvironment.name}")
log.info("");
log.info("Get the value for Test Case Property called 'TestCaseProp' - ${context.expand( '${#TestCase#TestCaseProp}' )}")
log.info("Get the value for Test Suite Property called 'TestSuiteProp' - ${context.expand( '${#TestSuite#TestSuiteProp}' )}")
log.info("");
log.info("Get the response status code for a named service call - ${testRunner.testCase.testSteps["REST Request"].testRequest.response.responseHeaders["#status#"];}");
log.info("");
log.info("Let's have a look at the response from a named test request...")
log.info(testRunner.testCase.testSteps["REST Request"].testRequest.response.getContentAsString() )
log.info("");
log.info("Root URL for a named request ${testRunner.testCase.testSteps["REST Request"].properties['Endpoint'].value}");
log.info("Get the path for a named service call - ${testRunner.testCase.testSteps["REST Request"].testRequest.getPath()}");
log.info("Get the full URL for a named service call.... ${testRunner.testCase.testSteps["REST Request"].properties['Endpoint'].value}${testRunner.testCase.testSteps["REST Request"].testRequest.getPath()}");
log.info("")
log.info("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

 

Here is the value I am trying to capture - requestUri

I cannot find any documentation regarding the testing and posting of these context values.

Any help would be greatly appreciated. See image below for my current test without the needed groovy

script.

BF_14Corp_0-1647439468123.png

 

cancel
Showing results for 
Search instead for 
Did you mean: