Any way to not re-instantiate global vars for every test execution?

Use case: test automation with UiPath.
I am trying to add a GUID to my logs that is constant over all my test cases, but re-instantiated for every run (that may contain multiple test cases).

It seems UiPath always starts every test case as a separate execution. I would like to be able to correllate execution logs from all tests in a test run when I run a suite of tests.

I tried to create a global variable with System.Guid.NewGuid.ToString() as its value. However, this variable is re-instantiated for every execution (and thus not really global, while the scope suggests as much). Is there any way to achieve what I want?

Hi @Tom_Heintzberger,

I agree that the way UiRobot.exe executor is setup for executing test cases is a little cumbersome to work with. We also struggle with this although not exactly what you are experiencing Test cases in a test set trigger multiple logins to VDI/VM

What we know
UiPath Test Suite considers each Test Case as its own independent entity, i.e., lets say a test case is doing some operation in an application all the preconditions to the operations have to be within the logic of the test case. For example, launch, login, navigate to target element/scenario. This means that the executor has to reset all previously stored values in runtime, be it local or global variables.

Officially, I see a way to achieve what you are looking for (3), but there is definitely two workarounds, both should work. In short, you are looking for a way to ensure that you have a Unique Identifier for all your test cases running in a given test set.

Global variables in test cases are therefore not statefull (kind of a short term memory), but Orchestrator assets or a local text file can be statefull resources you can use. The two possible ways you can try

  1. Setting asset in the first running test case, getting asset in all test cases

    Choose the first test case which triggers in your test set. You will have to check which test case runs first in your test set. Note that we cannot set an order ourselves see the explanation from @Horea_Soanca here : Run test cases in order, but once you choose the test cases in your test set by trial and error you will know which of the test cases runs first. This workaround needs to be part of that test case.

    a. In your first test case in the Given sequence, first Create a GuiD and then save the Guid to an asset in Orchestrator (say text asset) using Set Asset activity.

    b. In your other test cases and if needed in the first one as well, you get the GuiD from Get Asset activity and use it in your test case log string.

  2. If you rather prefer doing workaround 1 using a text file in the robot machine itself
    You set the GUiD to a text file while starting the first test case and all test cases will then read the new GUiD from the text file (any text formatted file) and log it as needed.

In both the cases you will ensure

  • A new GUiD is created for every run of the test set
  • All test cases within the test set use the same unique identifier
  • The logs can be polled to group test sets and their test cases
  1. Other ways achieving this without using GUiD
    Last time I checked the Test Manager Database, I could see relational tables for each test set and foreign keys to test cases running within those test set, I cannot remember the key name but I faintly remember it was an id (GUiD). UiPath Test manager backend thus ensure that you have a unique identifier for all test cases running as part of a test set. This is assuming that you are using On-Premises test manager and not the Automation Cloud.

    If you are using Automation Cloud then you can get these from the API endpoint
    I am unsure exactly which endpoint will get you the relation, but I am sure you can review the swagger documentation.

I would also request you to lodge a feature request here if you feel this issue is hindering your implementations : Test Suite - UiPath Community Forum

Let us know if you need more help in achieving this.
Hope this helps you and others. Cheers!

Hi @jeevith,

Thank you for your extensive reply, I believe there’s some pointers I can work with. I’d like the solution to be compatible with both on-prem and cloud orchestrator, so I will try the Asset route first. Also, one of the end-goals here is to be able to create dynamic test set runs containing only the most relevant test cases for a given context, so the option of ‘knowing’ which test runs first is sort of off the table :frowning:

Ideally we should have as little user interaction for this as possible, so It would be ideal to achieve a way to conditionally set an asset if the value is an empty string, or pass it as . That way I should be able to just use an exectution template to set it as needed. Then I can have all TC’s log the same value to be able to correlate them. The last thing I’ll have to figure out is to detect the end of the run…

I’ll also try to work out a feature request to somehow correlate set cases that were executed together (be it from orchestrator, or even from studio’s test explorer alike). This could ofcourse also easily be achieved by introducing the very common concept of BeforeAll/AfterAll or high level setup/teardown routines that have the ability to set or clear assets or real global variables.