I'm automating tests using UFT 12.52 for an application.
I captured the objects for a repository and then started to create a sequence of actions on the objects.
However, there is a frequent problem. Before calling an action on an object it needs to exist, be visible, and in some cases be enabled (e.g. textboxes).
To solve this problem I tried testing if the object exists, and is visible (and enabled, if applicable), before the call to any action on the object. If those are true, then make a action with the object. Testing these properties of the object is done until a timeout has been exceeded. If the timeout is exceeded an exception should be thrown.
I developed the code below, but the result is very unstable behavior:
- Non-recognition of the current object being tested
- No recognition of the parent object
- UFT starts to test an object of the 2nd line, before executing the action on the object of the 1st line ...
I have the following questions:
- Is there a UFT/VBScript solution that solves this problem?
- Are there problems in my algorithm?
Here is my code:
Function test()
clickObj SwfWindow("<parent object name 1 >").SwfButton("<child object name 1>"), true
clickObj SwfWindow("<parent object name 2 >").SwfButton("<child object name 2>"), false
End Function
Function clickObj(obj, isEnabled)
If (prepareObj(obj, isEnabled) = true) Then
obj.Click
Else
Err.Raise 424 'Error 424 = "Object required"
End if
End Function
Function prepareObj(obj, isEnabled)
If isEnabled = true Then
If ((testObjProperty(obj,"exist") = true) And (testObjProperty(obj,"visible") = true) And (testObjProperty(obj,"enabled") = true)) Then
prepareObj = true
else
prepareObj = false
End If
Else
If ((testObjProperty(obj,"exist") = true) And (testObjProperty(obj,"visible") = true)) Then
prepareObj = true
else
prepareObj = false
End If
End If
End Function
Function testObjProperty(obj, propertyName)
Dim startTime : startTime = Timer
Dim elapsedTime : elapsedTime = 0
Dim propertyOk : propertyOk = false
Dim timeout : timeout = 45
Do
Select Case propertyName
Case "exist"
propertyOk = obj.Exist(1)
Case "visible"
propertyOk = obj.GetROProperty("visible")
Case "enabled"
propertyOk = obj.GetROProperty("enabled")
End Select
If propertyOk = true Then
testObjProperty = true
Exit Function
Else
elapsedTime = Timer - startTime
End If
Loop While timeout > elapsedTime
testObjProperty = false
End Function