Forum Discussion

sastowe's avatar
sastowe
Super Contributor
13 years ago

execute once for entire suite

I have a bunch of projects that all live within one suite. I want to execute something once regarless of what is selected. If tester chooses to execute the suite, run the sequence once. If they select a projec, run the sequence once. Is this possible?



When I run a OnTestStart event, it seems to rerun with each project. Am I being dense and blind? Thanks



S

2 Replies

  • jose_pita's avatar
    jose_pita
    Super Contributor
    What do you mean by "regardless of what is selected"?



    When I want to run all my projects within a suite I just make sure they are enabled on the project suite page and run the project suite (Ctrl+alt+F5) , but, in order for the projects tests to run, they need to be selected on each project page like the image shows...
  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor


    In the GeneralEvents_OnStartTest routine you could use an if statement to check a temporary project variable.



    I created a boolean type temporary project variable with default value set to true. It will be true for the test item then it is changed to false below. In my case I only wanted to run a Login script before the first test item selected. Another option would be to use script-level code (code outside functions and subroutines) that is executed automatically when the script loads.



    Sub GeneralEvents_OnStartTest(Sender)



      If Project.Variables.blnFirstTestItem = True Then  

        ' code only executed once before the first test item

        Login

        Project.Variables.blnFirstTestItem = False

      End If



      ' other code to execute before every test item

    End Sub