How can I get screenshot of every soft assertion in a test method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How can I get screenshot of every soft assertion in a test method

Abhishek
Hi,

Could you tell me how can I get screenshot of every soft assertion in a test method.

E.g. My test is to create a new user.This requires a 4 page navigation.  The test steps are as:
Page 1. Open URL and click link
Page 2. Click link to create new user
Page 3. Fill and submit form
Page 4. Verify confirmation of user creation.

I have all these steps in a single test method and implemented soft assertion to verify each page.

What modifications do i need to do to achieve the same ?

screenshot is implemented in teardown as:

@AfterMethod
        public void quitBrowser(ITestResult result) throws IOException{
                System.out.println("Quiting browser...");
                if(!result.isSuccess()){
                        File imageFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                        String faliureImageFileName= result.getMethod().getMethodName()
                                        + new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime())
                                        +".png";
                        File faliureImageFile = new File(faliureImageFileName);
                        FileUtils.moveFile(imageFile, faliureImageFile);
                }
                driver.quit();
        }
 

With this implementation I get screenshot for only first soft assertion that fails and not for others.