技术开发 频道

Visual Studio2010测试:对象识别原理

  UIMap.UItest文件控制识别代码的生成

  在第二章上部分已经提到,在UIMap.uitest文件中,对象的识别代码的生成部分是放在节点下的,点击生成代码后,会将其真正起作用的识别代码生成到UIMap.designer.cs下,那么他们的代码究竟是怎样的呢?

  以刚才那个窗体生成的代码为例,我们要识别TextBox1,如果使用录制生成器,把TextBox1填入到对象库,我们来看看他生成的识别代码(可以简略看,下面会有说明)。

<Maps>
  
<UIMap Id="UIMap1">
    
<TopLevelWindows>
      
<TopLevelWindow ControlType="Window" Id="UI 系统登录Window" FriendlyName="系统登录" SpecialControlType="None" SessionId="199642">
        
<TechnologyName>MSAA</TechnologyName>
        
<WindowTitles>
          
<WindowTitle> 系统登录</WindowTitle>
        
</WindowTitles>
        
<SearchConfigurations>
          
<SearchConfiguration>VisibleOnly</SearchConfiguration>
        
</SearchConfigurations>
        
<AndCondition Id="SearchCondition">
          
<PropertyCondition Name="Name"& gt;系统登录</PropertyCondition>
          
<PropertyCondition Name="ClassName" Operator="Contains">WindowsForms10.Window</PropertyCondition>
          
<PropertyCondition Name="ControlType">Window</PropertyCondition>
        
</AndCondition>
        
<SupportLevel>0</SupportLevel>
        
<Descendants>
          
<UIObject ControlType="Window" Id="UITbx_uidWindow" FriendlyName="Tbx_uid" SpecialControlType="None">
            
<TechnologyName>MSAA</TechnologyName>
            
<WindowTitles>
              
<WindowTitle> 系统登录</WindowTitle>
            
</WindowTitles>
            
<SearchConfigurations>
              
<SearchConfiguration>VisibleOnly</SearchConfiguration>
            
</SearchConfigurations>
            
<AndCondition Id="SearchCondition">
              
<PropertyCondition Name="ControlName">Tbx_uid</PropertyCondition>
              
<PropertyCondition Name="ControlType">Window</PropertyCondition>
            
</AndCondition>
            
<SupportLevel>0</SupportLevel>
            
<Descendants>
              
<UIObject ControlType="Edit" Id="UITbx_uidEdit" FriendlyName="Tbx_uid" SpecialControlType="None">
                
<TechnologyName>MSAA</TechnologyName>
                
<WindowTitles>
                  
<WindowTitle> 系统登录</WindowTitle>
                
</WindowTitles>
                
<SearchConfigurations>
                  
<SearchConfiguration>VisibleOnly</SearchConfiguration>
                
</SearchConfigurations>
                
<AndCondition Id="SearchCondition">
                  
<PropertyCondition Name="Name"& gt;密码 :</PropertyCondition>
                  
<PropertyCondition Name="ControlType">Edit</PropertyCondition>
                
</AndCondition>
                
<SupportLevel>0</SupportLevel>
                
<Descendants />
              
</UIObject>
            
</Descendants>
          
</UIObject>
        
</Descendants>
      
</TopLevelWindow>
    
</TopLevelWindows>
  
</UIMap>
</Maps>

  别看UIMap.uitest里为这些对象生成的了一大堆代码,其实对象中真正管作用的属性就ControlType,ID两个:

  ID这个属性表示调用对象在对象库中的ID,例如在第二章下部分,编写ExecuteActions的时候,描述对那个对象进行操作。

0
相关文章