Forum Discussion
rhsou123 wrote:
I'm using Excel 2016 and I changed the third parameter to True. Tm still facing the same problem, Testcomplete waits for a long time without any Execution or it exits after connecting to the first driver !
Did you close the workbook? Basically, set the options to true... and then DON'T have the Excel document open anywhere in your environment.
Also, I don't know if there is a typo in what you posted, but in your call to the second driver, you don't have any quotes around the actual filename. So, if that is actually the way it is in your code, that would be a problem, too.
Additionally, your first driver is pointing to "Sheet1"... your second driver indicates to use a sheet called "BatchRun"... is this the true sheet name for the second driver? Verify you have ALL values set properly within your call to DDT.ExcelDriver...
AND Close the workbook...
The file path that the second driver uses is getting from the first driver means it is the value of a Cell in the first driver, and I verified, I'm using the correct path also the sheet name is correct.
After connecting to the first driver, I verify if some conditions are true in it, if yes I connect to the second one.
Does this make the problem ?
PS: my files are closed !
- tristaanogre8 years agoEsteemed Contributor
In JavaScript, I wrote the following:
function readTwoExcel () { var xcelDriver1, xcelDriver2; xcelDriver1 = DDT.ExcelDriver('C:\\Source\\SandBox\\JavaScriptProject\\Script\\book1.xlsx', 'DataSheet1', true); while (!xcelDriver1.EOF()){ Log.Message('Book 1 - Sheet1 Value 1: ' + xcelDriver1.Value('Value1') + ' Sheet1 Value2: ' + xcelDriver1.Value('Value2')); xcelDriver2 = DDT.ExcelDriver('C:\\Source\\SandBox\\JavaScriptProject\\Script\\book2.xlsx', 'DataSheet2', true); Log.Message('Book 2 - Sheet2 Value 1: ' + xcelDriver2.Value('Value1') + ' Sheet2 Value2: ' + xcelDriver2.Value('Value2')); DDT.CloseDriver(xcelDriver2.Name); xcelDriver1.Next(); } DDT.CloseDriver(xcelDriver1.Name); }
This works... it gives me a loop through all the rows of my first file and, each time through the loop, writes out the current row of my first file and the first row of the second file each time through. So, there is no problem with opening two excel files like this.
If I open EITHER of those workbook files in Excel while my script is running, I get an error in my test log that I am attempting to work with a closed driver. Same thing if I have that third ACE parameter set to false. So, no matter what, best practice is to keep the workbooks closed while running.
So, we've established:1) You need to make sure you are using the ACE driver (third parameter true) because you have Excel 2016. Again, best practice
2) You need to make sure that, when the code is running, your workbooks/Excel is closed. Again, best practice.
3) What you are attempting IS feasible assuming that all configurations of your Excel drivers are set up properly.
Some things we don't know:
1) Are there any error messages in the test log when things fail?
2) How is the second driver actually being configured with regards to filename, sheet name, etc? Is there a possible bad parameter being passed there?
If you can answer these questions, we'll be closer to a solution.
EDIT: Actually, if I have the ACE driver parameter set to False, since I'm using Excel 2013, I get the same "cannot use a closed driver" error... I'm honestly surprised that you are able to use these drivers in an Excel 2016 environment without using the ACE driver.
- baxatob8 years agoCommunity Hero
Try to close the first driver before starting the second one.
DDT.CloseDriver(yourDriver)
- tristaanogre8 years agoEsteemed Contributor
OK... drop a watchpoint on that value that is supposed to be the path of your excel file in the second driver. Make sure that it is, actually, passing the correct path name. What it sounds like, then, is that the second driver is NOT getting passed a correct property for your file name. Keep in mind that you may need to escape special characters. I'm not a really good at VBScript... I can struggle through it... but it's possible that you are not actually sending a correct file name.
Set up a very basic routine as a check and see if you can hardcode the value of the second excel workbook and access it that way. This is just to debug the main code but I suspect that you're having problems with the declaration of the third driver.
I do still suggest that a) you use the ACE driver (set that third parameter to true) and b) don't have your workbooks open when the code is running. But it seems like that's not the primary source of your problem so let's see if we can fix your connection to the second book. - tristaanogre8 years agoEsteemed Contributor
baxatob wrote:
Try to close the first driver before starting the second one.
DDT.CloseDriver(yourDriver)
That might fix the problem, but it will break his code solution... the second driver is being instantiated within a while loop based off the first driver and is being created, conditionally, based upon values within the first driver. Might not work too well. I'm working on mocking up something similar to see what problems I run into.
- baxatob8 years agoCommunity Hero
Also I suggest to check carefully all test logic.
Looking to the provided code, it is not evident to me, that driver #2 will be executed at all.set xlDriver = DDT.ExcelDriver("C:\Script-Resources\BatchRun\myfile.xls","Sheet1",True) xlDriver.First while not xlDriver.EOF value1 = xlDriver.Value("x") value2 = UCase(xlDriver.Value("y")) If value1= "Y" Then value3 = xlDriver.Value("z") value4 = xlDriver.Value("t") If value2 = "ENVIRONMENT_SET" Then value5 = value2 BuiltIn.ShowMessage(value5) Else If value5 = "" Then call Basic.myfunction() ExitTest Else set xlDriver1 = DDT.ExcelDriver(C:\Script-Resources\BatchRun\myfile2.xls,"BatchRun",True) xlDriver1.First while not xlDriver1.EOF value6 = xlDriver1.Value("xx") If value6 = "Y" Then value7 = xlDriver1.Value("yy") value8 = xlDriver1.Value("tt")
First of all I don't see any .Next() method within while EOF loop.