Image Load verification

5 posts, 0 answers
  1. Waylon
    Waylon avatar
    10 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    Hi There,
    Do we have any way to verification image load? Currently I need make sure the images are load successfully, the images can be changed, I just need make sure those images will be displayed, no 'X' there, but currently all images of the system are displayed, I have no way to record them, another question is can we use the same image for all other images?

    Thanks
    Waylon
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 31 May 2011 Link to this post

    Hello Waylon,

    Please watch the episode on Telerik TV on Image Verification. This standard Image Verification will not work if the image changes, as it is based on image content. We have conceived a couple work-arounds, however:
    1. Perform an image verification on the red "X" when the image fails to load. Then, with the help of a coded step, you can tell the test to continue if the verification fails (which in this case means the real image loaded). If the verification passes (meaning the red "X" is showing and the image did not load), then the test fails.
    2. Craft a step entirely in code that sends a request to the image URL. If a 200 OK code is received, the step passes. If a 404 NOT FOUND code is received, the step fails.
    Both of these options can be copied and slightly tweaked to meet the needs of several image elements on a single page.

    For an advanced Image Comparison in code, please see this KB article.

    Note: While you can manually build a verification of the image element based on "IsVisible," this step will pass even if an "X" loads instead of the actual image. In this case Test Studio is simply verifying the underlying element is visible, and not verifying that the element's image is properly loading.

    Best wishes,
    Anthony
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Waylon
    Waylon avatar
    10 posts
    Member since:
    May 2011

    Posted 02 Jun 2011 Link to this post

    Craft a step entirely in code that sends a request to the image URL. If a 200 OK code is received, the step passes. If a 404 NOT FOUND code is received, the step fails.

    How to send the request via Telerik?
  4. Waylon
    Waylon avatar
    10 posts
    Member since:
    May 2011

    Posted 02 Jun 2011 Link to this post

    I was coding this way, seems works
    Private Function SendRequest(ByVal url As String)
                Dim Request As HttpWebRequest = WebRequest.Create(url)
                Dim Response As HttpWebResponse
                Dim SW As StreamWriter
                Dim SR As StreamReader
                Dim ResponseData As String
                Try
                  Response = Request.GetResponse()
                  SR = New StreamReader(Response.GetResponseStream())
                  ResponseData = SR.ReadToEnd()
                Catch Wex As System.Net.WebException
                  SR = New StreamReader(Wex.Response.GetResponseStream())
                  ResponseData = SR.ReadToEnd()
                  Throw New Exception(ResponseData)
                Finally
                   SR.Close()
                End Try

               Return ResponseData
            End Function
  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 02 Jun 2011 Link to this post

    Hello Waylon,

    I'm glad you got it working. Please contact us again if you have further questions.

    Regards,
    Anthony
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top