Forum Discussion

Edgar_Brodie's avatar
Edgar_Brodie
New Contributor
12 years ago

Disable test items during execution


Hi,



I would like to disable (child) test items during execution of the parent item.



A Project Suite variable (DoLightRun) is defined to manage skipping specific (child) tests that have this script attached:



function SkipMeAndMyChildren()


{


  if (ProjectSuite["Variables"]["GetVariableDefaultValue"]("DoLightRun"))


  {


    var childCount = Project["TestItems"]["Current"]["ItemCount"];


    var childIndex = 0;


    


    for (childIndex = 0 ; childIndex < childCount ; childIndex++)


    {


      //DOES NOT WORK BECAUSE PROPERTY IS READ ONLY 


      //Project["TestItems"]["TestItem"](childIndex)["Count"] = 0;  


      


      //DOES NOT WORK BECAUSE PROPERTY IS READ ONLY 


      //Project["TestItems"]["TestItem"](childIndex)["Enabled"] = false;


      


    }


 


    // Quit this parent test project


    Runner["Stop"](true);


  }


}



Is there some posibility to get this to work? I would really like to disable/enable test items during execution of the suite. Many thanks in advance for any tips.

  • Hi,



    > I don't know if you can from a script [...]

    No, this is not possible from the script.



    Alternative (to COM-based) approach may be to read some configuration file that specifies what test items should be either executed and/or skipped, iterate through all test items in the given test project and either execute or skip them.
  • Hi Edgar.



    I designed something similar here.

    I want some checkpoint to be critical and if they fail, I provide a list of TestItem to skip.



    First, I created an XML node that contains all my test item (including folders).

    If I want to disable an item or a folder, I push it into a List.

    I add an event handler on OnStartTest event that look if current test item is contains in the list of disabled one.



    If the item has been disabled, I call the Runner.Stop() and log a warning to explain why the item has been disabled.



    It works fine. Let me know if you are interested, I would provide some script.



    Cheers.



    Guillaume.
  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    I don't know if you can from a script, but you can do it from a COM application:





        Private Sub FindTestAndEnableRecurse(ByRef TCTest As TCTest) As Boolean

            FindTestAndEnableRecurse = False



            Dim TestList As TestComplete.ItcProjectTests_COMAccess = TestExecuteObject.Integration.TestSuite(TCTest.ProductName)

            Dim TestFound As TestComplete.ItcProjectTestItem_COMAccess = Nothing



            For i As Integer = 0 To TestList.Count - 1

                If TestList.TestItem(i).Name.ToUpper.Contains(TCTest.TestCode.ToUpper) Then

                    Log("Found test " & TCTest.TestCode & " at index " & i & ".")

                    TestFound = TestList.TestItem(i)

                    EnableDisableTest(TestFound, True)

                Else

                    EnableDisableTest(TestList.TestItem(i), False)

                End If

            Next



            If Not TestFound Is Nothing Then FindTestAndEnableRecurse = True



        End Function



        Public Sub EnableDisableTest(ByRef ThisTest As TestComplete.ItcProjectTestItem_COMAccess, bEnable As Boolean)

            ThisTest.Enabled = bEnable

            For j As Integer = 0 To ThisTest.ChildCount - 1

                EnableDisableTest(ThisTest.ChildTestItem(j), bEnable)

            Next

        End Sub

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    > I don't know if you can from a script [...]

    No, this is not possible from the script.



    Alternative (to COM-based) approach may be to read some configuration file that specifies what test items should be either executed and/or skipped, iterate through all test items in the given test project and either execute or skip them.
  • Thanks for the answers and the confirmation that I want something that is not supported.



    Also thanks for the tips on Com, however I am not sure my team wants me to invest into "getting into Com" in order to allow switching off branches and sub branches in our test item tree if the user (any of our testers) switches a checkbox as ProjectSuite variable...




    In my opinion, it would, for script-kiddies like me be very fulfiling if the property Project["TestItems"]["TestItem"](childIndex)["Enabled"] was not read-only. Maybe some day...





  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Edgar,


     


    Actually, we have a suggestion to implement this functionality, and your request has increased its rating. Thanks!


    At the moment, you can use Hugo's example.


     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Guillaume,


     


    Interesting solution! Of course, we are interested in your script :)