以XML文件方式扩展QTP的.NET插件的问题

来源:互联网 发布:java lisp 编辑:程序博客网 时间:2024/05/16 18:21

今天试了一下QTP的.NET插件,QTP的.NET插件对于解决.NET控件识别和测试问题非常重要,是测试.NET平台程序必不可少的条件(包括测试.NET Windows Forms、.NET Web Forms、WPF控件)。.NET第三方控件或自定义的个性化控件的识别和测试问题可通过QTP的.NET插件提供的扩展模块来解决。

QTP的.NET插件主要提供了两种方式的扩展来支持个性化控件的测试:

(1).NET DLL:使用其为VS.NET提供的Custom Server模板来创建用C#写的DLL来支持个性化控件的测试。

(2)XML:使用XML文件来描述扩展。

第一种方法的好处是可以充分利用开发工具的优势,第二种方法则相对更便捷,可随时进行扩展,但是今天试用的结果是可实现录制方面的扩展,在回放方面的扩展不能实现,不知道是不是还有什么诀窍没掌握,QTP提供的帮助文档在这方面也比较有限。
在SwfConfig.xml文件中的扩展描述如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Controls>
  <Control Type="MyWindowsControlLibrary1.UserControl1">
          <Settings>
                 <Parameter Name="ConfigPath">D:/Program Files/Mercury Interactive/QuickTest Professional/dat/ControlDefineXMLSample.XML
                 </Parameter>
          </Settings>
         <CustomRecord>
                 <Component>
                        <Context>AUT-XML</Context>
                 </Component>
          </CustomRecord>
          <CustomReplay>
                <Component>

                       <Context>AUT-XML</Context>
                 </Component>
          </CustomReplay>
  </Control>
</Controls>

ControlDefineXMLSample.XML的定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<Customization>
       <Record>
              <Events>
                     <Event name="MouseDown" enabled="true">
                            <RecordedCommand name="MouseMove">
                                   <Parameter>                                
                                   EventArgs.X
                                  </Parameter>
                                   <Parameter lang="C#">
                                   Parameter = EventArgs.Y;
                                  </Parameter>
                            </RecordedCommand>
                     </Event>
              </Events>
       </Record>
       <Replay>
              <Methods>
                     <Method name="SetValue">                    
                      <Parameters>
                                   <Parameter type="int" name="X"/>
                                   <Parameter type="int" name="Y"/>
                            </Parameters>
                            <MethodBody>

                                   System.Windows.Forms.MessageBox.Show("Mouse Position at Record Time");

                            </MethodBody>
                     </Method>
              </Methods>
       </Replay>
</Customization>

基本上是按QTP的帮助文档描述,以及它提供的一个小例子来写的。如果完全按其在NETExtensibility.chm文件中的“Example of a Control Definition XML File”这一节的例子来写则完全不能进行录制方面的扩展,它的例子如下:

详细:http://www.51qa.net/Item/804.aspx