context values saved to a data sink
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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())
- Labels:
-
Function Tests
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 to "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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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#"];}");
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
