Forum Discussion

Rajesh2's avatar
Rajesh2
Contributor
8 years ago
Solved

Can anyone please help me with using Tuples in TestComplete with Python

Hi,

 

I need to fetch the testcases based on the ExecutionFlag(Y/N) from Excel

 

I need to store the testcases which have ExecutionFlag="Y" and store it in Array.

 

Now i need to create a loop and the execute those testcases which have ExecutionFlag="Y" sequentially.

 

Can anyone explain how to go about this?

 

Example:

From the Excel attached

I have TC01, TC03, TC04 which has execution flag=Y and TC02, TC05, TC06 execution Flag=N

So Testcases with ExecutionFlag=Y should be stored in an array,

Now create a loop and execute the testcases one by one sequentially.

 

NOTE: Excel attached

 

  • This should work:

     

    A = get_test_suite(test_case_container)
    Log.Message(str(A[0]))

    as well as this:

     

    A = [get_test_suite(test_case_container)]
    Log.Message(str(A[0][0]))

     

     

     

     

18 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Instead of using Array, I would go with Project Variable table type or you can directly using DDT.

     

    Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1"); 
    cno_TCName = 0
    cno_RunFlag = 1
      // Iterates through records
      RecNo = 0;
      while (! Driver.EOF() ) 
      {
        if(Driver.Value(cno_RunFlag) == "Y")
        {
             //Execute your code
         }
        Driver.Next(); // Goes to the next record
      }

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

     

    • baxatob's avatar
      baxatob
      Community Hero

      Ok.

       

       

      test_case_container = DDT.ExcelDriver("C:\\TestCases.xls", "Sheet1")
      
      def get_test_suite(test_case_container):
      
          tests_to_run = [] # creating an empty list
      while not test_case_container.EOF(): if test_case_container.Value["ExecutionFlag(Y/N)"] == "Y": tests_to_run.append(test_case_container.Value["TCID"])

      test_case_container.Next() return tests_to_run

       

       

      get_test_suite() will return a list of strings, where each string is a name of your test case marked with "Y" flag.

      • Rajesh2's avatar
        Rajesh2
        Contributor

        Thank you so much baxatob.. But i am unable to print tests_to_run which has appended all test cases with Execution Flag = "Y". 

         

        Like if i need to print all the testcases with Execution Flag="Y" using that array tests_to_run. 

  • baxatob's avatar
    baxatob
    Community Hero
    What did you mean saying "print"?
    If you want to output the resulting value e.g. to the log, use:

    Log.Message(str(get_test_suite(your_excel_file_driver)))

    tests_to_run is a local variable inside get_test_suite() function.
    • Rajesh2's avatar
      Rajesh2
      Contributor

      Hi baxatob. I was asking like how to print only the first value?

       

      Like from ['TC1138', 'TC996', 'TC1135', 'TC1138', 'TC1140'] i need to print only 'TC1138'.

       

      Can you help with this problem?

      • baxatob's avatar
        baxatob
        Community Hero

        Rajesh2,

         

        my_list = [1, 2, 3, 4, 5]
        
        my_list[0] == 1
        
        my_list[-1] == 5

        etc...

        You ask very fundamental questions. I believe you need to open Python's Tutorial where you will find all answers and more.

        It's impossible to code something without that knowledge.

  • Hi All,

    I'm not able to find the solution.please provide solution with java script

     

    Thanks 

    vinoth G