2

I am working on selenium automation for one of the project, I have a number of test cases I want to create a separate log file for each and every test case

Example : Suppose I have two test cases with names X and Y, when I execute all the test cases (X and Y), then I need to create folder (in parallel to execution) with current time stamp and inside that folder I need to create two log files with name same as the test case names (i.e. X and Y)

please help if any body having idea

Note : I am using Log4j framework with java language.

4

Use appenders to achieve this. Try the process below :

  1. Write a logic to create directory at runtime with timestamp. Use DateFormat and Date to get timestamp as you need.

    File dir = new File(DateFormatObj.format(DateObj)); dir.mkdir(); System.setProperty("tempFolder",dir.getAbsolutePath());

  2. Write logic for appender in each test case (or log4j.xml i didnt try that out).

    FileAppender fileApp = new FileAppender();

// Assuming your class name is your test name

 `fileApp.setFile(System.getProperty("tempFolder") + "\\" + "this.getClass().getSimpleName()" + ".log");`
  1. Call folder creation method as your Test Case/Suite starts. Logs will be generated specific to your test case and all will move to folder created.
-1

can we use this appender.....

testname testrun ${testname}.log ${testname}.%i.log 1 100 10MB %d{ISO8601} %-5level %C{1} [%M:%L] [%thread] - %msg%n

  • can you give information on why this is a better solution, what it offers over other options? Maybe break down what each part means and how it is used in this context – ECiurleo Jul 21 '16 at 8:48
  • Hi Sunil, is this an answer/suggestion? Or is this a new question? – corsiKa Jul 21 '16 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.