Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
8 years ago

How to call the data to a particular function from DDT Record Data in Python

Hi All,

I have used this particular code to call the data from the Excel i.e

RecNo = 0
  #Posts data to the log (helper routine)
def ProcessData():
  global RecNo
  Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo))
  Log.PushLogFolder(Fldr)
 
  for i in range(DDT.CurrentDriver.ColumnCount):
    Log.Message(DDT.CurrentDriver.ColumnName[i] + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value[i]))
  
  Log.PopLogFolder()
  RecNo = RecNo + 1
  
# Creates the driver (main routine)
def TestDriver():
  global RecNo
  # Creates the driver
  # If you connect to an Excel 2007 sheet, use the following method call:
  # Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", True);
  Driver = DDT.ExcelDriver("C:\\Book1.xls", "Sheet1",True)
  RecNo = 0
  while not Driver.EOF() : 
        # Processes data        
        ProcessData()
        # Goes to the next record
        Driver.Next()

Am able to get the Data record wise

 

record.jpg

 

Now how to call this data to a  testcase function i use in different Unit

 

Please guide me 

12 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Say your TestDriver() method is in Unit1. 

     

    First make this method to return required data.

     

    Then if you want to call it from another module:

     

    from Unit1 import TestDriver
    
    currentTestCaseData = TestDriver()

     

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      baxatob thanks for the info ,but am able retive the complete data but i need a particular data suppose

       

      exlwork.jpg

       

      Now i need only Testcase 4 row data only ,so cant split the data while processing it or else cant we store it in some particular project variables base on the row wise and read that particular row values.

      • baxatob's avatar
        baxatob
        Community Hero

        I prefer to use DB Table variables based on Excel worksheet.

         

        First you need to create such kind of ProjectSuite / Project / KeywordTest variable, e.g my_testcases variable.

         

        After you have assigned your excel worksheet to this variable you can manipulate it:

         

        def get_test_case_data(test_case):
        
            source = Project.Variables.my_testcases
            source.Reset()
        
            while not source.Value['TestCase'] == test_case:
                source.Next()
        	
            execution = source.Value['Execution']  
            param1 = source.Value['Param1'] 
            param2 = source.Value['Param2']
            module1 = source.Value['Module1']
            module2 = source.Value['Module2']
        
            return execution, param1, param2, module1, module2