Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[UFT 12.52/VBScript] Test object exist, is visible and enabled before take an action
#1
Not Solved
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:
  • 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 share the following code and the following doubts:
  • Is there a UFT/VBScript solution that solves this problem?
  • If there is a problema in my algorithm, where are the errors?
Thank you for your attention.
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  General run error when Exist fails msacks 1 1,863 02-08-2019, 02:12 AM
Last Post: Ankur
  Can we integrate HP UFT with VSTS Test Manager or Sandpit Version rodgernadal 0 2,131 06-07-2017, 02:18 PM
Last Post: rodgernadal
  UFT 12.02 Compatibility for IE 11.0 : Fail to identify the defined Object Amruta_121 9 11,180 01-11-2016, 12:45 PM
Last Post: vinod123
  HAVING PROBLEM IN CREATING OBJECT OF TEST BATCH RUNNER mayankchauhan 0 3,438 04-04-2014, 05:29 PM
Last Post: mayankchauhan
  how to find Excel file exist or not in vbscript code sree.85 3 11,252 08-22-2013, 11:42 AM
Last Post: akhandesh

Forum Jump:


Users browsing this thread: 1 Guest(s)