---
title: "Test Automation Example: Error Handling"
slug: "test-automation-example-error-handling"
updated: 2025-02-03T10:15:05Z
published: 2025-02-03T10:15:05Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://success.panaya.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Automation Example: Error Handling

## Error Handling

Error handling is often crucial during script execution. One approach is to check whether an element exists, save the result to a parameter, and include a ‘go to section’ for managing errors.

For example, consider a workflow in SAP GUI to verify whether a material exists in transaction ME21N. If a non-existent or inactive material number is entered, an error message will appear at the bottom of the SAP GUI screen.

## Possible solutions to capture an error

Store the error message text in a **parameter**, then use a "**Go to section**" command configured to trigger only if the parameter matches a specified value.

![](https://cdn.document360.io/f404076c-de23-4609-848e-2dfd4ef701b0/Images/Documentation/store_error.png)

Error messages in SAP GUI can vary depending on whether the material exists or is active. To account for this variability, the [len()](https://success.panaya.com/docs/automation-functions#len) function in ScriptBuilder is used.

This function returns the length of the error message string.

- If the length is greater than zero, it indicates that an error message exists and should be handled.
- If no error message is present, the string length is zero, and no error handling is needed.

Sample error message at the bottom, since Material 1300 does not exist:

![](https://cdn.document360.io/f404076c-de23-4609-848e-2dfd4ef701b0/Images/Documentation/error_1.png)

The screenshot below displays another error message captured by ScriptBuilder, which then redirects to the “Error Management” section for handling.

![](https://cdn.document360.io/f404076c-de23-4609-848e-2dfd4ef701b0/Images/Documentation/error_2.png)

The section “**Error Management**” in the script contains the necessary error-handling logic. This could include:

- Logging Errors: Record the error message and relevant details.
- Default Values: Assign default values to variables or inputs when invalid or missing data is detected.
- Redirect Workflow: Redirect the script to an alternate workflow or recovery path, such as skipping the problematic step or proceeding with a fallback process.
- Data Validation: Before proceeding, validate inputs and outputs to ensure compliance with expected formats, ranges, or constraints.
- Conditional Navigation: Navigate to specific sections of the script depending on the type or severity of the error.
- Error Recovery: Implement steps to correct the error automatically, such as retrying with adjusted inputs or resetting variables.
- Terminating the Script: Stop script execution gracefully.
