Forum Discussion

Chowdhary's avatar
Chowdhary
Contributor
8 years ago

Reg: Changing the header dynamically

I have a list of test steps under a test case. i want to change the header dynamically, like if i have test step like change, i can add the header to replace with existing header to all the test steps with one step. 

 

I don't think so we have feature like this, if so it can be very useful to me.

 

If not, how we can do this ?

 

Ref: I am attaching a copy for reference.

3 Replies

  • Think you can do it using Event Handlers

     

    Create a event handler of type 'RequestFilter.filterRequest' and use a script like below. Customize for your need accordingly

     

    def headers = request.requestHeaders
    headers.clear()
    headers.put( "my_header", "header_value" )
    request.requestHeaders = headers

     

    Regards,

    Gilu Gopi

    • Chowdhary's avatar
      Chowdhary
      Contributor

      Thanks for responding, I got what your are telling, but I am not sure exactly how I can do it.

       for every test case[10-30 step steps]  I need to replace the whole header with different. can u describe how to do it..

      • gilugopi's avatar
        gilugopi
        Contributor

        The event handler you create will by default apply to all requests in the project ( unless you specifically populate target column with a regular expression to select any specific requests only)

         

        1. So as I mentioned above create an event handler of type 'RequestFilter.filterRequest' for the speficic project where you want to update headers.

        2. Copy paste below code in the script for event handler

         

        def headers = request.requestHeaders
        headers.clear()
        headers.put("header_1","value_1")
        headers.put("header_2","value_2")
        request.requestHeaders = headers

         

        3. modify header_1, header_2 and and it's values to what you need. Add more rows of headers.put if you need to add more than two headers.

         

        4. Then execute your test cases.

         

        Right before execution of each request, this event handler will remove all your existing headers and add the specific headers mentioned in script to your requests. If you execute whole project all requests will be updated.

         

        Once everything is update, go to even handler window and disable the script and save your project.