Thursday, May 3, 2018

Use fiddler trace to delay the server response and modify response

Recently, there is a test case that requires to delay the server response so as to verify whether the client handles the timeout exception properly.

This can be done with Fidder script, as the only request we want to delay is after 401 credential is provided by user in a post request, so the below Fiddler rule is applied.

To do this,
1. open fiddler
2. select Rule/Customize rules ... menu
3. update the OnBeforeResponse method with the below code to delay the response for 900 seconds
    static function OnBeforeResponse(oSession: Session) {
        if (m_Hide304s && oSession.responseCode == 304) {
            oSession["ui-hide"] = "true";
        }
        if (oSession.HTTPMethodIs("POST")) { 
            if ( oSession.oRequest.headers.Exists("Authorization")){
                Thread.Sleep(90000);
            }
        }
    }

In addition, Fiddler also provides an easy way to customize response from server, like javascript file. To do so
1. send the request to server to get the response in fiddler
2. select the request&response item from fiddler and drag and drop to AutoResponder tab on right side of the screen
3. right click the item added in AutoResponder tab and select "Edit Response ..." context menu
4. in the opened dialog, edit the header and response text and then save the change
5. click Enable rule checkbox in AutoResponder tab
6. send the request again, and verify the customized response is returned to device.

No comments:

Post a Comment