Forum Discussion

pavanmac's avatar
pavanmac
Contributor
8 years ago

How to split an array ?

How to split an array ?

 

Array=[ctrl_id, data, action, keys]

 

This should be done using testcomplete with python. 

 

Array=[]
for i in range(2, RowCount+1):
#for j in range(1, ColumnCount + 1):
getValue = VarToString(Excel.Cells.Item[i,2]) #+ '\r\n'
Array.append(getValue)

for i in range(len(Array)):
Log.Message(Array[i])

 

can any one please help me with this. 

3 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    Not clear what you have on original array and how would you like to dived it.

    pl. provide an example...we can give a try

     

    Also not clear why you make a big array out of excel items instead of creating small arrays you need at first instance.

    something like below...........

      
    Array=[]
    for i in range(2, RowCount+1):
      getValue = VarToString(Excel.Cells.Item[i,2]) 
      Array.append(getValue)
      if getValue == "keys": # have to identify if it's a key( looking at actual data) 
         Log.Message(Array[i])  # or a function call to do what you need to do with array........
         Array.clear()

     or if you would like to break array to equal part run and see below code......

     

    C = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',1,2]
    def list_slice(S, n):
        return [S[i:i+n] for i in range(0,len(C),n)]
        
    def showSlices():    
        Log.Message(str(list_slice(C,4)))

      

    • pavanmac's avatar
      pavanmac
      Contributor

      Hi , 

       

      Thank you for the reply. NisHera

       

      Actually we have test cases with navigation steps followed. So, based on the testcase we need to fetch the navigation values and store it inside an array. Then this array should be split into 4 slices and for each slice i need to send the navigation step to it and should pass to all the values till the excel cell reads null.. EX: For ctrl_ID it should read ctrl_id and send buttonok to the application.. and it should do it till the excel cell value is null.

       

      I have the excel sheet attached to it please take a look into it! 

       

      This should be done in testcomplete using Python !! 

      • NisHera's avatar
        NisHera
        Valued Contributor

        What you are trying to do seems possible. But would be complex if you are novices for  TC , Python.

         

        Automate testing involves testing, programming and project management

        First you have to break down complex task to manageable small chunks depending on what you have what you need and your skills and your application (project management). Which we cannot help that much.

         

        But after that when you have specific questions (programming) we will able to help.

        Also if you have questions on best approach in particular situation (Testing) the forum could guide you.