Forum Discussion

BillA603's avatar
BillA603
Contributor
6 years ago

InputBox: How to tell if Cancel selected

I am invoking the BuildIn InputBox to get user input from my TestComplete 12.5 Vbscript.

 

The InputBox dialog has 2 buttons: OK and Cancel and I would like a way for the user to abort the script execution. I thought the Cancel button might work, but the dialog behavior seems to be the same no matter which button is clicked. the typed value or default value gets returned. I cannot find documentation indicating how to determine which button was clicked.

 

Does anyone know how to tell if the user clicks Cancel?

 

Thanks

 

 

 

4 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Usually the point of an automated test is to remove the actual user interaction.  What is it you're trying to accomplish by adding this dialog into the test?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      From the help (https://support.smartbear.com/testcomplete/docs/reference/program-objects/builtin/inputbox.html)

       

      "

      Result Value

      If the user presses OK, InputBox will return the entered string. Otherwise, it returns Default."

       

      So, clicking cancel returns whatever you have indicated in the "Default" value... it doesn't cancel a script or test or anything... just returns a value.

       

      If you're not using JavaScript, JScript, Python, or C++, then yes, InputQuery will work... but any of those languages won't work with InputQuery because of the "out" parameters.

       

      So, if you want to use "InputBox", then set your default value to be whatever would be the "stop the test" value you desire.  That way, if the user clicks "Cancel", then that default value will be returned as the result and the test will halt as you code it.... but note that if the user does not change the default value and clicks "OK", then it will still halt the test.

       

      If you truly want to be able to create a dialog that will allow the user to control the test run, then I suggest you look into UserForms (https://support.smartbear.com/testcomplete/docs/testing-with/advanced/user-forms/about.html).

       

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        > I am invoking the BuildIn InputBox to get user input from my TestComplete 12.5 Vbscript.

        Thus InputQuery() was suggested as a quick effortless replacement.
        Though the reply by tristaanogre is definitely more detailed and descriptive.