Displaying captured browser image

2 posts, 0 answers
  1. Peter
    Peter avatar
    1 posts
    Member since:
    Nov 2010

    Posted 27 Apr 2011 Link to this post

    Hey all,

    I'm using TFS in conjunction with the free version of WebAii and .NET 4 to automate my WebAii tests, and I've run into a problem where when the test fails, I have no real way of seeing why the test fails, other then some debugging code I write.  I want to be able to display the image of the failed browser screen somewhere.  Ideally, I'd love to be able to add it to the debug trace, or some other type of output, but I don't think that's possible.  Can anyone suggest a way for me to be able to display the image I capture after a failed test, so when I look at the test result I immediately know why it failed?

    Or even suggest some best practices in debugging why the test fails via some sort of output displayed in the test result.  I just want it completely simplified, so when ANYONE looks at the test results, they immediately know why it failed.

  2. Stoich
    Stoich avatar
    1 posts

    Posted 28 Apr 2011 Link to this post

    Hi Peter,
        you can capture an image of the browser at any point in the test and save that image to the hard drive. Here's how it looks in code:
    System.Drawing.Bitmap image = ActiveBrowser.Capture();
    image.Save("C:\\MySavedImages\\CurrentBrowser.png", System.Drawing.Imaging.ImageFormat.Png);
    The best place for this piece of code is probably inside a catch(Exception e) {} block. That way you'll have an image of the browser at the time of failure - that can be extremely useful.

    Obviously, there are plenty of other things you can do with the captured image other than simply saving it to the hard drive.

    I hope this helps, please let me know whether you have any additional questions on this.

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top