使用QTP的.NET插件扩展技术测试ComponentOne的ToolBar控件

2024-03-26 05:48

本文主要是介绍使用QTP的.NET插件扩展技术测试ComponentOne的ToolBar控件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

对于ComponentOneToolBar控件,我们可以采用QTP.NET插件扩展技术来处理。下面是在VS.NET2005中编写的插件扩展代码:

using System;

using Mercury.QTP.CustomServer;

using System.Windows.Forms;

using QuickTestCustomServer_C1ToolBar;

using C1.Win.C1Command;

 

namespace QuickTestCustomServer_C1ToolBar

{

    [ReplayInterface]

    public interface IC1ToolBarReplay

    {

        #region Wizard generated sample code (commented)

        //          void  CustomMouseDown(int X, int Y);

        #endregion

        void C1ToolBar_Click(string text);

    }

    /// <summary>

    /// Summary description for C1ToolBar.

    /// </summary>

    public class C1ToolBar :

        CustomServerBase,

        IC1ToolBarReplay

    {

        // You shouldn't call Base class methods/properties at the constructor

        // since its services are not initialized yet.

        public C1ToolBar()

        {

            //

            // TODO: Add constructor logic here

            //

        }

 

        #region IRecord override Methods

        #region Wizard generated sample code (commented)

        /// <summary>

                   /// To change Window messages filter implement this method.

                   /// The default implementation is to get only Control's window messages.

                   /// </summary>

        //public override WND_MsgFilter GetWndMessageFilter()

        //{

        //    return WND_MsgFilter.WND_MSGS;

        //}

       

        /*

                   /// <summary>

                   /// To catch window messages you should implement this method.

                   /// Please note: This method is called just in case the CustomServer is running

                   /// under QuickTest process.

                   /// </summary>

                   public override RecordStatus OnMessage(ref Message tMsg)

                   {

                            // TODO:  Add OnMessage implementation.

                            return RecordStatus.RECORD_HANDLED;

                   }

        */

        #endregion

        /// <summary>

        /// In case you extend Record process, you should add your Events handlers

        /// in order to listen to Control's Events.

        /// </summary>

        public override void InitEventListener()

        {

            #region Wizard generated sample code (commented)

            /*                    // Notice, You can add as many handlers as you need.

                            // Adding OnMouseDown handler.

                            Delegate  e = new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);

 

                            // Adds an event handler as the first handler of the event.

                            // The first argument is the name of the event for which to listen.

                            //         You must provide an event that the control supports.

                            //         Use the .NET Spy to obtain the list of events supported by the control.

                            // The second argument is the event handler delegate.

 

                            AddHandler("MouseDown", e);

*/

            #endregion

                       

            //Delegate e = new C1.Win.C1Command.ClickEventHandler(this.oControl_Click);

            //AddHandler("Click", e);

 

            C1.Win.C1Command.C1ToolBar oControl = (C1.Win.C1Command.C1ToolBar)SourceControl;

 

            for (int i = 0; i < oControl.CommandLinks.Count; i++)

            {

                oControl.CommandLinks[i].Command.Click += new C1.Win.C1Command.ClickEventHandler(this.oControl_CommandClick);

            }

        }

       

        /// <summary>

        /// At the end of the Record process this method is called by QuickTest to release

        /// all the handlers the user added in InitEventListener method.

        /// Please note: Handlers added via QuickTest methods are released by QuickTest infrastructure.

        /// </summary>

        public override void ReleaseEventListener()

        {

            //C1.Win.C1Command.C1ToolBar oControl = (C1.Win.C1Command.C1ToolBar)SourceControl;

            //oControl.Click -= new

            //C1.Win.C1Command.ClickEventHandler(oControl_Click);

        }

 

        #endregion

 

        #region Record events handlers

        #region Wizard generated sample code (commented)

        /*                   public void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs  e)

                   {

                            // Record line in QTP.

                            if(e.Button == System.Windows.Forms.MouseButtons.Left)

                            {                          

                                     RecordFunction( "CustomMouseDown", RecordingMode.RECORD_SEND_LINE, e.X, e.Y);

                            }

                   }

*/

        #endregion

 

        private void oControl_CommandClick(object sender, C1.Win.C1Command.ClickEventArgs e)

        {

            C1.Win.C1Command.C1ToolBar oControl = (C1.Win.C1Command.C1ToolBar)SourceControl;

            //oControl.CommandLinks[0].State.ToString()

            base.RecordFunction("C1ToolBar_Click", RecordingMode.RECORD_SEND_LINE, e.CallerLink.Text);

            //C1.Win.C1Command.C1ToolBar oControl = (C1.Win.C1Command.C1ToolBar)SourceControl;

            Add a step in the test for the test object with the ClickButton method

            and the tooltip text as an argument

            //base.RecordFunction("ClickButton", RecordingMode.RECORD_SEND_LINE, e.CallerLink.Text);

        }

 

        #endregion

 

        #region Replay interface implementation

        #region Wizard generated sample code (commented)

        /*                   public void CustomMouseDown(int X, int Y)

                   {

                            MouseClick(X, Y, MOUSE_BUTTON.LEFT_MOUSE_BUTTON);

                   }

*/

        #endregion

 

        public void C1ToolBar_Click(string text)

        {

            //MessageBox.Show("Test!");

            C1.Win.C1Command.C1ToolBar oControl = (C1.Win.C1Command.C1ToolBar)SourceControl;

            //Find the correct item in the toolbar according to its tooltip text.

            for (int i = 0; i < oControl.CommandLinks.Count; i++)

            {

                //Found the correct ButtonItem

                if (oControl.CommandLinks[i].Text == text)

                {

                    //base.ReplayReportStep("Find",EventStatus.EVENTSTATUS_GENERAL,text);

                    if (oControl.CommandLinks[i].Command.IsParent == true)

                    {

                        System.Drawing.Rectangle oRect = oControl.CommandLinks[i].Bounds;

                        int x = oRect.X + oRect.Width - 2;

                        int y = oRect.Y + oRect.Height/2;

                        //Click the middle of the button item

                        base.MouseClick(x, y, MOUSE_BUTTON.LEFT_MOUSE_BUTTON);

                    }

                    else

                    {

                    // Retrieve the rectangle of the button's boundaries and

                    // locate its center

                   

                    //System.Drawing.Rectangle oRect = oControl.CommandLinks[i].CheckRect;

                    System.Drawing.Rectangle oRect = oControl.CommandLinks[i].Bounds;

                    int x = oRect.X + oRect.Width / 2;

                    int y = oRect.Y + oRect.Height / 2;

                    //Click the middle of the button item

                    base.MouseClick(x, y, MOUSE_BUTTON.LEFT_MOUSE_BUTTON);

                    }

                    break;

                }

            }

            base.ReplayReportStep("C1ToolBar_Click", EventStatus.EVENTSTATUS_GENERAL, text);

          }

       

        #endregion

    }

}

 

 

把如下XML代码插入到QTP安装目录中的dat目录下的SwfConfig.xml文件中(注意修改DLL的文件路径):

<!-- Merge this XML content into file "<QuickTest Professional>/dat/SwfConfig.xml". -->

  <Control Type="C1.Win.C1Command.C1ToolBar" >

    <CustomRecord>

      <Component>

             <Context>AUT</Context>

        <DllName>D:/QTP_dotNET/ComponentOne/ToolBar/QuickTestCustomServer_C1ToolBar/QuickTestCustomServer_C1ToolBar/bin/QuickTestCustomServer_C1ToolBar.dll</DllName>

        <TypeName>QuickTestCustomServer_C1ToolBar.C1ToolBar</TypeName>

      </Component>

    </CustomRecord>

    <CustomReplay>

      <Component>

             <Context>AUT</Context>

        <DllName>D:/QTP_dotNET/ComponentOne/ToolBar/QuickTestCustomServer_C1ToolBar/QuickTestCustomServer_C1ToolBar/bin/QuickTestCustomServer_C1ToolBar.dll</DllName>

        <TypeName>QuickTestCustomServer_C1ToolBar.C1ToolBar</TypeName>

      </Component>

    </CustomReplay>

<!--<Settings>

       <Parameter Name="sample name">sample value</Parameter>

    </Settings> -->

  </Control>

 

 

这样,启动QTP之后,就可以直接使用QTP的录制功能来录制和产生ComponentOneToolBar控件脚本了,例如:

SwfWindow("New document").Activate

SwfWindow("New document").SwfObject("SwfObject").C1ToolBar_Click "&New"

SwfWindow("New document").SwfObject("SwfObject").C1ToolBar_Click "E&xit"

 

这篇关于使用QTP的.NET插件扩展技术测试ComponentOne的ToolBar控件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/847463

相关文章

Linux使用fdisk进行磁盘的相关操作

《Linux使用fdisk进行磁盘的相关操作》fdisk命令是Linux中用于管理磁盘分区的强大文本实用程序,这篇文章主要为大家详细介绍了如何使用fdisk进行磁盘的相关操作,需要的可以了解下... 目录简介基本语法示例用法列出所有分区查看指定磁盘的区分管理指定的磁盘进入交互式模式创建一个新的分区删除一个存

C#使用HttpClient进行Post请求出现超时问题的解决及优化

《C#使用HttpClient进行Post请求出现超时问题的解决及优化》最近我的控制台程序发现有时候总是出现请求超时等问题,通常好几分钟最多只有3-4个请求,在使用apipost发现并发10个5分钟也... 目录优化结论单例HttpClient连接池耗尽和并发并发异步最终优化后优化结论我直接上优化结论吧,

SpringBoot使用Apache Tika检测敏感信息

《SpringBoot使用ApacheTika检测敏感信息》ApacheTika是一个功能强大的内容分析工具,它能够从多种文件格式中提取文本、元数据以及其他结构化信息,下面我们来看看如何使用Ap... 目录Tika 主要特性1. 多格式支持2. 自动文件类型检测3. 文本和元数据提取4. 支持 OCR(光学

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

《JAVA系统中SpringBoot应用程序的配置文件application.yml使用详解》:本文主要介绍JAVA系统中SpringBoot应用程序的配置文件application.yml的... 目录文件路径文件内容解释1. Server 配置2. Spring 配置3. Logging 配置4. Ma

Linux使用dd命令来复制和转换数据的操作方法

《Linux使用dd命令来复制和转换数据的操作方法》Linux中的dd命令是一个功能强大的数据复制和转换实用程序,它以较低级别运行,通常用于创建可启动的USB驱动器、克隆磁盘和生成随机数据等任务,本文... 目录简介功能和能力语法常用选项示例用法基础用法创建可启动www.chinasem.cn的 USB 驱动

C#使用yield关键字实现提升迭代性能与效率

《C#使用yield关键字实现提升迭代性能与效率》yield关键字在C#中简化了数据迭代的方式,实现了按需生成数据,自动维护迭代状态,本文主要来聊聊如何使用yield关键字实现提升迭代性能与效率,感兴... 目录前言传统迭代和yield迭代方式对比yield延迟加载按需获取数据yield break显式示迭

使用SQL语言查询多个Excel表格的操作方法

《使用SQL语言查询多个Excel表格的操作方法》本文介绍了如何使用SQL语言查询多个Excel表格,通过将所有Excel表格放入一个.xlsx文件中,并使用pandas和pandasql库进行读取和... 目录如何用SQL语言查询多个Excel表格如何使用sql查询excel内容1. 简介2. 实现思路3

java脚本使用不同版本jdk的说明介绍

《java脚本使用不同版本jdk的说明介绍》本文介绍了在Java中执行JavaScript脚本的几种方式,包括使用ScriptEngine、Nashorn和GraalVM,ScriptEngine适用... 目录Java脚本使用不同版本jdk的说明1.使用ScriptEngine执行javascript2.

c# checked和unchecked关键字的使用

《c#checked和unchecked关键字的使用》C#中的checked关键字用于启用整数运算的溢出检查,可以捕获并抛出System.OverflowException异常,而unchecked... 目录在 C# 中,checked 关键字用于启用整数运算的溢出检查。默认情况下,C# 的整数运算不会自

在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码

《在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码》在MyBatis的XML映射文件中,trim元素用于动态添加SQL语句的一部分,处理前缀、后缀及多余的逗号或连接符,示... 在MyBATis的XML映射文件中,<trim>元素用于动态地添加SQL语句的一部分,例如SET或W