Difference between Creating object of XLS_Reader in the base class anddatautil class | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos
10% June Month Discount Avail now

Selenium Training Forum

Difference between Creating object of XLS_Reader in the base class anddatautil class

viijjii Post on 09/10/2018


I am little bit confunsion about  creating object of XLS_Reader in the base class and datautil class  

 because TestNG will allocate memory for XLS Reader  during compile time  for each test cases due to that GC memory error occur. but how it will be resolved when we intialize when we declare it Data Util class. Could you please help me to expalin it 

Mohammed Reply on 09/10/2018

You need to create the object of Xls_Reader only when its required , that is at run time and not at compile time.
If you keep it at global before each test case then this will cause objects to be created for all class before it starts.

Let me know if you want the code i will add it here

Mohammed Reply on 09/10/2018

I have fixed this issue and i tested with more than 2k sample test cases it will just take 3-4 seconds to start execution 

viijjii Reply on 09/10/2018

Hi Mohammed,
Could you please add code here it will be very helpful for me to understand




Demo Reply on 11/10/2018


Can you give the code

Mohammed Reply on 11/10/2018

Hi All, 
Sure will share the code , I would like to know where the GC overload limit is faced i updated the code for eclipse first then I got the same in jenkins 
So after updating it finally its working 
Please find the updates below hope it helps.

@vijjii - can you please let me know where you found the GC overload , was it in jenkins or in eclipse while running your test suite.?

Hi Vijjii,
Let me explain in detail
In Ashish thakur framework he is creating the object of the XLS_Reader and passing in the data provider, so if you want to make sure GC overhead is not faced do the following 
Do not create the object of the XLS_Reader in each class at global level or in the Base class (Just avoid creating the object) this helped me

Test case will look like

public class TC_0001_CP_identifications_Verify_PageTitle extends TestBase {
DataUtil dataUtil = new DataUtil();

String testName = "TC_0001_CP_identifications_Verify_PageTitle";

public Object[][] getDataForTestCaseName() throws FileNotFoundException {
return dataUtil.getDataForTestCaseName(ConstantValues.DATA_XLS_PATH_PORTAL, testName); // here we will pass the path of the XLS_Reader instead of object.

I changed the methods in DataUtil class from static to nonstatic 

Step 2: In data util class create the object of xls like given below
public class DataUtil{
static Xls_Reader xls =null; // global object kept to null

public Object[][] getDataForTestCaseName(String excelLocation, String testCaseName) throws FileNotFoundException {

Object[][] data = null;
Xls_Reader xls = new Xls_Reader(excelLocation);

String sheetName = ConstantValues.TESTDATA_SHEET;

Also for other methods use 
public boolean isTestExecutable(String excelLocation, String testCaseName) {
xls = new Xls_Reader(excelLocation);


IF you cannot understand or do not have time to modify all the scripts then just create the object of the XLS_Reader in the Base as static and extend the base class to all other classes this is temporary fix
public static Xls_Reader xls_chbackoffice = new Xls_Reader(ConstantValues.DATA_XLS_PATH_CHBACKOFFICE);

I have tried both the ways and this works , there is no issue or bug in the XLS_Reader Class its only how we create the object of it and at what point.

viijjii Reply on 12/10/2018

Hi Mohammed ,

Thank a lot for sharing the code.
I faced the GC overload exceeded memory issue  in Jenkins first and build was failed due to memory error. When I tried to execute the same scripts in eclipse for debugging and  found  the same issue there as well. Then i increased the heap size as by issuing below command as temporary fix

Xms1024M -Xmx2048M

viijjii Reply on 12/10/2018

Thanks ashish

viijjii Reply on 12/10/2018

Hi mohammed,
I 'd like to say thanks a lot again. Because  the solution which u provided really helped a lot to fix the fc memory issue .

Mohammed Reply on 12/10/2018

My pleasure.



Demo Reply on 16/10/2018

Thanks Mohammed for help