Automatic Test Creation

 

 

User's Requirement

 

From a Test Plan folder it should be possibile create a test automatically inside the last folders of the tree.

 

 

Proposed Solution

 

Creation of a button in Test Plan Section that create a dummy test into the last folders of the tree in the case they are empty.


 

 

______________________________________________________________________________

 

Implementation on the Product

 

We will add a new button in Test Plan that do these operations:

  • extract the list of all the folders on which the initial path is the same of the selected folder
  • check the last folder (those that don't have other subfolder or test)
  • creation of a virtual test object (NULL)
  • add all the default values for the mandatory fields.

 

1. ActionCanExecute: call of the Sub

Function ActionCanExecute(ActionName)

On Error Resume Next

Dim Res

Res = True

 

'Suppose that the action called from the button is act_CreaTest

if ActionName = "act_CreaTest" then

    'call TestPlan sub

    Test_CreazioneAutomatica

end if

 

ActionCanExecute = Res

On Error Goto 0

End Function

 

 

It is necessary declare a global variable inside the Common Section that will be the Selected Folder. So we declare at the begin of Common Module the object call Folder_TP as:

 

Dim Folder_TP

 

We will insert into the MoveToSubject Sub (in TestPlan Module) this instruction

 

Sub MoveToSubject(Subject)

On Error Resume Next

     Set Folder_TP = Subject   'Subject now will be a global object

On Error Goto 0

End Sub

 

I must manage also its destruction with this code:

 

    set Folder_TP = Nothing

 

in both sub: Test_MoveTo (under TestPlan Module) and ExitModule (under Common Module)

 

 

 

2. The Sub to Create the Dummy Test. It will extract the list of Children of the Selected Folder and search for those that are the last and that are empty.

 

Sub Test_CreazioneAutomatica

On Error Resume Next

Dim ListOfSons, MyCom, RecSet, MyTest

 

'check if the Selected Folder has at least one Child

if Folder_TP.Count > 0 then

 

     'load the list of Children

     Set ListOfSons = objFlder_TP.FindChildren("",False,"")

 

        'do a for cyle for each son
        for each El_Fld in ListOfSons

 

          'Check if the folder is one of the last (.Count<1) and it is not Unattached 
          if El_Fld.Count < 1 And _
             El_Fld.Name <> "Unattached" then

 

             'query to understand if under the folder there aren't tests.

              qry = "Select count(*) from test where ts_subject = " & El_Fld.NodeID

       

              'creation of Command object to execute the query

              set MyCom = TDConnection.Command
              MyCom.CommandText = qry

            

              'execution of the query and save the result into the RecordSet object
              set RecSet = MyCom.Execute

 

              'I start from the 1st record of the RecordSet

              RecSet.First

             

              'Check if the folder is empty

              if RecSet.FieldValue(0) = 0 then

                'test creation 

                set MyTest = TDConnection.TestFactory.AddItem(Null)
                MyTest.Name = "TestName"
                MyTest.Type = "MANUAL"
                MyTest.Field("TS_SUBJECT") = El_Fld.NodeID

 

                'set all mandatory fields value

                MyTest.Field("TS_USER_01") = "Valore"
                .....

 

                'Post all the info to the DB table and Refresh.
                MyTest.Post
                MyTest.Refresh

         

                'Destruction of MyTest object
                set MyTest = Nothing               

 

              end if

 

              'destruction of the objects

              Set RecSet = Nothing
              Set MyCom  = Nothing

 

          end if

 

        next

 

     set ListOfSons = Nothing


end if

 

'Refresh Action for the GUI.

Actions.Action("act_filter_refresh").Execute 

 

On Error Goto 0

End Sub

 

 

Pag: <<    <    >    >>