Forum Discussion

jgoetz's avatar
jgoetz
Occasional Contributor
9 years ago

One loop to run different keyword tests for different test cases...

I have a data-driven loop spreadsheet that lists the KeywordTest Script names in row one, each script is a column.  Then I have a row for each test case or loop with indicators that I would changed based on if I want to run that script for that loop or not.  The spreadsheet is like so:

 

Customer TypeGlobal_LoginAdd_Customer_BusAdd_Customer_PersonGlobal_Logout
BusinessYYN/td>Y
PersonYNY/td>Y

 

Then in the keyword test, I have an if...then for each keyword test where if Variables.DPTestCaseRun("Global_Login") Equals "Y" then Run Keyword Test Global_Login. This is repeated for each column of keyword test names

 

If...ThenVariables.DPTestCaseRun("Global_Login") Equals "Y"
Run Keyword TestGlobal_Login
If...ThenVariables.DPTestCaseRun("Add_Customer_Bus") Equals "Y"
Run Keyword TestAdd_Customer_Bus
If...ThenVariables.DPTestCaseRun("Add_Customer_Person") Equals "Y"
Run Keyword TestAdd_Customer_Person
If...ThenVariables.DPTestCaseRun("Global_Logout") Equals "Y"
Run Keyword TestGlobal_Logout

 

I would like to have a script (Keyword or VB script) loop through one if...then statement for the above with feeding the name of the Keyword test as a variable or parameter, for the one I want to check the indicator for and call if it is Y. Any suggestions?

 

I got as far as saving the script names on a separate spreadsheet tab in one column and then creating a datapool with that name being feed as a variable into a script with the following code to call the script: "Call Eval("KeywordTests." + testCaseName + ".Run")", but I don't know how to feed in the name to tell it find the indicator for that particular column in the table above?

 

When I use the following code I get an error, Object doesn't support this property or method.?

If (KeywordTests.Sanity_Test_Run.Variables.DPTestCaseRun(testCaseName) = "Y") Then

Call Eval("KeywordTests." + testCaseName + ".Run")

End If

2 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    You can parse your table this way (I wrote the code in Python, but you should understand the idea) :

     


    table = Project.Variables.YourTable
    rows = table.RowCount
    cols = table.ColumnCount

    for r in range (rows):
       for c in range (cols):
           test_name = table.Item[c, 0]
           if table.Item[c, r] == "Y":
               # do something with test_name

     

     

    • jgoetz's avatar
      jgoetz
      Occasional Contributor

      Thank you!  I did the following for VB.

       

      Sub testSuiteRun()
        
        Dim excelApplication, projectPath
        Dim sheetName
        
        'Open and set Excel objects, spreadsheet, sheet, row count and column count
        Set excelApplication = Sys.OleObject("Excel.Application")
        projectPath = Project.Path
        Set book = excelApplication.Workbooks.Open(projectPath & "TestCase Runs\TC_Script_Run.xlsx")
        sheetName = "Sheet 1"
        Set sheet = book.Sheets(sheetName)
        rowCount = sheet.UsedRange.Rows.Count
        colCount = sheet.UsedRange.Columns.Count  
       
        'Loop through rows of spreadsheet ignoring the header row
        For r = 2 To rowCount
              
            'Loop through component script columns     
            For c = 4 To colCount
              
              'Set test case name to the header cell (row 1) for active column and the run indicator for active column and row
              testCaseName = VarToString(sheet.Cells(1, c)) 
              runInd = VarToString(sheet.Cells(r, c)) 
               
              'Check if test case name is not blank for active col to eliminate extra blank columns   
              If testCaseName <> "" Then
                
                'check if run indicator is Y and if so then call that component script   
                If runInd = "Y" Then
                  
                    Call Eval("KeywordTests." + testCaseName + ".Run")     
                  
                End If
              
              End If
          
            Next
           
        Next
      
        'quit excel
        excelApplication.Quit
      End Sub