Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

How do you use screen shot capture in selenium tests? If anyone is using, how effective do you find it ?

share|improve this question
1  
To easy of a question. We are trying to build a site here where you ask very difficult questions. This question would have been answered if you would googled it. Or read a selenium forum. Or searched the selenium mail list. –  Hannibal May 6 '11 at 7:07
    
The answer to the first question is clearly stated in documentation and examples. The second has no context and so there's no way to decide what answer is best. –  John May 7 '11 at 2:55
1  
Voted to close, as Hannibal says, this question is a bit too simple especially at beta stage. Perhaps you could improve the question by adding detail about what problems you're facing with using screen shot capture? What is stopping you from trying it? –  testerab May 7 '11 at 17:53
2  
little bemused at some of the responses to this question, especially regarding the "complexity" of the question. What give syou guys the right to judge this? A question is only easy if you know the answer so get of your high horse and help the guy out instead of complaining. I'm assuming you want to draw some people here. What's wrong with a simple question? –  user507 May 16 '11 at 10:18
1  
@Rakesh if you think your question is answered then mark one of them as right –  Tarun May 17 '11 at 14:56

8 Answers 8

up vote 4 down vote accepted

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.

share|improve this answer

There is a method on the selenium class

mySelenium.captureScreenshot(filenameToSaveImageTo);

Or if you need the entire screen

mySelenium.captureEntirePageScreenshot(filenameToSaveImageTo,"");

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? :-)

Source for code snippets

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. :-)

share|improve this answer
    
Thanks Glowcoder that adds color to it. Indeed it answers my question effectively. If also wanted to know where exactly people use screen capture if any one is using it? –  Rakesh Prabhakaran May 5 '11 at 18:31
    
I did it when I had to know a specific page layout and wanted more than just text verification, sometimes text placement was key. It all depends on your requirements. –  MichaelF May 5 '11 at 19:42

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).

share|improve this answer
    
+1 for the idea of comparing them against expected results. It would be more difficult, but it would take the manual aspect out of it. I still personally see it being, I don't know how to put it, "not in the spirit" of automated testing, if you catch my drift. But that is a very clever idea, even if the practicality of it has some hurdles to jump through. –  corsiKa May 5 '11 at 18:19

Our localization team uses screenshots extensively. They've got a automation built around the basic screenshots so they can quickly check our product with a bunch of different languages, and verify that sizing, truncation, positioning, graphics, etc are all correct for the language.

share|improve this answer
    
+1 I really like the idea of taking something manual and removing lots of the manual labor out of it. IMO the more automation the better. –  corsiKa May 6 '11 at 21:19

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Found this tip on screenshots useful. Kindly Check - http://elementalselenium.com/tips/16-take-screenshot-on-failure

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.