Skip to main content

Verify Broken Links in Page using QTP

------------------------------------------------------------------------------------------------------------
Browser("Browser").Page("Page").Sync
Set objLink = Description.Create
objLink("micclass").Value = "Link"
Set objAllLinks = Browser("Browser").Page("HomePage").ChildObjects(objLink)

iTotalLnksCnt = objAllLinks.Count

For iCurItr =0 to iTotalLnksCnt - 1
strURL = objAllLinks(iCurItr).GetROProperty("url")
Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHTTP.Open "GET", strURL, False
objWinHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
objWinHTTP.Send
iReturnVal = objWinHTTP.Status
If iReturnVal = 200 Then
msgbox "Link - " & sURL & " Exists"
ElseIf iReturnVal = 404 Then
msgbox "Link - " & sURL & " is Broken"
Else
msgbox "Code" - iReturnVal
End If
Set objWinHTTP = Nothing
Next
------------------------------------------------------------------------------------------------------------
Other Codes
100 HTTP_STATUS_CONTINUE The request can be continued.
101 HTTP_STATUS_SWITCH_PROTOCOLS The server has switched protocols.
200 HTTP_STATUS_OK The request is completed successfully.
201 HTTP_STATUS_CREATED The request has been fulfilled and resulted in the creation of a new resource.
202 HTTP_STATUS_CREATED The request has been accepted for processing, but the processing has not been completed.
203 HTTP_STATUS_PARTIAL The returned meta information in the entity-header is not the definitive set available from the originating server.
204 HTTP_STATUS_NO_CONTENT The server has fulfilled the request, but there is no new information to be sent back.
205 HTTP_STATUS_RESET_CONTENT The request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action.
206 HTTP_STATUS_PARTIAL_CONTENT The server has fulfilled the partial GET request for the resource.
207 HTTP_STATUS_WEBDAV_MULTI_STATUS During a World Wide Web Distributed Authoring and Versioning (WebDAV) operation, this indicates multiple status codes for a single response. The response body contains Extensible Markup Language (XML) that describes the status codes.
300 HTTP_STATUS_AMBIGUOUS The requested resource is available at one or more locations.
301 HTTP_STATUS_MOVED The requested resource has been assigned to a new permanent Uniform Resource Identifier (URI), and any future references to this resource should be done using one of the returned URIs.
302 HTTP_STATUS_REDIRECT The requested resource resides temporarily under a different URI.
303 HTTP_STATUS_REDIRECT_METHOD The response to the request can be found under a different URI and should be retrieved using a GET HTTP verb on that resource.
304 HTTP_STATUS_NOT_MODIFIED The requested resource has not been modified.
305 HTTP_STATUS_USE_PROXY The requested resource must be accessed through the proxy given by the location field.
307 HTTP_STATUS_REDIRECT_KEEP_VERB The redirected request keeps the same HTTP verb. HTTP/1.1 behavior.
400 HTTP_STATUS_BAD_REQUEST The request could not be processed by the server due to invalid syntax.
401 HTTP_STATUS_DENIED The requested resource requires user authentication.
402 HTTP_STATUS_PAYMENT_REQ Not implemented in the HTTP protocol.
403 HTTP_STATUS_FORBIDDEN The server understood the request, but cannot fulfill it.
404 HTTP_STATUS_NOT_FOUND The server has not found anything that matches the requested URI.
405 HTTP_STATUS_BAD_METHOD The HTTP verb used is not allowed.
406 HTTP_STATUS_NONE_ACCEPTABLE No responses acceptable to the client were found.
407 HTTP_STATUS_PROXY_AUTH_REQ Proxy authentication required.
408 HTTP_STATUS_REQUEST_TIMEOUT The server timed out waiting for the request.
409 HTTP_STATUS_CONFLICT The request could not be completed due to a conflict with the current state of the resource. The user should resubmit with more information.
410 HTTP_STATUS_GONE The requested resource is no longer available at the server, and no forwarding address is known.
411 HTTP_STATUS_LENGTH_REQUIRED The server cannot accept the request without a defined content length.
412 HTTP_STATUS_PRECOND_FAILED The precondition given in one or more of the request header fields evaluated to false when it was tested on the server.
413 HTTP_STATUS_REQUEST_TOO_LARGE The server cannot process the request because the request entity is larger than the server is able to process.
414 HTTP_STATUS_URI_TOO_LONG The server cannot service the request because the request URI is longer than the server can interpret.
415 HTTP_STATUS_UNSUPPORTED_MEDIA The server cannot service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
449 HTTP_STATUS_RETRY_WITH The request should be retried after doing the appropriate action.
500 HTTP_STATUS_SERVER_ERROR The server encountered an unexpected condition that prevented it from fulfilling the request.
501 HTTP_STATUS_NOT_SUPPORTED The server does not support the functionality required to fulfill the request.
502 HTTP_STATUS_BAD_GATEWAY The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
503 HTTP_STATUS_SERVICE_UNAVAIL The service is temporarily overloaded.
504 HTTP_STATUS_GATEWAY_TIMEOUT The request was timed out waiting for a gateway.
505 HTTP_STATUS_VERSION_NOT_SUP The server does not support the HTTP protocol version that was used in the request message.

Comments

Popular posts from this blog

Convert JSON to XML using QTP/UFT/VBScript

Sample Code : Dim strPage,strJSON,objIE strPage = "C:\Jay\JLoader.html" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate2 strPage While objIE.Busy : Wend strJSON = "{""FirstName"":""Jay"", ""LastName"":""Krishna""}" Set objWin = objIE.document.parentWindow objWin.execScript "var jsonStr2XML = function(strJSON) { return json2xml(JSON.parse(strJSON));};" Msgbox  oWin.jsonStr2XML(strJSON) objIE.Quit In Detail: Converting The most popular data interchange format JSON(JavaScript Object Notation) to XML using QTP/UFT. Parsing JSON in UFT could be a challenge so we will use JavaScript in UFT to make it perfect. SO We need :              Java Script API  - To Convert JSON to XML                         JavaScript Files :                         http://goessner.net/download/prj/jsonxml/j

Read Outlook mail attachment and Body using Vb Script or QTP

Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNameSpace("MAPI") Set ObjFolder = olns.GetDefaultFolder(6) j = 0 For each item1 in ObjFolder.Items        iattachCnt = item1.Attachments.Count     Print "Attachments Count: " & iattachCnt     For i = 1 to iattachCnt         Print "FileName :    " & item1.Attachments(i).FileName         Print "Display Name:   " & item1.Attachments(i).DisplayName         Print "Size: " & item1.Attachments(i).Size     Next     Print " Body : " & item1.body     Print "--------------------------------------Mail Num - " & j & " -----------------------------------------------"     j = j+1    Next

Excel Sorting By Rows and Columns

Excel Sorting By Row: Const xlAscending = 1 Const xlNo = 2 Const xlSortRows = 2 Set objExcel = CreateObject(“Excel.Application”) objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”) Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Cells(1,1).activate Set objRange = objExcel.ActiveCell.EntireRow objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows set objExcel=nothing Excel Sorting By Column : Const xlAscending = 1′represents the sorting type 1 for Ascending 2 for Desc Const xlYes = 1 Set objExcel = CreateObject(“Excel.Application”)’Create the excel object objExcel.Visible = True’Make excel visible Set objWorkbook = _ objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”)’Open the document Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 … Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank Set objRange2 = objExcel.Range

How to Read or Select Context Menu or Right Click Menu using QTP.

Select The Item in Right Click Menu or Context Menu: Window("sampleWindow").WinMenu("MenuObjType:=1).Select"File;New" Here MenuObjtype can be 1 r 2 r 3 .......n Check wether the Item is Exist or Not: If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("1","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If                                         Or If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("File","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If Get the Items in Context Menu: For i = 1 to 10 Print  Window("sampleWindow").WinMenu("MenuObjType:=" & i).GetItemProperty("1","Label") Then Next

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP This code uses the HTMLDom and URLDownloadToFile method from urlmon API. Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file Private Declare Function URLDownloadToFile Lib “urlmon” Alias _                                            “URLDownloadToFileA” ( _                                            ByVal pCaller As Long, ByVal szURL As String, _                                            ByVal szFileName As String, _                                            ByVal dwReserved As Long, _                                            ByVal lpfnCB As Long) As Long Sub FileSave(strUrl, Des)     r = URLDownloadToFile(0, strUrl, Des, 0, a)