Forum Discussion

Nformation's avatar
Nformation
Contributor
10 years ago

Try-Catch for Click Methods

I've written a jscript function for closing my application at the end of every test. It first tries to close the application by clicking buttons and, if that fails, calls the Close method. 

 

If the script fails to close the application through the UI, I don't want to log an error--just a warning. However, the script throws an error anyway. I tried surrounding in a Try/Catch, but I've learned that doesn't work with the TestComplete operations I'm performing. How should I go about this?  

 

Here's my script: 

try
  {
    Aliases.Informa_Cashiering_Client.CurrentTransaction.ApplicationWindow.Grid.FloatingContainerBorder.Grid.FloatingContainerHeader.Grid.stackPanel.Button_CloseApplication.ClickButton();
  } 
  catch (e)
  {
    Log.Warning("Unable to close through the UI"); 
  }
  
  if(myProcess.Exists){
    myProcess.Close(1000);  
  }
  • NisHera's avatar
    NisHera
    Valued Contributor

    when you running..

    .Button_CloseApplication.ClickButton();

    TC will look for Button_CloseApplication object.

    If not found it will through an error

     

    so call it withing an if condition

    eg IF ....Button_CloseApplication.WaitProperty('Exists',true, 1500)

           ...........Button_CloseApplication..clickbutton();

     

    if WaitProperty() methoed fails would retun Exsist false without firing an error......

    for more refer this