Forum Discussion

rickm's avatar
rickm
Contributor
13 years ago

Script access to variables for ProjectName, KeywordTestName, etc

I've searched but I can't find how to access things such as the Project Name, the Keyword Test name currently running and the currently running TestedApp.  Others might be nice, such as the folder containing the Keyword Test.



I'd like to access these from the Keyword Test and from scripts called from a Keyword Test.



I'd also like access from a Script Extension at record-time.



Another is variable substitution in the instructional text of a stored Manual Checkpoint



The Project Name can be set once in the Project Variables. That's not too bad, but setting each Keyword Test name in each test's Variables is a bit much.



Is there a pool of global variables or a method call somewhere, or some elegant tricks I need to learn?

17 Replies

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Rick,


    There was a similar feature request some time ago, so I increased its rating and described your case.

    The request does not define a specific object, to which a method or property should be added. It just says that our users need a way to determine the current test name (test or script routine).


    Sorry, I have no information to which object the new method or property will be added.

    At the moment, I think, this will not be KeywordTests as this functionality can also be applied to script tests.

  • newbie23's avatar
    newbie23
    Occasional Contributor
    I like Rick's suggestion.  But it would be nice if "Project.TestItems.Current.Name" could be smart enough to know if you are running as a project or individual keyword test for people like me that run one way for tests and another for debugging :)
  • newbie23's avatar
    newbie23
    Occasional Contributor
    Strike my last comment on having that path be able to tell whichever way it is running (as project, keyword, script)... I miss-understood how it was grabbing the name.



    +1 on having the feature implemented so you can grab the name from keywordtests or from script - I would also use that quite a bit

  • Yes, it took me awhile to finally understand that Project.TestItems refers to KeywordTests added to the Project's list of tests to run. The name that is returned from Project.TestItems.Current.Name can be different form the actual KeywordTest name since there is an editable field for this name.



    I think I equated the name TestItems to KeywordTests because when you
    click in the explorer panel to add a new KeywordTest, it says "add item".



    What we want is something that might look like Project.KeywordTests.Current.Name, and it would always return the name of the KeywordTest no matter where it was run from. Something similar for scripts would be useful as well.
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Rick,


    What we want is something that might look like Project.KeywordTests.Current.Name, and it would always return the name of the KeywordTest no matter where it was run from. Something similar for scripts would be useful as well.


    Rick, you can get the test name (test name, not test item's name) by using the following property:

      Project.TestItems.Current.ElementToBeRun.Caption

    Unfortunately, currently it works only for test items, not for script tests.


    Scott,



    Could you please describe what you need to know the current test name for? Developers are still gathering information for the feature... Your description would help us understand the problem. Also, maybe we'll be able to find another (better) solution.

    • matt_tarka's avatar
      matt_tarka
      New Contributor

      Why would I want to know the current keyword test name?

       

      Because I archive files when running many keyword tests. When I archive the files, I want the archive location to contain the name of the test associated with the folder contents. Imagine yourself having 100 folders from different tests and asking yourself, which is associated with KeywordTestA, KeywordTestB, or KeywordTestC.  In order to name, the folder I need the name of the keyword test, not TestItem.