02-07-2017, 12:28 AM
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 enabled(case of textboxes).
To solve this problem I thought, before the call to any action on the object, test if the object exists, is visible and enabled, if the 3 or 2 properties are true, then make a action with the object. Testing these properties of the object would be done until a timeout has been exceeded. If the timeout was exceeded an exception would be thrown to be handled.
I developed the code below, but the result is very unstable behavior:
Could someone help me?
Any help will be welcome.
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 enabled(case of textboxes).
To solve this problem I thought, before the call to any action on the object, test if the object exists, is visible and enabled, if the 3 or 2 properties are true, then make a action with the object. Testing these properties of the object would be done until a timeout has been exceeded. If the timeout was exceeded an exception would be thrown to be handled.
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 ...
- Is there a UFT/VBScript solution that solves this problem?
- If there is a problema in my algorithm, where are the errors?
Could someone help me?
Any help will be welcome.
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
print "end prepareObj " & obj.GetTOProperty("TestObjName")
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