Ask a Question

Data Driven Loops

SOLVED
MarkSchofer
Frequent Contributor

Data Driven Loops

They seem easy enough. Read a CSV file (I have done that). The parameters are for only an individual cell and I am not able to get the looping working

here is the script version.
def Loopy():
Check_V = ""
Check_Amt_V = ""
Check_Date_V = ""
Project.Variables.LoopD.Reset()
RecordIdx = 1
while RecordIdx <= 105:
#Derive DataLoop
#Retrieves the Excel cell value and saves it as Last Operation Result.
#LastResult = Excel.Open("C:\\Smartbear\\Documentation\\Formatted Pension.xlsx").SheetByTitle["Pension Formatted"].CellByName["AB1"].Value
#Check_Amt_V = LastResult
#Posts an information message to the test log.
Log.Message(Project.Variables.LoopD, "HappyBirthday")
#Retrieves the Excel cell value and saves it as Last Operation Result.
LastResult1 = Excel.Open("C:\\Smartbear\\Documentation\\Formatted Pension.xlsx").SheetByTitle["Pension Formatted"].CellByName["AB1"].Value
#Derive CheckAmt
Check_Amt_V = LastResult1
#Posts an information message to the test log.
Log.Message(Check_Amt_V, "")
#Derive Payee
#Retrieves the Excel cell value and saves it as Last Operation Result.
LastResult2 = Excel.Open("C:\\Smartbear\\Documentation\\Formatted Pension.xlsx").SheetByTitle["Pension Formatted"].CellByName["A1"].Value
Check_V = LastResult2
#Posts an information message to the test log.
Log.Message(Check_V, "")
#Opens the specified URL in a running instance of the specified browser.
#Browsers.Item[btIExplorer].Navigate("https://qat1.q.pers.state.or.us/Clarety/SANavigator.do?event=R_GO")
#Derive Check Date
#Retrieves the Excel cell value and saves it as Last Operation Result.
LastResult3 = Excel.Open("C:\\Smartbear\\Documentation\\Formatted Pension.xlsx").SheetByTitle["Pension Formatted"].CellByName["AA1"].Value
Check_Date_V = LastResult3
#Posts an information message to the test log.
Log.Message(Check_Date_V, "")
Project.Variables.LoopD.Next()
RecordIdx = RecordIdx + 1

6 REPLIES 6
Marsha_R
Community Hero

You have the concept, but you're working too hard here

 

See the Iterating through records section at this link

https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/drivers.html

 

You'll have one loop that iterates through the records.  The driver is only opened and closed once.

As you work with a particular row, you can refer to the cells by column name.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
MarkSchofer
Frequent Contributor

Yes that is a perfect response given it is a Monday here in the Pacific North West - That is pretty darn easy and now I have to the 23bit 64 bit matching game. I am going to give it a try with a CSV file.   It recommends a 32 bit version of TC or a 64 bit version of excel.    

**bleep** that was really easy. I did download the driver and it worked like a charm. Yes I was working far too hard.

Here is my solution

 

def CurDriverExample():
# Creates a driver
DDT.ExcelDriver("C:\Smartbear\Documentation\FormattedPension.xlsx", "FP")
# Iterates through records
while not DDT.CurrentDriver.EOF():
# Gets a value from the storage and posts it to the log
count = DDT.CurrentDriver.ColumnCount
for i in range (0, count):
column = DDT.CurrentDriver.ColumnName[i]
#Log.Message(DDT.CurrentDriver.Value[1])
aqTestCase.Begin("GetCheckNumber")
Log.Message(DDT.CurrentDriver.Value[2])
aqTestCase.End()
#Log.Message(DDT.CurrentDriver.Value[3])
aqTestCase.Begin("GetCheckDate")
Log.Message(DDT.CurrentDriver.Value[26])
aqTestCase.End()
aqTestCase.Begin("GetCheckAmt")
Log.Message(DDT.CurrentDriver.Value[27])
aqTestCase.End()
DDT.CurrentDriver.Next()
# Closes the driver
DDT.CloseDriver(DDT.CurrentDriver.Name)

Closer!

 

You should be able to change these sort of blocks 

aqTestCase.Begin("GetCheckNumber")
Log.Message(DDT.CurrentDriver.Value[2])
aqTestCase.End()

 

to something like

aqTestCase.Begin("GetCheckNumber")
Log.Message(DDT.CurrentDriver.NameOfCheckNumberColumn)
aqTestCase.End()

 

That's assuming you have a header row 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
MarkSchofer
Frequent Contributor

I learned something here. I do not have column headers as that is system dependent.

  • For the Excel driver, the names and number of columns and rows are determined by the populated cells in the underlying Excel sheet. Depending on certain Windows Registry settings, the driver may recognize the first row of an Excel worksheet as column names or data.

    I am the later.

You mentioned using a .csv file - that would be the easier way to go and that will get you the column headers.  You can still open it in Excel for editing if need be, but I've run into issues with Excel files before where the cells get hidden characters or otherwise corrupted and the only way to fix it is to make a new sheet.   


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
cancel
Showing results for 
Search instead for 
Did you mean: