Forum Discussion

michael_sica's avatar
michael_sica
New Contributor
14 years ago

Evaluating HTTP response code

Hello,



Full disclosure - I haven't downloaded TestComplete and played with it. I'm still in the "evaluate a bunch of products from their web sites and demo videos" stage. I really like what I see on the TestComplete web site, but I haven't seen anything related to the ability to evaluate an HTTP response code (I did some forum searching as well). 



Part of a full end-to-end test for me would be to hit a URL and then evaluate what the HTTP response code is. I.e. Have TestComplete hit http://www.example.com/not_allowed/ and then have TestComplete verify that the web server has returned a 403 response code. 



Does TestComplete have any view into the response code that is returned when it hits a URL? 



Thank you,

-michael.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    If all you're doing is testing via the UI, then not easily as far as I know.  TestComplete itself is not sending the HTTP request, the browser is and so the response code is sort of hidden.



    However, you can instantiate instances of the MSXML2.XMLHTTP objects through TestComplete, send a GET request and then evaluate the response code from that.



    Now, based upon the example that you noted, you probably could use evidence from the UI, such as if the URL of the resulting page is your error page, validating the text on that error page for the 403 error, etc.  These would be evidence through the UI that would indicate what response code you're using.  But when it comes to the actual low-level HTTP protocol Request/Response, you're best bet is to utilize the native XMLHTTP object.
  • Thanks again. My 5-minute proof-of-concept works.



    Dim objXML


    Function Test404


        Set objXML = CreateObject("MSXML2.XMLHTTP")


        objXML.Open "GET", "http://localhost/notfound", False


        objXML.Send    


        If (objXML.status = "404") Then


          Log.Message "Test passed " & objXML.status  


        Else


          Log.Error "Test failed " & objXML.status


        End If       


    End Function

  • Hi Everyone,



        My requirement is similar to this. When clicked on link in our application on a webpage, page will be displayed in a frame in the same page. Since the page is loading and frame is not loading, iam not able to track the error. Please give suggestions. Thanks in Advance.
  • Kavitha,


    I don't think that it's possible to get the response code for individual HTTP requests in functional web tests, for , as far as I know, browsers don't provide information on this.


    In your case, you can determine whether or not a page has been loaded to IFRAME by analyzing the page's contents.

    If you try to load a non-existing page (like http://mmm..nn.sss), the browser will display a notification that the page could not be found (see attached image1). This notification is an html page. TestComplete has access to it and its contents (see image2). So, you can

    check the page's contents and decide if the page was loaded successfully.


    Below, is a code snippet that demonstrates how you can do this:




    Sub FrameTest

      ' Get the page and frame

      Set page = Sys.Process("iexplore", 2).Page("file:///C:/TEMP/myPage.htm")

      Set frame = page.Frame("myIFRAME")

     

      ' Get acces to the frame's document

      ' In TestComplete, you can do this though some child object of the frame

      Set temp = frame.Child(0) 

      Set frameDoc = temp.document

     

      ' Get the title element that contains the error text --

      ' "Internet Explorer cannot display the web page"

      Set titleElem = frameDoc.all("mainTitle")

     

      ' Check the element's contents

      If Not (titleElem Is Nothing) Then

        If titleElem.innerText = "Internet Explorer cannot display the web page" Then

          Log.Error "Error loading a page."

          Exit Sub

        End If

      End If


      ...

        

    End Sub