Tool Independent Method to Automate Web Services

 

There are various methods to automate and validate web services. Here we will going to see Web Services automation using Microsoft XML HTTP object model (Refer https://msdn.microsoft.com/en-us/library/ms535874%28v=vs.85%29.aspx) for more details on the same.

This Microsoft XML HTTP object model can be used to automate web services using any of automation tools. Here in this article we have created various generic reusable functions that performs various operations on web services.

1. Function to Retrieve Whether Service API Response is Successfully generated or not
‘+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*

Public Function ValidateServiceAPI(ByVal svcAPIName, ByVal svcAPIURL, ByVal svcToken, ByVal requestHeaderPrefix)
    Set oReq = CreateObject(“Microsoft.XMLHTTP”)
    oReq.Open “GET”, svcAPIURL,False
    oReq.SetRequestHeader “Authorization”, requestHeaderPrefix & ” ” & svcToken
    oReq.Send
    iServiceStatusCode = oReq.Status
   
    If iServiceStatusCode = 200 Then
        Reporter.ReportEvent micPass, svcAPIName & ” API Configuration Service – Success”,svcAPIName & ” API Configuration Service Success with Status Code – ” & iServiceStatusCode
        ValidateServiceAPI = True
    Else
        Reporter.ReportEvent micFail, svcAPIName & ” API Configuration Service – Failure”, svcAPIName & ” API Configuration Service Failure with Status Code – ” & iServiceStatusCode
        ValidateServiceAPI = False
    End If
    Set oReq = Nothing
End Function

 

2. Function to Retrieve Service API Response
‘+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*

Public Function GetServiceAPIResponse(ByVal svcAPIName, ByVal svcAPIURL, ByVal svcToken, ByVal requestHeaderPrefix)
    Set oReq = CreateObject(“Microsoft.XMLHTTP”)
    oReq.Open “GET”, svcAPIURL,False
    oReq.SetRequestHeader “Authorization”, requestHeaderPrefix & ” ” & svcToken
    oReq.Send
    iServiceStatusCode = oReq.Status
    sServiceAPIResponse = oReq.ResponseText
   
    If iServiceStatusCode = 200 Then
        GetServiceAPIResponse = sServiceAPIResponse
        Reporter.ReportEvent micPass, svcAPIName & ” API Configuration – Success”,svcAPIName & ” API Configuration Service Success – ” & iServiceStatusCode & vbNewLine & “API Response Code – ” & sServiceAPIResponse
    Else
        GetServiceAPIResponse = sServiceAPIResponse
        Reporter.ReportEvent micFail, svcAPIName & ” API Configuration – Failure”, svcAPIName & ” API Configuration Service Failure – ” & iServiceStatusCode & vbNewLine & “API Response Code – ” & sServiceAPIResponse
    End If
    Set oReq = Nothing
End Function

Advertisements
By shalabhdixit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s