How do you use screen shot capture in selenium tests? If anyone is using, how effective do you find it ?
When you need some visual checks to be done, and if that is a small part of your entire test suite, you can create methods to take screenshots, label them appropriately and leave comments in your test results for each screenshot. Consider a scenario where you have checked the text on the page, but also need to check some layouts and rendering on different browsers.
Another utilization is when you want to capture screenshots on error. Some of the errors can be tough to replicate, but cannot be ignored or a failure that the automation test does not handle. E.g. a pop-up message, hidden fields, etc.
If a TC fails during the automation and a screenshot is taken, it also eliminates the need of manually reproducing it and having to take a screenshot.
It is a very good aid to the automation test results, if not overused.
I find the concept of "capturing" very important, just not necessarily with a screen shot.
One of the most effective things I ever did was to get the full stack trace of application exceptions in the html comments of a page. This was only available when turned on in our test environments because of security reasons.
When this is enabled, every time an action is performed that might cause an exception like, pressing a button or clicking on a link, the framework will check the HTML source for any exception in the comments. That way, if there is a bug the full stack trace is logged into the test results, making investigation a lot easier.
Screenshots are really helpful of you want to quickly visualise failures by looking at a folder full of large thumbnails to see if, for example the browser is crashing, or a common error dialogue is present.
I've only used selenium a bit, but in general, I find screen shots most effective as a debugging tool - i.e. for capturing screen information when there's an error or anything else unexpected happens.
You can, of course, attempt to compare current and expected screen shots, but that's a more difficult problem (IME).
I have largely used capturing screen shot when there are errors in page, instead of using it for each and every step. Combination of Selenium + TestNG + fest (Fixture for easy software testing) lets you capture Screen shot on test failure. I am not able to Google it now though remember that fest has listner which you could add in your ant build. Hence when ever there is a test failure screen shot is captured and posted to TestNG report.
Apropos of image comparison I have used captureScreenShotToString api of Selenium. Using this you could keep a String reference of images and then capture String representation run time to compare with already stored String representation of image.
I guess I need not talk about drawbacks of image comparison
We have been using screenshots for one reason only. If the test fails, I want to see what was on the page when that happened. One of the best debugging tools we have is the fact that, with selenium, we can see what the user would have seen when the test failed. More often than not, by being able to see it, the problem becomes apparent.
There is a method on the selenium class
Or if you need the entire screen
The last empty string could be used for keyword parameters, like background, etc.
Disclaimer: I personally don't use it (or selenium.) That being said, I'm not sure there's much to be gained from it. If you can't get the results you need programatically, you miss something from automating it. If you have to manually review the images, it's not entirely automated. Imagine if you're set up to fail a build when the tests fail. How do you fail the build if you have to manually look at them before it's approved or not? I guess you could hire a couple interns for the most boring job ever... hey it's university credit, right? :-)
Edit: I may have misread the first part of the question. I had thought you were asking "How do I use selenium to take a screen capture." Upon further reading, I realize this may have been a false intrepration. Regardless, I'll leave it up there in case it proves useful to someone. :-)
Found this tip on screenshots useful. Kindly Check - http://elementalselenium.com/tips/16-take-screenshot-on-failure