Forum Discussion

BrandonH's avatar
BrandonH
Contributor
8 years ago

Checking the success of a clickButton action

Hi,

 

     I'd like to test whether a series of button clicks was successful (i.e. were all the objects found and successfully clicked).  I first attempted this by putting them in a try/catch statement, however, the errors do not get sent to the catch.

 

     Is there a way to determine the status of a ClickButton action (and other actions) via script?

 

Thanks,

  • try/catch only catches code exceptions.  Object not found errors are not trapped by code try/catch logic.

     

    To that end, I would use, for each button, a "WaitAliasChild" call to detect if the button exists.  Then, if it exists, call the ClickButton action on it.  After the ClickButton is executed, do another check of some sort to detect if the results of the button click worked.  Something like this:

    function testMyButton(){
        var myButton;
        myButton = Aliases.myApp.MyForm.WaitAliasChild('MyButton', 10000);
        if (myButton.Exists) {
            myButton.ClickButton();
            if (newTextField.Text != 'It Works') {
                 Log.Error('MyButton click button failed');
            }
        }
        else {
            Log.Error('MyButton does not exist');
        }
    }
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    try/catch only catches code exceptions.  Object not found errors are not trapped by code try/catch logic.

     

    To that end, I would use, for each button, a "WaitAliasChild" call to detect if the button exists.  Then, if it exists, call the ClickButton action on it.  After the ClickButton is executed, do another check of some sort to detect if the results of the button click worked.  Something like this:

    function testMyButton(){
        var myButton;
        myButton = Aliases.myApp.MyForm.WaitAliasChild('MyButton', 10000);
        if (myButton.Exists) {
            myButton.ClickButton();
            if (newTextField.Text != 'It Works') {
                 Log.Error('MyButton click button failed');
            }
        }
        else {
            Log.Error('MyButton does not exist');
        }
    }
    • BrandonH's avatar
      BrandonH
      Contributor

      Thanks tristaanogre.  That's essentially how I do it now, although for some tests there is no identifiable way, on our UI, to determine that a ClickButton was successful. Is there a way to reference the log to check status?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Not really.  Is there some other effect like a data record in an SQL database, a field or option on a different screen, etc?  Generally, if there is no error on "ClickButton" than, generally, it can be assumed to be successful...

         

        ...kinda begs the question that if you have a button to click and no discernable difference in the application, why have the button? ;)  That's a humorous way of saying that there is some effect of the button somewhere in your application... If you were manually testing it, how would you verify it's success?  Whatever you would do manually, see if there is a way to do the same validation via your automation.