Forum Discussion

maddenapally's avatar
maddenapally
Contributor
6 years ago

How to retrieve all test steps using groovy script

Hi Team,

 

I want to retrieve all the test steps from test case, Need to add headers to the each step.

 

Regards,

Karthik

  • Radford's avatar
    Radford
    6 years ago

    I'm sorry I haven't had experience of that so I can't really offer specific advice, but have a look at the Event Handling functionality:

     

    https://support.smartbear.com/readyapi/docs/testing/handling-events.html

     

    In particular the RequestFilter.filterRequest event. The recent version of ReadyAPI come with a sample script with the comment:

     

    "// Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls"

     

    This sounds like what you are after.

     

    Edit: It was Version 2.4 which added the sample event handler scripts to new projects.

  • Radford's avatar
    Radford
    Super Contributor

    Not sure where you want to run the script from, but here is one that will run from a test case Setup Script:

     

    testCase.getTestSteps().each(){testStepName, testStep  ->
    	log.info(testStepName)
    	log.info(testStep.getClass())
    }
    • maddenapally's avatar
      maddenapally
      Contributor

      Thanks 

       

      I want to take the Environment from the property that to Test case level.

      Using that environment(int or staging). I need to set the Headers to all the test steps.

      It has to work, if I run test step level also.

       

      Regards,

      Karthik

      • Radford's avatar
        Radford
        Super Contributor

        I'm sorry I haven't had experience of that so I can't really offer specific advice, but have a look at the Event Handling functionality:

         

        https://support.smartbear.com/readyapi/docs/testing/handling-events.html

         

        In particular the RequestFilter.filterRequest event. The recent version of ReadyAPI come with a sample script with the comment:

         

        "// Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls"

         

        This sounds like what you are after.

         

        Edit: It was Version 2.4 which added the sample event handler scripts to new projects.