Forum Discussion

Hellotest's avatar
Hellotest
Contributor
5 years ago

To Derive logical value from 2 responses

In test case below scenario

Step 1 - Get call and Response has ID 

Step 2-  If ID=="" (from step1) then Add call and

              Response has ID

Step 3- Update Call with ID Derived from step1 or 2 

If step 2 is run then ID should be from its response 

Here step 3 is conditional  so how can I add the ID ?

I was adding ID based on GetData feature from step 1 response but that fails if step 2 is run as latest ID is derived there.

Could you please suggest

  • ChrisA's avatar
    ChrisA
    5 years ago

    Hi,

     

    You could streamline this and not use setPropertyValue and getPropertyValue.  I frequently update the test request steps based on some conditional, but only use custom properties very, very rarely.

     

    From the original problem, you always run Step 3.  The only thing with Step 3 is what ID to use.  There's no need to disable step 3 or set custom properties.

     

    Personally, I would create a Groovy Script prior to Step 3 which only returns the ID you want in Step 3.  Nothing more, nothing less.  You've already worked out the ID in a Groovy script.  Simply return the ID.  In Step 3, do a 'get data' to obtain the result of the Groovy Script.

    The

  • Hi Hellotest :

     

    You can create structure like below:

     

    1. Get call

    2. groovy step --> if id present in step 1 then run step 2 and get id and store in custom properties else disable it

    3. disabled POST Step

    4. Update step --> getting id from custom properties.

     

    Let me know in case you need more clarity on this.

     

  • Hello,

    I wrote groovy script as below.[Step 1-GetPointTypes; Step 2- AddPointType; Step3- UpdatePointType] 

    When groovy script is run , it takes control correctly and prints value .

    Question is - How to access this value(refPointTypeId ) in test step in UpdatePointType?

    I tried ${#testCase.testSteps#refPointTypeId} or  ${#testSteps#refPointTypeId} or  ${#project#refPointTypeId} but not working, please suggest. 

     

    import static com.jayway.jsonpath.JsonPath.parse
    def refPointTypeId = context.expand( '${GetPointTypes#Response#$[0][\'RefPointTypeId\']}' )
    testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("refPointTypeId",refPointTypeId)

    if (refPointTypeId == "" )
    {
    testRunner.gotoStepByName("AddPointType")
    def refPointTypeIdNew = context.expand( '${AddPointType#Response#$[\'RefPointTypeId\']}' )
    testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("refPointTypeId",refPointTypeIdNew)
    log.info(refPointTypeId)
    }
    else{
    log.info(refPointTypeId)
    testRunner.gotoStepByName("UpdatePointType")
    }



     

    • Hellotest's avatar
      Hellotest
      Contributor

      Hello,

      Disregard my previous. I figured out that getProperty() will add to that field.

      Issue I am facing now is in step 2 (AddPointType) since control goes to execute the AddPointType, the value which I am trying to retrieve from its response is null. (code highlighted below in bold and Italic)

      How to get the value from response in same groovy script. Please suggest 

       

       

      import static com.jayway.jsonpath.JsonPath.parse

      def refPointTypeId = context.expand( '${GetPointTypes#Response#$[0][\'RefPointTypeId\']}' )
      if (refPointTypeId == "" )
      {
      testRunner.gotoStepByName("AddPointType")
      def refPointTypeIdNew = context.expand( '${AddPointType#Response#$[\'RefPointTypeId\']}' )
      testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("pointTypeId",refPointTypeIdNew)
      log.info(testRunner.testCase.testSteps["UpdatePointType"].getPropertyValue("pointTypeId"))
      }
      else{
      testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("pointTypeId",refPointTypeId)
      testRunner.gotoStepByName("UpdatePointType")
      }

      • ChrisA's avatar
        ChrisA
        Contributor

        Hi,

         

        You could streamline this and not use setPropertyValue and getPropertyValue.  I frequently update the test request steps based on some conditional, but only use custom properties very, very rarely.

         

        From the original problem, you always run Step 3.  The only thing with Step 3 is what ID to use.  There's no need to disable step 3 or set custom properties.

         

        Personally, I would create a Groovy Script prior to Step 3 which only returns the ID you want in Step 3.  Nothing more, nothing less.  You've already worked out the ID in a Groovy script.  Simply return the ID.  In Step 3, do a 'get data' to obtain the result of the Groovy Script.

        The