-1

How to take the screenshot of failed test case with test case name? For example: Suppose the test case name is testVelifyLogin(). If it fails then my screenshot name should be testVelifyLogin_time_date.jpg

Please help me how to do this.

i have written code for screen shot as following:

public void onTestFailure(ITestResult iTestResult) {

        String path = System.getProperty("user.dir") + "\\TestOutput\\ScreenShots";

        DateFormat dateFormat = new SimpleDateFormat("HH_mm_ss_dd_MM");
        Calendar cal = Calendar.getInstance();
        String date = dateFormat.format(cal.getTime());
         File scrFile = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);

        try {
            FileUtils.copyFile(scrFile, new File(path,"screenshot_"+date+".jpg"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

instead of screenshot_ i want the test case name.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Manoj Mishra
  • 117
  • 6
  • What have you tried and what was the result? Please read the help topics on how to ask a good question. You need to research your own issue, find code samples, etc. and write your own code to solve the issue. If you do all that and still can't figure it out, then come back and edit your question and add notes from the research you did, the code you have tried reduced to a [mcve], and what the result was... any error messages, etc. It's also very important to include any relevant HTML and properly format the HTML and code. – JeffC Jul 10 '16 at 23:48

1 Answers1

0

you will get it from ITestResult object. For instance,

String testName = iTestResult.getName();
user861594
  • 5,733
  • 3
  • 29
  • 45