Attaching Screen shots to TestNG report + @Before suite issue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Attaching Screen shots to TestNG report + @Before suite issue

kingarasan
Hi Tarun,

Thanks for sharing your knowledge, it's really very helpful.

I am facing two issues,

1. Attaching (embedded) failure screen shots to TestNG report?

I tried to attached for the screen shot for the Pass method and it's working. For failure test only exceptions are getting logged.

Reporter.log("<img src=\"file:///" +  failureImageFileName + "\" alt=\"\"/><br />");

Is there any way I can do this for Failure test methods?

2. @BeforeSuite - variable defined is not passed to Test Methods.

Class - SeleniumBase
@BeforeSuite -> Using TestNg Parameter (if value is QA) set a variable "path=www.qatest.com"
Class - Test 1
@Test -- Try to use path variable
Class - Test 2
@Test-- Try to use path variable

Test are failing as the path variable is Null.

If I change BeforeSuite to BeforeMethod it's working. Any idea what's the mistake i am doing?

Also can you please share "Soft Assertion" code?

Thanks for your help.

Cheers
Reply | Threaded
Open this post in threaded view
|

Re: Attaching Screen shots to TestNG report + @Before suite issue

softwaretestingforum
Administrator
Hi Kingarasan,

Thanks for kind words.
About screen shot with TestNG, could you try this =

http://stackoverflow.com/questions/11122261/attaching-screenshots-to-testng-failed-methods-results

I have not used it myself but let me know if you encounter any exception.

About parameter use case, is it possible for you to give me a reproducible use case?

About soft assertion, project is available here for download -

http://manual-and-automated-testing.1070.n6.nabble.com/Selenium-Training-Project-for-12th-December-Data-Driven-Testing-using-Selenium-tp5001553.html

~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Attaching Screen shots to TestNG report + @Before suite issue

kingarasan
Thanks Taurn,

Attaching screen shot is working fine.

I have included the below method in customVerification (Soft Assertion) failure cases to take the screen shot and it's working perfectly.


    public void TakeScreenshot(WebDriver driver) {
        try {
            String failureImageFileName = RESULT_FOLDER_LOCATION + new SimpleDateFormat("MM-dd-yyyy_HH-ss").
                                                  format(new GregorianCalendar().getTime())+ ".png";
            WebDriver augmentedDriver = new Augmenter().augment(driver);
            File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(screenshot, new File(failureImageFileName));

            String userDirector = System.getProperty("user.dir") + "/";
            Reporter.log("<a href=\""+ userDirector + failureImageFileName +"\"><img src=\"file:///" + userDirector
                         + failureImageFileName + "\" alt=\"\""+ "height='800' width='1200'/> "+"<br />");
            Reporter.setCurrentTestResult(null);
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }


Note:
Problem I face after putting this method in @AfterMethod
1. I can't see the image in the Reporter log as failure exception was shown
2. some time the failure occurred on the first page, but the screen shot taken was on the last page.

above solution solved these two problems.

Thanks once again.
Reply | Threaded
Open this post in threaded view
|

Re: Attaching Screen shots to TestNG report + @Before suite issue

softwaretestingforum
Administrator
1. Screen shot would be pushed to folder which is specified in tear down
2. Screen shot would be of the page where assertion failed or any other exception was encounterd
~ seleniumtests.com