0

I need to compare the 2 columns in the excel using the selenium java but excel contains more than 4k records so its taking more than a hour to compare. Is there any faster way of doing this.

I tried, Method 1

println(GlobalVariable.gl_system_time)
for(int k=2;k<= sheet.getLastRowNum();k++)
    
    {
        
        formulary1 = sheet.getRow(k).getCell(2).getStringCellValue()
        columnName.add(formulary1)
        
        formulary2 = sheet.getRow(k).getCell(3).getStringCellValue()
        columnName1.add(formulary2)

    }
println(GlobalVariable.gl_system_time)
    
    if(columnName1.equals(columnName))
    {
        KeywordUtil.markFailed('column are same')
    }
    else
    {
        KeywordUtil.markPassed('column are different as expected')
    }
    
    println(columnName)
    println(columnName1)

    

Method 2

    for(int k=2;k<= sheet.getLastRowNum();k++)
    
    {
        
        formulary1 = sheet.getRow(k).getCell(2).getStringCellValue()
        
        formulary2 = sheet.getRow(k).getCell(3).getStringCellValue()

            if(formulary1 == formulary2)
            {
                break ;
            }
            else{
                continue;
            }

    }
but both are taking more than a hour.

Thanks.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
VIMAL
  • 1
  • What is it that you are trying to achieve here? Say we have 4K records of 2 columns each, are you hoping for no row to have the same value? Or every row to have the same value for both the columns? – whiplash Nov 25 '21 at 10:10
  • @ArunSubramanian `KeywordUtil.markPassed('column are different as expected')` so he's expecting different value I guess. – pburgr Nov 25 '21 at 10:36
  • 1
    Maybe better to add formula to another collumn `=IF(C2=D2; TRUE; FALSE)`. – pburgr Nov 25 '21 at 10:38
  • 1
    @pburgr If that is true, then your idea would work best. He can even change it to IF(C2=D2;1;0) and then add a SUM(E2:En) in N+1 and check if that is equal to 0. If everything was unequal, then sum would be 0. – whiplash Nov 25 '21 at 10:41
  • As @pburgr said, why can't you use formula? – Nandan A Nov 25 '21 at 10:55
  • @arun-subramanian TThe both the column 1 and 2 should not have the same value it should be different. if it has the same value in both then it's failing. – VIMAL Nov 26 '21 at 04:57
  • 1
    The performance issue may be caused in Katalon itself. Try to add external Apache POI dependencies (not sure if still possible) and create custom keywords to extract cell values. Better to read the result only (true/false or 1/0). This may be faster. One more thing if you don't need to know all of non-equal vaues and one fail is enough break the iteration when first non-equal is found. – pburgr Nov 26 '21 at 07:02

0 Answers0