But that code is the same as above which can be taken only one screen shot and not when failed so need some more for above code WebDriver ; import org. TakesScreenshot ; import org. By Mukesh Otwani T By clicking “Post Your Answer”, you acknowledge that you have read our updated terms of service , privacy policy and cookie policy , and that your continued use of the website is subject to these policies. WebDriver ; import org. If a test step fails in the try block then it goes to the catch block and capture a screenshot of the web page.

Uploader: Shagar
Date Added: 27 December 2009
File Size: 17.7 Mb
Operating Systems: Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X
Downloads: 29517
Price: Free* [*Free Regsitration Required]

To take screenshot of failed test case in Selenium Webdriver

Naughty Ninja 4 13 We could easily identify where exactly the script got failed by seeing the screenshot. I am Mukesh Otwani working professional in a beautiful city Bangalore India.

To achieve this, we could place the entire code in try-catch block.

The above code gives me only one screenshot for webdrivee test cases, due to the code above has single name “screenshot. We need to design script in such a way that we can utilize script code as much as possible.


How to capture screenshot for failed test cases in Selenium Webdriver

One suggestion is that you set up a Context class and put the information you want e. File ; import org. Samir 99 selenihm 7. Above code will execute fine and if test case will fail it will capture the screenshot.

To take screenshot of failed test case in Selenium Webdriver – LATEST SOFTWARE TESTING NEWS

It depends on how you control your cases. AfterMethod ; import org. Writing Selenium Webdriver script is not enough everyone can design script nowadays. Previously I have covered a post on capture screenshot in Selenium so if you have not gone through the previos post then I will highly recommend you to please go through the post and youtube as well.

By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. He loves to be with his wife and cute little kid ‘Freedom’. If a script fails, we need to know where was the error in script.


Lyu, Can we get the screen shot names as Test case names?? What you can do in many different ways. Sign up using Facebook.

Sign up or log in Sign up using Google. I hope you got me?? One of the options you have in this case can be, in create a string of date and time that is going to be unique, like this: By Mukesh Otwani T TakesScreenshot ; import org. OutputType ; import org. Mukesh Otwani December 17, at By ; import org.

How to take screen shot for failed test cases using selenium webdriver in Java? – Stack Overflow

WebDriver ; import org. Which means placing the test steps in try block and screen capture statement in catch block. ITestResult ; import org.

Sign up using Gailure and Password. TakesScreenshot ; import org. Here I will be using two new topics which will help us to achieve the same. Lyu 4