This is a migrated thread and some comments may be shown as answers.

Image Load verification

4 Answers 104 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Waylon
Top achievements
Rank 1
Waylon asked on 31 May 2011, 02:46 PM
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

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 31 May 2011, 07:28 PM
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 >>

0
Waylon
Top achievements
Rank 1
answered on 02 Jun 2011, 03:50 PM
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?
0
Waylon
Top achievements
Rank 1
answered on 02 Jun 2011, 05:02 PM
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
0
Anthony
Telerik team
answered on 02 Jun 2011, 05:05 PM
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 >>

Tags
General Discussions
Asked by
Waylon
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Waylon
Top achievements
Rank 1
Share this question
or