locked
Verifying Images size in Web Test?

    Question

  • Hi Guys,

    Can anyone advice on  how to validate images & image properties like image size (height and width) in web test?

    Im using VSTS 2008

    Thanks in advance.

    rgds
    Prem
    Friday, December 11, 2009 2:05 PM

Answers

  • Hello Prem,

    As the image file is considered as dependent request under the top request. We could get the image item with web test request plug-in.

    I did some tests on my machine and they worked fine. You may refer to the codes below:

    public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                foreach (WebTestRequest dependent in e.Request.DependentRequests)
                {
                    string url = dependent.Url;  //Get the url of dependent request
                    Image t=null;

                    if (url.EndsWith(".png"))    //Verify whether this request is .png file, you could modify here to adjust your case
                    {
                        WebClient webclient = new WebClient();

                        using (Stream stream = webclient.OpenRead(url))
                            t=Image.FromStream(stream);          //Get the corresponding image file

                        //Get the height and width of this image and bind them with context parameter
                        e.WebTest.Context["hight"] = t.Height.ToString();
                        e.WebTest.Context["weidth"] = t.Width.ToString();
                    }
                }
            }

    Here are some articles related to this issue:
    http://msdn.microsoft.com/en-us/library/bb514192.aspx
    http://blogs.msdn.com/densto/pages/webtestrequest-dependentrequests-collection.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
    Monday, December 14, 2009 9:08 AM
    Moderator
  • Cheers Edwer that was really helpful.

     

    rgds

    Prem

    • Marked as answer by Prem143 Friday, December 18, 2009 4:45 PM
    Friday, December 18, 2009 4:45 PM

All replies

  • Hello Prem,

    As the image file is considered as dependent request under the top request. We could get the image item with web test request plug-in.

    I did some tests on my machine and they worked fine. You may refer to the codes below:

    public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                foreach (WebTestRequest dependent in e.Request.DependentRequests)
                {
                    string url = dependent.Url;  //Get the url of dependent request
                    Image t=null;

                    if (url.EndsWith(".png"))    //Verify whether this request is .png file, you could modify here to adjust your case
                    {
                        WebClient webclient = new WebClient();

                        using (Stream stream = webclient.OpenRead(url))
                            t=Image.FromStream(stream);          //Get the corresponding image file

                        //Get the height and width of this image and bind them with context parameter
                        e.WebTest.Context["hight"] = t.Height.ToString();
                        e.WebTest.Context["weidth"] = t.Width.ToString();
                    }
                }
            }

    Here are some articles related to this issue:
    http://msdn.microsoft.com/en-us/library/bb514192.aspx
    http://blogs.msdn.com/densto/pages/webtestrequest-dependentrequests-collection.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
    Monday, December 14, 2009 9:08 AM
    Moderator
  • Cheers Edwer that was really helpful.

     

    rgds

    Prem

    • Marked as answer by Prem143 Friday, December 18, 2009 4:45 PM
    Friday, December 18, 2009 4:45 PM