2 min read

Enhancing Tosca with PowerShell: Managing Dynamic Downloads & File Edits

Enhancing Tosca with PowerShell: Managing Dynamic Downloads & File Edits

Problem Statement: Automating Dynamic File Handling in TOSCA.

 

Handling downloaded or exported files is a common challenge in test automation. In Tricentis Tosca, dealing with dynamically named files and modifying text file content can be difficult due to its default limitations.

This post explores how integrating PowerShell with Tosca’s TBox Start Program module can help overcome these challenges and enable efficient automation of dynamic file-handling scenarios.

 

Solution Approach: Overcoming Tosca’s Limitations with PowerShell

To handle dynamically named downloaded files and automate text file modifications, we can leverage Tosca’s TBox Start Program module along with PowerShell commands. This allows us to extend Tosca’s automation capabilities beyond its built-in functionalities.

Below are two common scenarios where PowerShell helps address Tosca’s limitations.

 

Scenario 1: Handling Exported Files with Dynamic Filenames

The Challenge:

In many applications, data is exported in formats like Excel or PDF, with filenames that include a numeric suffix (e.g., Report_1.xlsx, Report_2.xlsx). Each time a file is downloaded, the name changes, making it difficult to automate actions based on the latest file.

Since Tosca lacks native support to detect dynamically named files, identifying and working with the most recently downloaded file becomes challenging.

The Solution:

We can use PowerShell within Tosca’s TBox Start Program module to retrieve the most recently downloaded file and store its name for use in automation.

PowerShell Command:

(Get-ChildItem C:\Users\UserName\Downloads |
Sort-Object LastAccessTime -Descending |
Select-Object -First 1).Name | Clip

How It Works:

Fetches all files from the Downloads folder.
Sorts them by LastAccessTime (latest file first).
Selects the most recent file.
Copies the filename to the clipboard for use in Tosca’s automation.

Once the filename is copied, Tosca’s TBox Clipboard module can store and utilize it in subsequent steps.


 

Scenario 2: Modifying Text File Content

The Challenge:

Another common requirement is modifying text files, such as replacing specific characters.

For example, we might need to replace commas (,) with underscores (_) in a text file. However, Tosca does not provide built-in functionality for direct text file modifications.

The Solution:

Using PowerShell, we can automate text file modifications and execute commands through Tosca’s TBox Start Program module.

PowerShell Command:

$tabFileContents = Get-Content -Path C:\Users\UserName\Desktop\Text1.txt |
ForEach-Object {$_ -replace ',', '_'} |
Out-File -FilePath C:\Users\UserName\Desktop\Text2.txt

How It Works:

Reads the contents of Text1.txt.
Replaces all commas (,) with underscores (_).
Writes the modified content to Text2.txt.

By executing this command in Tosca’s TBox Start Program module, text file modifications can be seamlessly automated.




Note: Replace UserName with your actual system username before running the scripts.

 

Conclusion:

By integrating PowerShell scripts with Tosca’s TBox Start Program and TBox Clipboard modules, we can overcome Tosca’s default limitations. This approach enables us to:

  • Identify and use the most recently downloaded file dynamically.
  • Modify text file content as required for automation scenarios.

With this solution, we can extend Tosca’s capabilities and achieve seamless test automation for file handling and content modification scenarios.

 

EWM-PP Integration: Consumption Options in S/4HANA Across Cloud & On-Prem

EWM-PP Integration: Consumption Options in S/4HANA Across Cloud & On-Prem

EWM-PP integration and various consumption options in S/4HANA with SAP Public/ Private Cloud / On-Premises

Read More
Accelerating Digital Transformation: Mygo’s Strategic Alignment with SAP’s 2025 Vision

Accelerating Digital Transformation: Mygo’s Strategic Alignment with SAP’s 2025 Vision

As SAP doubles down on its “Suite First, AI First” strategy for 2025, Mygo Consulting remains at the forefront of driving innovation through RISE...

Read More
EWM-PP Integration: Consumption Options in S/4HANA Across Cloud & On-Prem

11 min read

EWM-PP Integration: Consumption Options in S/4HANA Across Cloud & On-Prem

EWM-PP integration and various consumption options in S/4HANA with SAP Public/ Private Cloud / On-Premises

Read More
Is SAP FM built into S/4HANA?

1 min read

Is SAP FM built into S/4HANA?

SAP Fleet Management (SAP FM) is not a built-in component of SAP S/4HANA. However, SAP FM can be integrated with SAP S/4HANA to provide a...

Read More
Advancing Innovation with Tricentis and Mygo Consulting

3 min read

Advancing Innovation with Tricentis and Mygo Consulting

Mygo Consulting is dedicated to making innovation accessible and impactful. Together with Tricentis, we’re supporting businesses in using technology...

Read More