kkc
11 years agoOccasional Contributor
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.
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.
- 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.