使用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

相关文章

性能测试介绍

性能测试是一种测试方法,旨在评估系统、应用程序或组件在现实场景中的性能表现和可靠性。它通常用于衡量系统在不同负载条件下的响应时间、吞吐量、资源利用率、稳定性和可扩展性等关键指标。 为什么要进行性能测试 通过性能测试,可以确定系统是否能够满足预期的性能要求,找出性能瓶颈和潜在的问题,并进行优化和调整。 发现性能瓶颈:性能测试可以帮助发现系统的性能瓶颈,即系统在高负载或高并发情况下可能出现的问题

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

字节面试 | 如何测试RocketMQ、RocketMQ?

字节面试:RocketMQ是怎么测试的呢? 答: 首先保证消息的消费正确、设计逆向用例,在验证消息内容为空等情况时的消费正确性; 推送大批量MQ,通过Admin控制台查看MQ消费的情况,是否出现消费假死、TPS是否正常等等问题。(上述都是临场发挥,但是RocketMQ真正的测试点,还真的需要探讨) 01 先了解RocketMQ 作为测试也是要简单了解RocketMQ。简单来说,就是一个分

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma