Test Automation Example: Error Handling

Prev Next

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.

Error messages in SAP GUI can vary depending on whether the material exists or is active. To account for this variability, the 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:

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

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.