Browser screenshot in selenium CI tests on DevOps

I’m using selenium scripts in a CI on Azure DevOps.
is it possible to take browser’s screenshots ?


We are taking screenshots in Jenkins CI tool and using Selenium as automation tool. I believe it will also work on Azure platform for Devops testing as well because it has integration with Selenium.

// Initialize Webdriver.
WebDriver driver = new ChromeDriver();

// Create method to take screenshot and add below code.
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
new File("./target/images").mkdirs();

FileUtils.copyFileToDirectory(screenshot, new File("./target/images/"));

You can create method to take screenshot and call it whenever required or better option to call after performing any action like click action or send key action.

Hope this information is helpful for you.