I got this interview Question
How to generate log in log file in proper manner? The particular test case steps should be aligned properly in log file when we do parallel exeution. How to achieve that?
Instructor
Ashish Thakur Replied on 07/08/2021
Make sure instance of every test case is different.Thats how logs will be generated separately for every test.
But still the different test case instances will execute in parallel. So all the instances will access one log file. So the report will not generate properly for each test case. Am i right?
Ex:
TC1 instance execute this line log.debug("---- TC1 ------")
TC1 instance execute this line log.debug("---- TC1 Step1 ------")
TC1 instance execute this line log.debug("---- TC1 Step2 ------")
TC2 instance execute line log.debug("---- TC2 ------")
TC2 instance execute this line log.debug("---- TC2 Step1 ------")
TC2 instance execute this line log.debug("---- TC2 Step2 ------")
In the log file the expected output in paralllel execution should be
---- TC1 ------
---- TC1 Step1 ------
---- TC1 Step2 ------
---- TC2 ------
---- TC2 Step1 ------
---- TC2 Step2 ------
But the actual output may be
---- TC1 ------
---- TC2 ------
---- TC2 Step1 ------
---- TC1 Step1 ------
---- TC1 Step2 ------
---- TC2 Step2 ------
Anyway to resolve this?
Instructor
Ashish Thakur Replied on 11/08/2021
In this case keep a separate log file for every test