Ask a Question

Cannot access current test name in script

Occasional Contributor

Cannot access current test name in script

We have the method below which is trying to log the name of the test currently being executed

function Test()

  var TestItems;

  TestItems = Project.TestItems;
  Log.Message("The " + TestItems.Current.Name + " test item is currently running.");

This is being run in TestSetup


This is just resulting in a very unhelpful JScript error

Object required

Stepping through, it appears as though Project.TestItems is assigned, but not Current

Has anyone ever had this problem?

We are using TestComplete using JScript as the scripting language


Project.TestItems is the object that Test Complete says to use to get information about the Project being run. As I mention above, there is information about the Project and Project.TestItems but TestItems.Current is null


Its as if I am calling this too early but I cant see where else to call it. It is being called in TestSetup



Frequent Contributor

Hi @psaxton,

   How are you running your test item? The error is because you have not added test item under your project / Even though you have test item you are trying to right click on that particular routine and selecting run current routine. In either case

TestItems.Current would be Null.


I tried running you code by adding a test item and selecting the "Run focused item" and the code is working fine. Please find attached snapshot.






Occasional Contributor



Sorry but your response is very unclear


Please can you explain exactly how to do this, or send a working example?


Please see the screenshot attached


As you can see, the test is already part of the project


When we debug, Project.TestItems.Count is 121 which is correct, but CurrentItem is null


Our tests 

You're getting the failure because you're running an individual function not a test item.


To use TestItems.Current you need to run it from the Project page.




Click the Accept as Solution button if my answer has helped
Esteemed Contributor

@cunderw wrote:

You're getting the failure because you're running an individual function not a test item.


To use TestItems.Current you need to run it from the Project page.



As @cunderw, to use TestItems.Current, the test needs to be run from the Project page.  One of your earlier posts does indicate that you do have a number of TestItems defined so it might not be a matter of adding your test as a TestItem, but more on the lines of just how you run it.

If you go to your project page and to the test item list, if you highlight the appropriate test item and click the button I've indicated below, you will run THAT test item. This should allow you to test your usage of TestItems.Current then.



Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Showing results for 
Search instead for 
Did you mean: