Forum Discussion

ray_mosley's avatar
ray_mosley
Frequent Contributor
13 years ago

Getting project information

When you set up project suite and project test items with enabled test items, the information is available to your jscript:    

    var ti =Project.TestItems;  

    var tiName = ti.Current.Name



HOWEVER, when you just run the script you are working on - that is, you do NOT use Run Project or Run Project Suite, but you execute using the Run Current Routine button - the script terminates on  ti.Current.Name (object required).



If I know how the executing script was started, I can set a dummy script name like UNKNOWN and prevent terminating execution (i.e., no execute the ti.Current.Name).



How can I tell which method

   Run Project Suite

   Run Project

   Run Current Routine

was used to start the currently executing jscript?



Thanks in advance.





  • I use this code in our scripts to determine whether I am running in a test item or not:



    function NotRunningInTestItem()

    {

      return !Project.TestItems.Current;

    }



    For your purposes, to get a test name you could do something along the lines:



    var testName;

    if (NotRunningInTestItem())

      testName = "unknown";

    else

      testName = Project.TestItems.Current.Name;



    Or if you want to be terse:



    var testName = !Project.TestItems.Current ? "unknown" : Project.TestItems.Current.Name;



    As far as distinguishing whether you're running the Suite or an individual Project, I don't know how you would do that.
  • ray_mosley's avatar
    ray_mosley
    Frequent Contributor
    Bert,



    Thanks for your response. I am using your code now, even giving you attribution!

    Thanks.