Forum Discussion

kkc's avatar
kkc
Occasional Contributor
11 years ago

VBScript Runtime Error when Using DDTDriver Object in TestExecute

Currently I've tried to use TestExecute to run my test scripts and met some unexpected runtime error which never occurred when I tried in TestComplete.



In my scripts, I tried to open the excel file using the DDTDriver Object (actually the ExcelDriver).



The script I create the ExcelDriver is as follows: 

p.s. I am sure that AccessDatabaseEngine has already been installed in my testing environment.




================

Function getDriverObject(strSpreadSheetName, strDriverName)


 


  Dim pathresource


  


  pathresource = Project.Path + "Resources\" + strSpreadSheetName


  Set getDriverObject = DDT.ExcelDriver(pathresource, strDriverName, TRUE)


  getDriverObject.Name = strDriverName


 


End Function

======================



And the scripts to read the excel content is as follows:



=====================


Function getContentFromSpreadSheet(ByRef strDriverName, strColumnName)


         


    strTemp = DDT.DriverByName(strDriverName).Value(strColumnName)


    


    If IsNull(strTemp) then


        getContentFromSpreadSheet = ""


    Else


        getContentFromSpreadSheet = strTemp


    End if


 


End Function

=====================



The issue is that I need to call the funtion "getContentFromSpreadSheet" several times in each cases, and there are always some cases failed due to the error "item cannot be found in the collection corresponding to the requested name or ordinal". The error occurred when execute the statement below:



==============

strTemp = DDT.DriverByName(strDriverName).Value(strColumnName)

==============



Since I need to read excel file to get my testing data, this issue will block my entire testing scenario. So I really need some suggestions. Thanks a lot!



p.s. I do remember calling the DDT.CloseDriver(strDriverName) each time when I  finish the entire loop in the excel file.

 



  • murugans1011's avatar
    murugans1011
    Regular Contributor
    hi  actually the issue not related with DDT

    "item cannot be found in the collection corresponding to the requested name or ordinal".



    Make Sure u have Valid columnname in excel.debug test and check for columnname which matches excel column name in this line



    strTemp = DDT.DriverByName(strDriverName).Value(strColumnName)





    u can also get column name through script



     temp=DDT.CurrentDriver.ColumnName(Index)  'index of column

  • kkc's avatar
    kkc
    Occasional Contributor
    I don't think I pass the incorrect column name. The face is that everytime some cases fails, but I don't know which ones fail, and the same case may fail after I ran it several times.



    For example:

    I have 10 cases to be run and case-A is one of them. First time case-A had been executed without any error found, but next time, the error occurred when executed case-A. And the third time, the error will occurred in executing case-B.





  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Kevin,



    The Google search with the error text as a parameter (https://www.google.com/?q=item+cannot+be+found+in+the+collection+corresponding+to+the+requested+name+or+ordinal) returns quite a lot of results with the root of the problem that people tried to get results from the closed or in any other way invalid recordset.

    So I would recommend to check your code if it does not occasionally close or invalidate in some other way DDT driver.