Wikis - Page

How to handle an 'invalid object handle exception' error in SilkTest Classic

0 Likes

Methods for handling the same problem in Silk4J can be found here:

https://community.opentext.com/devops-cloud/silk-test/w/tips/17643/handling-a-com-borland-silktest-jtf-common-invalidobjecthandleexception-in-silk4j

This error occurs when there is a change in the application under test (AUT) and from a GUI perspective a handle to a given object gets invalidated.  This is something we cannot check in the Open Agent at runtime nor can we guarantee the validation of the object handle as this is not within our control.  Furthermore, it is not recommended to use a Find or FindAll method outside the test method because the resulting handle to the desired TestObject is only valid in one particular GUI situation/context.

The following function should help by ensuring that the handle for the given object remains stable for the required number of checks. The function requires two inputs: the locator of the object that is giving trouble and the number of checks to be carried out.

[-] boolean validateHandle(string sLocator, integer iChecks)
    [ ] int i=0
    [ ] int j=0
    [ ] boolean bFound =true
    [ ] window wToFind=null
    [ ]
    [ ] // Put the code into a check loop
    [-] while(true)
        [ ] // See if we can get the current handle
        [-] if bFound==true
            [ ] wToFind=Desktop.Find(sLocator)
            [ ] bFound=false
        [ ] // Loop through attempts to check for handle stability
        [-] for(i=1;i<=iChecks;i )
            [ ] sleep(0.1)
            [ ]  bFound=wToFind.Exists()
            [-] if bFound==true
                [ ] j=j 1
            [ ]
        [ ] // If the handle has been stable iChecks times then use it
        [-] if j==iChecks
            [ ] break
        [ ] // Otherwise it's not useable
        [-] else
            [ ] bFound=false
            [ ] break
    [ ] return bFound

Labels:

Support Tips/Knowledge Docs
Comment List
Related
Recommended