
How many hours do you spend maintaining your Tosca Commander test cases? Probably more than you'd like, right?
Tosca Commander is one of the best test automation tools on the market. But you still need to maintain the test cases you create.
This blog contains a small selection of experiences, tips, and tricks that our Automation Genius team has gathered and refined over the years. These can save you many hours of headaches and maintenance effort in the future.
The test case is created and it runs perfectly. But as soon as you restart the System Under Test (SUT), nothing works anymore! What happened?
To control an element within a SUT, Tosca Commander requires technical IDs to identify it. However, in some cases, these technical IDs incorporate a dynamic element, such as a number. This element can change from time to time, after a SUT restart, or following a redeployment.
This makes identifying the element more difficult, and you need a way to compensate for this. A very simple way to do this is to integrate wildcards or regular expressions (RegEx) into the technical ID.
The following screenshot shows a regular expression example where the caption, i.e., the window title, is used as the technical ID. The regular expression allows the window to be identified in two languages.

It's after 5 PM and suddenly your Tosca test cases are failing! Your SUT likely behaves differently at certain times of day. This could be because the SUT undergoes a processing change after the workday ends.
In such a case, it may make sense to create two test cases: one for before 5 pm and one for after 5 pm.
However, this requires detailed knowledge of the SUT, precise documentation, good planning, and a functioning scheduler. Following the Pareto principle, you might conclude that the effort required for these two test cases exceeds your already limited budget.
If your testers are experienced enough, they will be aware of these limitations. In this case, it may be sensible to allow two different results in one test case to be correct and completely avoid the additional planning, setting up a scheduler, extended documentation, and even creating a second test case.
You can use regular expressions for this, here's an example:
{REGEX["Placed|Done"]}
Valid values for the status are now "Placed" and "Completed".

Verification is the most important part of a test case. This is often done by verifying a value within a text string of the application. In some test scenarios, values in buffers must be verified because there are no controls where this can be directly checked. So how can you verify buffers?
It sounds a bit counterintuitive, but the easiest way to do this is using the "TBox Set Buffer" module. You specify the name of the buffer you want to check, and "Value" contains the value it should match. However, you use the "Verify" action mode instead of "Input".
In the following example, the buffer "Status" is checked for the value "Payment successful".

Following the previous tip, we'll take this one a step further. String operations are a crucial part of processing text in the SUT (System Under Table). To retrieve your strings from your SUT, you need to buffer them. Often, more text is buffered than necessary. For example, from the text "Sum: CHF 350.00", only the "350.00" is needed.
The simplest way is to use the dynamic expression {XB}. This expression allows you to cache parts of a fixed set and verify it simultaneously. Here, the example above is verified, and the sum is extracted into the buffer "Sum".

The resulting buffers received the following values:

A more advanced method for buffering parts of a string is, again, the use of regular expressions. RegEx searches for patterns rather than a fixed text and is therefore more flexible.
It is also possible to define "Capturing Groups". Tosca has implemented these in such a way that the found "Capturing Groups" values are transferred to Buffer.
Here is an example of a regular expression that buffers an address into its components:

And here are the resulting buffers:

Bonus tip: Infometis YouTube
Michael Weiglein provides a great example with a detailed explanation in his YouTube video: https://youtu.be/q9cQTuo_oD4.
If you want to shorten a string to an optional length, you can easily do this using regular expressions (RegEx). It's optional because it might not be known beforehand whether the original length of the base string is shorter or longer than that of the target string. The length specification {0,15} indicates that the target string will be shortened to 15 characters if the base string is longer than 15 characters. If the base string is shorter than 15 characters, then the target string will be exactly the same length as the base string.

Resulting buffers:

If you have primarily worked with Tosca Commander's CALC function, the new TBox functions now offer a better alternative in most cases. The previous tips are good examples of how this works without CALC. Firstly, you no longer need Excel pre-installed, and secondly, execution with TBox Dynamic Expressions is significantly more performant.
Since version 14.2, Tosca Commander now supports "String Operations" using Dynamic Expressions. These can also replace a large part of the CALC functionality.
Here is just a brief overview of the newly available operations:
{STRINGTOLOWER[InputText]}:
{STRINGTOUPPER[InputText]}:
{TRIM[InputText][Optional Parameters]}:
{BASE64[InputText]}:
{STRINGREPLACE[InputText][Pattern][NewValue][Optional Parameter1, Optional Parameter2]}:
{NUMBEROFOCCURRENCES[InputText][Pattern][Optional Parameter]}:
{STRINGLENGTH[InputText]}:
More detailed information, including examples, can be found on the following Tricentis documentation page.
In this blog, we've presented seven tips, including a bonus tip, on how to elegantly solve automation problems with Tosca. These tips have already saved the Automation Genius hours of maintenance work, and we hope they will for you too.
If you would like more tips on Tosca, you might also be interested in the following article:
Top 5 mistakes Tosca beginners do and how to avoid them
In addition, we offer certified Tosca training courses where we are happy to share our knowledge and experience with you in greater depth.
Happy Automation!
Would you like to utilize our expertise and implement technological innovations?


Do you have a question or are you looking for more information? Provide your contact information and we will call you back.