Showing posts with the label TestNG

Advance Level Screenshot capturing using Selenium Webdriver and TestNG Listners

In my opinion, you should avoid the following: using static drivers  (because using static variables is a bad practice) using static methods for taking screenshots  (because using static methods is a bad practice) taking screenshots in the test methods  (because you will duplicate code in lots of tests) taking screenshots in the @After methods  (because you dont need to do this) I prefer to take the screenshots using a TestNG listener as follows. create a class for taking the screenshots Every time you need to take a screenshot, create an object for this class and use the capture method. The capture method will take the screenshot and save it in the screenshots folder. package framework ; import java . io . File ; import java . io . FileOutputStream ; import org . openqa . selenium . OutputType ; import org . openqa . selenium . TakesScreenshot ; import org . openqa . selenium . WebDriver ;   public class Screenshot { private WebDriver driver ;