Recording User Actions Over Silverlight Applications - Specifics

Applies to TestComplete 15.10, last modified on December 15, 2021

The information in this topic applies to web tests that locate web objects by using internal identification properties provided by TestComplete and run in local environments.

When recording tests for a Silverlight application, keep in mind the following specifics:

  • The Silverlight application under test can invoke common dialog boxes like Open File, Save File, etc. When recording a test, the “Dialogs must be user-initiated” security error may occur in the application upon recording a user action that invokes such a dialog box. This happens due to some security restrictions in the Silverlight runtime. Actually, even if such a dialog box is initiated by the user (for instance, when the user clicks a button in the application to show the dialog box), there is a timeout between the time when the user initiates showing the dialog (by clicking a button, for instance) and the time when the dialog is completely displayed. If, for some reason, this timeout elapses, the Silverlight runtime "thinks" that the dialog has been invoked by a non-user-initiated action and throws the System.Security.SecurityException exception. For more information on this security restriction, see the MSDN Library.

    The issue is that TestComplete performs lots of operations (exposes object internals in the tested application, captures screenshots for user actions with Test Visualizer, etc.) when recording user actions over the tested application. This may take much time, especially when the tested application contains dozens of UI controls and internal objects. It may happen that the time spent by TestComplete to record a user action that invokes a common dialog box in the tested Silverlight application exceeds the above-mentioned timeout set by the Silverlight runtime, and the latter throws a security exception.

    Note: Such an issue may occur both with in-browser and out-of-browser Silverlight applications.

    If you face this issue when recording a test for your Silverlight application, try using one of the following workarounds:

    • Before recording a test, disable Test Visualizer. Although Test Visualizer is a really powerful feature of TestComplete, it is actually quite time-consuming. Therefore, if it is disabled during test recording, the time that TestComplete spends to record a user action over the tested application may decrease appreciably, especially if you are testing an application that contains a lot of complex UI elements. In this case, most probably, the time will not exceed the timeout set by Silverlight for invoking common dialog boxes and the exception will not occur. Note that you can leave Test Visualizer enabled when playing back the recorded tests.

      To disable Test Visualizer during recording, select Off in the Collect Test Visualizer data during recording group of settings in Visualizer Options.

    • Record a test for your Silverlight application by using the following technique:

      • Start recording a test and perform the needed actions over the tested application.

      • Right before opening the dialog box for which your Silverlight application throws a security exception (for instance, before clicking a button that invokes the dialog), pause the test recording (see Recording Tests - Overview).

      • When the test recording is paused, invoke the needed dialog box in the tested application. The security error should not occur in this case.

      • After the dialog box is shown, resume the test recording and perform the remaining actions over the tested application.

      • After finishing recording, record one more test (it will be a temporary helper test) in which you perform only one user action that initiates showing the dialog box. In this case, a security exception may occur in the application, but you do not have to worry about this.

      • When the recording of the second (helper) test is finished, locate the code snippet or the keyword test operation (depending on whether you have recorded scripts or keyword tests) that initiates invoking of the dialog box from the test and copy it. For instance, if the dialog box is invoked from your application by clicking on a certain button, you should copy the code (or the keyword operation) that simulates mouse clicking on the button in the application.

      • In the first test (the main test), locate the point at which the dialog box must be invoked and then paste the copied code snippet (or the keyword operation) to this point.

      • Save the changes. Now the test is ready for execution. You may delete the second (helper) test.

See Also

Testing Silverlight Applications
Recording Specifics
About Test Visualizer

Highlight search results