Forum Discussion

BF_14Corp's avatar
BF_14Corp
New Contributor
2 years ago

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

  • ChrisAdams's avatar
    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#"];}");

     

    • ChrisAdams's avatar
      ChrisAdams
      Champion Level 2

       

      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("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

       

      • BF_14Corp's avatar
        BF_14Corp
        New Contributor

        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's avatar
      BF_14Corp
      New Contributor

      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's avatar
    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.