How to Handle Runtime Errors in UFT?
Consider you are going for a drive on a pleasant day, and suddenly, some error in the vehicle console pops up. That will be frustrating; sometimes, you might cancel the trip. That’s similar to the way runtime errors happen in UFT; there can be many reasons for them to occur.
Let’s review why runtime errors happen in UFT and how we can handle them.
Causes for Runtime Errors
Here are the common runtime errors and their examples in UFT:
Object Recognition Issue
- Cause: UFT fails to identify an object because the properties used in the script do not match those of the object in the application. This often occurs when the application’s UI changes after creating the script.
- Example:
Browser("B").Page("P").WebEdit("username").Set "user"
. If the “username” field is not present or its properties have changed, UFT will throw a runtime error.
Synchronization Issue
- Cause: The script attempts to interact with an object that is not yet loaded or available. This is common in web applications where elements load asynchronously.
- Example:
Browser("B").Page("P").Link("Login").Click
. If the “Login” link is not yet visible or interactive, UFT will encounter a runtime error.
Type Mismatch Error
- Cause: Occurs when a script tries to operate on a data type that is not suitable, like trying to add a number to a string.
- Example:
Dim x: x = "Hello" + 5
. would cause an error because it tries to concatenate a string with a number.
Incorrect Script Logic
- Cause: Errors due to logical mistakes in the script, such as invalid loop conditions or incorrect conditional statements.
- Example:
For i = 1 To 10: If i = 5 Then: Exit For: End If: Next
. If the Exit For is incorrectly used or based on a wrong condition, it could lead to a runtime error.
Resource Limitation
- Cause: This happens when the system runs out of memory or other resources, affecting the script’s execution.
- Example: This can occur in scenarios with extensive data manipulation or loading large objects, where UFT fails due to insufficient system resources.
Incorrect Path or External Resource
- Cause: The script fails due to an inability to access external files or resources, often because of incorrect file paths or network issues.
- Example:
DataTable.ImportSheet "C:\nonexistentFolder\myfile.xls", 1, "Global"
would throw an error if the specified file or path does not exist.
Unexpected Application Behavior
- Cause: The script encounters an unexpected state or behavior in the application, often due to unhandled application errors or changes.
- Example: If a script expects a confirmation dialog after a button click, but the dialog does not appear (perhaps due to a bug), subsequent steps interacting with the dialog will fail.
Handling Runtime Errors in UFT
You can follow the below tips to handle runtime errors in UFT:
-
Error Handling with Conditional Statements: Use conditional statements to check for the existence of an object before interacting with it. This can prevent object recognition errors.
If Browser("title:=MyApp").Page("title:=MyPage").WebButton("text:=Submit").Exist(10) Then Browser("title:=MyApp").Page("title:=MyPage").WebButton("text:=Submit").Click Else Reporter.ReportEvent micFail, "Object not found", "Submit button not found." End If
-
Synchronization Using Wait Statements: Implement wait statements to allow time for objects to load before interacting with them, reducing synchronization issues.
Browser("title:=MyApp").Page("title:=MyPage").Sync Browser("title:=MyApp").Page("title:=MyPage").WebElement("html id:=dynamicElement").WaitProperty "visible", True, 10000 Browser("title:=MyApp").Page("title:=MyPage").WebElement("html id:=dynamicElement").Click
-
Using On Error Resume Next for Type Mismatch:
On Error Resume Next
allows the script to continue running after an error, which helps handle type mismatch errors.On Error Resume Next Dim result: result = "Number: " + CStr(5) If Err.Number <> 0 Then Reporter.ReportEvent micFail, "Type Mismatch Error", Err.Description Err.Clear End If
-
Validating File or Resource Availability: Check if external resources are available before using them to handle errors related to file paths or external resources.
If FileExists("C:\someFolder\myfile.xls") Then DataTable.ImportSheet "C:\someFolder\myfile.xls", 1, "Global" Else Reporter.ReportEvent micFail, "File Not Found", "myfile.xls does not exist." End If
-
Exception Handling for Unexpected Application Behavior: Use a combination of conditional checks and error handling to manage unexpected application states.
Browser("title:=MyApp").Page("title:=MyPage").WebButton("text:=Confirm").Click If Browser("title:=MyApp").Page("title:=MyPage").Dialog("title:=Confirmation").Exist(5) Then Browser("title:=MyApp").Page("title:=MyPage").Dialog("title:=Confirmation").WebButton("text:=OK").Click Else Reporter.ReportEvent micFail, "Unexpected Behavior", "Confirmation dialog did not appear." End If
AI-Driven Test Automation: A Paradigm Shift
Initially, the test automation tools were used mainly to reduce the effort of manual testers. The frequently executed test cases were automated so the manual testers could focus on new scenarios.
However, creating and maintaining a script is always a nightmare as there has always been script dependency, so the tester should know programming. Also, the locators that depend on DOM elements can ail the test scripts anytime. But these were okay till a few years back.
Right now, the market trend is more aggressive, so the automation tools need to be more intelligent, and they should save the script maintenance effort. Also, they should be smart enough to generate test scripts and test data. Traditional tools like UFT Selenium failed to meet the expectations here.
testRigor outpowers other tools in all these aspects. With its integrated generative AI, testRigor provides various features that reduce the effort involved. It supports the creation of test cases and generates test data based on the test description provided. Also, testRigor doesn’t have any scripting language dependency. Anyone on the team can create or edit test scripts in plain English, allowing the development, management, SMEs, BAs, or other stakeholders to develop and run new test scenarios and increase test coverage.
enter "pants" in "search" click "search" click on the first "item" check that page contains button "add to cart" click "add to cart" click "cart" click "submit purchase"
Also, testRigor provides integrations with market-leading tools for test management, infrastructure providers, CI/CD, ERP, and CRM systems. You can check more about testRigor’s top features.
Summing Up
Currently, the quality of the product delivered to the end-user holds critical value. The future of any app can be attributed significantly to the extent and quality of software testing. To ensure the product is top-notch quality, the automation tools should be intelligent enough to accept and execute the delegated tasks from testers efficiently. Using the right tools like testRigor makes delivering excellent quality products easier with minimum cost, maintenance, and time.
Achieve More Than 90% Test Automation | |
Step by Step Walkthroughs and Help | |
14 Day Free Trial, Cancel Anytime |