Forum Discussion

ManuT's avatar
ManuT
Occasional Contributor
8 years ago

Reading an ExcelSheet

Hi all,

 

In our TestComplete JavaScript framework, I am placing all the objects with their Xpaths related to the webpage in one Excel. And I am writing the TestCases in another excel which contains keywords and object names. There is a driver script written in TestComplete which reads TestCase Excel and the Object Excel.

 

I found that the execution speed is very slow as it has to hit the  object excel for every object it founds in TestExcel while running TestCases.

 

Is there anyway, I could make a better way to read the entire excel in one go or Any other suggestions on this to make the execution speed faster? I appreciate your help.

 

 

Thanks, 

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The only way you have to do what you want is to create some sort of unit of code that is shared across all your other tests and test cases where you read the excel sheet and basically rebuild, from scratch, on your own, the equivalent of NameMapping. That's basically what you're trying to do... have all the object identification factors preloaded in your test project.

    Based upon what you're trying to do, it seems you're trying to basically replicate what happens in Selenium... you're using TestComplete now and there is no need to do XPath identification in code. Map your objects with NameMapping and the object repository is immediately available.

    The reason why things are running slow is not necessarily because of reading the Excel... it has EVERYTHING to do with the fact that, for every object, you're doing a scan of the HTML document tree for the XPath... a long process to begin with. Using NameMapping that scan doesn't happen and the object identification is MUCH faster. I'd suggest you look into re-designing your framework to use NameMapping/Aliases instead.
  • shankar_r's avatar
    shankar_r
    Community Hero

    I would suggest, As a first step of driver script create table type project variable(s) for each sheets which you want to access the data in one go.

     

    Then wherever you can just getting from project variable. I have been using this approach for long time and i'm getting faster execution and without any hang.

     

    Sample code which i'm using,

    function fn_getTestCaseObject(gTestDataPath,strSheetName)
    {
          try
          {
                var  tempTCExcelObject;
        
                tempTCExcelObject = DDT.ExcelDriver(gTestDataPath,strSheetName,false);
        
                Project.Variables.AddVariable("tblTestData","Table");
        
                for (var i = 0;i< tempTCExcelObject.ColumnCount;i++) 
                {
                      Project.Variables.tblTestData.AddColumn(tempTCExcelObject.ColumnName(i));
                }
                
                tempTCExcelObject.DriveMethod("<UnitName>.fn_driveTestData");
                DDT.CloseDriver(tempTCExcelObject.Name);
          }
          catch(ex)
          {
                Log.Error("Error occured in fn_getTestCaseObject function , Error Description: " + ex.stack);
          }
    	
    }
    function fn_driveTestData()
    {
          var intRowCount=1,i,tempValue;
          try
          {
                intRowCount = Project.Variables.tblTestData.RowCount;
                Project.Variables.tblTestData.RowCount = intRowCount + 1;
                
          	for(i = 0 ; i < DDT.CurrentDriver.ColumnCount ; i++)
          	{
                     Project.Variables.tblTestData.$set(DDT.CurrentDriver.ColumnName(i),intRowCount,aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
          	}
          }
          catch(ex)
          {
                Log.Error("Error occured in fn_driveTestData function , Error Description: " + ex.stack);
          }	
          
    }
    • ManuT's avatar
      ManuT
      Occasional Contributor

      I have created the driver scripts. But, I am using  Excel = Sys.OleObject("Excel.Application") instead of DDT driver. The problem is I am using two excels. The TestCase Excel should go and hit the object excel every time.

      • Marsha_R's avatar
        Marsha_R
        Icon for Champion Level 3 rankChampion Level 3

        You really should take advantage of what tristaanogre and I mentioned above.  Using Name Mapping for your objects will go faster and avoid the two Excel file problem.  

  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3

    Are you opening and closing the Excel driver inside your test case loop?  We open it before the loop and close it after the loop and don't seem to be having any timing issues.

     

    Why not use name mapping, at least a high level one, for your objects?  It's much faster for TestComplete to access the object from there.