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

PDF Automation in QTP

                                                                            The most challenging issue with PDFs is that it could be of any kind, not just a tabular data; it could have plain text, images or even forms to fill up. So this makes a tester’s life a bit difficult, never mind, we will definitely find an easy of do it… Although there are already some better approaches we have to deal with PDF documents but I found many of us are facing so many difficulties using this. There are lots of queries coming at QTP forums asking for an easy way of doing it with PDFs. keeping those in my mind I started c...

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 :  ...

Download Test Resource From QC Using QTP

'########################################################################### '* Function Name: QCGetResource '* Designer: Jay '* Date 09-May-2012 '* This script will Download QC Test Resource to a local dir '########################################################################### Function QCGetResource(resourceName,saveTo)     Set qcConn = QCUtil.QCConnection     Set oResource = qcConn.QCResourceFactory     Set oFilter = oResource.Filter     oFilter.Filter("RSC_FILE_NAME") = resourceName     Set oResourceList = oFilter.NewList     If oResourceList.Count = 1 Then         Set oFile = oResourceList.Item(1)         oFile.FileName = resourceName         oFile.DownloadResource saveTo, True     End If         Set qcConn = Nothing     Set oResource = Nothi...

compare Two Text files using Vb Script

Public Function CompareFiles (FilePath1, FilePath2) Dim FS, File1, File2 Set FS = CreateObject(“Scripting.FileSystemObject”) If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then CompareFiles = True Exit Function End If Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles = False Do While File1.AtEndOfStream = False Str1 = File1.Read(1000) Str2 = File2.Read(1000) CompareFiles = StrComp(Str1, Str2, 0) If CompareFiles <> 0 Then CompareFiles = True Exit Do End If Loop File1.Close() File2.Close() End Function Return value: The function returns 0 or False if the two files are identical, otherwise True. Example: File1 = “C:\countries\apple1.jpg” File2 = “C:\countries\apple3.jpg” If CompareFiles(File1, File2) = False Then MsgBox “Files are identical.” Else MsgBox “Files are different.” End If    Source: Mercury Forum’s KB articles

CreateImageFromClipBoard using QTP

'-------------------------------------------------------------------------' Method : CreateImageFromClipBoard' Author : Jai Purpose : It gets the clipboard image and convert as a image file.' Parameters: FileName - String, contains the BMP file name' iIndex - Integer, contains the Worksheet index' Returns : String. The replaced file name it gives.' Caller : - Nil' Calls : - Nil' ------------------------------------------------------------------------- Sub CreateImageFromClipBoard(sFileName) Dim wshShell,ShellReturnCode, sCmdExec Set WshShell = WScript.CreateObject("WScript.Shell") sCmdExec = "D:\autostuff\i_view32.exe /silent /clippaste /convert="& sFileName ShellReturnCode = WshShell.Run(sCmdExec, 1, True) End Sub