Forum Discussion

ajb's avatar
ajb
Occasional Contributor
6 years ago

Object destroyed using .Keys in TestComplete 12 and TC12.5

I'm having an issue where a VBScript script worked fine for years in previous versions of TC but often, but not regularly fails in TC12 and TC12.5. The point where it fails is always using .keys. Here are parts of the function:

function selectMenu(strMenuNumber,TimeOut)
If Sys.WaitProcess("QAD.Client", TimeOut).WaitWinFormsObject("ShellForm", TimeOut).Exists Then
Set QADNetUI = Sys.Process("QAD.Client").WinFormsObject("ShellForm")
If QADNetUI.WaitWinFormsObject("MdiClient","", TimeOut).Exists Then
Set MainGrid = QADNetUI.WinFormsObject("MdiClient","")
Else
Err.Raise 775,"selectMenu::WaitWinFormsObject(MdiClient, TimeOut)", "can not find MdiClient"
exit function
End If
Set MenuBar = QADNetUI.WinFormsObject("pnlTopHeaderParent")._
WinFormsObject("pnlTopHeader").WinFormsObject("_mnuShellMenuBar")._
WinFormsObject("_ShellMenuBar_Toolbars_Dock_Area_Top")
Set SearchBar = QADNetUI.FindChild("ClrClassName", "UltraTextEditor", 20)

.

.

.
'Enter the menu name, number or file name and run it
If QADNetUI.Exists Then
  With SearchBar
      .SelectAll()
     .keys"[Del]" 
     delay 2000
     Log.Message("Menu Number = " &strMenuNumber)
    .set_Text(strMenuNumber)
    delay 2000
    .keys"[Enter]"
  End With
  delay 3000
  Else
   Err.Raise 777, "selectMenu::QADNetUI.Exists", "Can not find SearchBar"
 End If
 Else
   Err.Raise 778, "selectMenu::WaitWinFormObject(QAD.Client, TimeOut)", "Can not find QADNetUI"
End If
End function

The script often, but not always stops at either of the .keys lines with the message; "The object was destroyed during method execution."

I have a workaround (it's kind of ugly), so I'm not looking for that. It just seems that TC12 and above has a problem with .keys that was not in earlier releases. I'm wondering if others are seeing this same behavior.

5 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    What happens when you like below,

     

    SearchBar.Keys("^a")
    SearchBar.Keys("[BS]")
    
    Log.Message("Menu Number = " &strMenuNumber)
    
    SearchBar.Keys(strMenuNumber)
    
    SearchBar.Keys([Enter])

     

    • ajb's avatar
      ajb
      Occasional Contributor

      Hi Shankar,

       

      It periodically gives the message "Window was destroyed during method execution." Your method for getting around the Del key is creative but I really don't need that step as I switch to using set_Text for the menu name. It still would get destroyed on the SearchBar.keys("[Enter]") in either case. I did notice that this time it said that the window was destroyed instead of the object. I have been getting both of those messages.

      I have a workaround that seems to work but it's not very pretty and I don't think it really needs to be this complicated. My main concern is that .keys for del or Enter seems to be unstable.

       

      For i = 1 to 4

      ' 'Log.Enable = False
      bolStillExists = SearchBar.Exists
      ' 'Log.Enable = True

      If Not bolStillExists Then
       Log.Warning("SearchBar object was destroyed. Finding it again.")
       Set SearchBar = QADNetUI.FindChild("ClrClassName", "UltraTextEditor", 20)
       End If

       Select Case (i)
       Case 1:
       SearchBar.SelectAll()

       Case 2:
       SearchBar.keys("[Del]")
       delay 2000
       Log.Message("Menu Number = " &strMenuNumber)

       Case 3:
       SearchBar.set_Text(strMenuNumber)
       delay 2000

       Case 4:
       SearchBar.set_Text(strMenuNumber)
       delay 2000
       SearchBar.keys("[Enter]")

       End Select
       Next



      Thanks for taking the time to help.

       

      Tony Biegen

  • ajb's avatar
    ajb
    Occasional Contributor

    I believe I resolved the problem in my code by moving one line. It seems to be stable but since the issue is erratic, I'll have to watch it for a while.

     

     'Enter the menu name, number or file name and run it
    If QADNetUI.Exists Then
    Set SearchBar = QADNetUI.FindChild("ClrClassName", "UltraTextEditor", 20) '<---moved this line into the If/Then
    With SearchBar
    .SelectAll()
    .keys"[Del]"
    delay 2000
    Log.Message("Menu Number = " &strMenuNumber)
    .keys(strMenuNumber)
    delay 2000
    .keys"[Enter]"
    End With
    delay 3000
    Else
    Err.Raise 777, "selectMenu::QADNetUI.Exists", "Can not find SearchBar"
    End If
    Else
    Err.Raise 778, "selectMenu::WaitWinFormObject(QAD.Client, TimeOut)", "Can not find QADNetUI"
    End If 

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      That makes sense, actually.  The reason why you may be getting "object destroyed" error is that, if the "[Del]" call and other stuff you're doing within your If then is causing a screen reload.  That would destroy the handle that SearchBar has and would need to have that object refreshed each time.

  • ajb's avatar
    ajb
    Occasional Contributor

    What I found surprising is that this structure has been in our tests since TC9 and this structure has worked fine there and in TC10 and TC11 until TC12. The Delete is deleting text in a single field so that the next menu item can be entered. I don't believe that the screen is being refreshed.

     

    Additionally, when I removed the delete (It's not really needed since I'm am now using set_Text to enter the name of the next menu item), the object still gets destroyed by the  .keys"[Enter]" on occasion. 

     

    Thanks for your post.