Export (0) Print
Expand All

How to: Record Mouse Hovers in Coded UI Tests

Visual Studio 2010

Under some circumstances, a control being used in a coded UI test might require you to use the keyboard to manually record mouse hover events. For example, when you test a Windows Form or a Windows Presentation Foundation (WPF) application, there might be custom code. Or, there might be special behavior defined for hovering over a control, such as a tree node expanding when a user hovers over it. To test circumstances like these, you have to manually notify the Coded UI Test Builder that you are hovering over the control by pressing predefined keyboard keys. For information about how to notify the Coded UI Test Builder, see the procedure Recording Mouse Hovers in Coded UI Tests below.

In many web sites, when you hover over a particular control, it expands to show additional details. Generally, these look like menus in desktop applications. Because this is a common pattern, coded UI tests enable implicit hovers for Web browsing. For example, if you record hovers in Internet Explorer, an event is fired. These events can lead to redundant hovers getting recorded. Because of this, implicit hovers are recorded with ContinueOnError set to true in the UI test configuration file. This allows playback to continue if a hover event fails. For more information about configuration settings, see the procedure Setting Implicit Hovers for Internet Explorer below.

To record mouse hovers in coded UI tests

  1. Generate your coded UI test. For more information, see How to: Generate a Coded UI Test by Recording the Application Under Test.

  2. When you perform your coded UI test, while hovering over the control, press and hold Ctrl, while you press and hold the Shift and R keys on your keyboard. Release the keys. A mouse hover event is recorded by the Coded UT Test Builder.

    Recording mouse hover event using keyboard

    NoteNote

    You can change the default keyboard assignment of Ctrl+Shift+R if necessary, as explained in the next procedure.

  3. After you generate the test method, code similar to the following will be added to the UIMap.Desinger.cs file:

    // Mouse hover '1' label at (87, 9)
    Mouse.Hover(uIItem1Text, new Point(87, 9));
    
    

To configure mouse hover keyboard assingnments

  • If necessary, the default keyboard assignment of Ctrl+Shift+R that is used to apply mouse hovering events in your coded UI tests can be configured to use different keys.

    Caution noteCaution

    You should not have to change the keyboard assignments for mouse hover events under ordinary circumstances. Use caution when reassigning the keyboard assignment. Verify that you are not using an assignment already in use elsewhere within Visual Studio or the application being tested.

    To change the keyboard assignments, you must modify the following configuration file:

    <drive letter:>\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\CodedUITestBuilder.exe.config

    In the configuration file, change the values for the HoverKeyModifier and HoverKey keys to modify the keyboard assignments:

    <!-- Begin : Background Recorder Settings -->
    <!-- HoverKey to use. -->
    <add key="HoverKeyModifier" value="Control, Shift"/>
    <add key="HoverKey" value="R"/>
    
    
    NoteNote

    You can also edit the following Microsoft Test Manager configuration file to specify that the keyboard assignments include an explicit hover while doing a manual test: <drive letter:>\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mtm.exe.config. The configuration file for Microsoft Test Manager uses the same keys and values as shown in the code sample. Just like coded UI tests, manual tests use the default keyboard assignment of Cntrl+Shift+R. For more information about manual tests, see Running Manual Tests Using Test Runner.

To set implicit hovers for the Web browser

  1. To enable the recording of implicit hovers in a Web browser, open the configuration file:

    <drive letter:>\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\CodedUITestBuilder.exe.config

  2. Verify that the configuration file has the key RecordImplicitiHovers set to a to a value of true as shown in the following sample:

    <!--Use this to enable/disable recording of implicit hovers.-->
    <add key="RecordImplicitHover" value="true"/>
    
    
    NoteNote

    You can also edit the following Microsoft Test Manager configuration file to specify the implicit hovers while doing a manual test: <drive letter:>\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mtm.exe.config. The configuration file for Microsoft Test Manager uses the same key and value as shown in the code sample. For more information about manual tests, see Running Manual Tests Using Test Runner.

Community Additions

ADD
Show:
© 2014 Microsoft