博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用QTP的.NET插件扩展技术测试ComponentOne的ToolBar控件
阅读量:4199 次
发布时间:2019-05-26

本文共 6530 字,大约阅读时间需要 21 分钟。

对于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"

 

转载地址:http://sunli.baihongyu.com/

你可能感兴趣的文章
10个出色的NoSQL数据库
查看>>
MySQL: InnoDB 还是 MyISAM?
查看>>
MySQL性能优化的最佳20+条经验
查看>>
SQL语言的组成部分 ddl dcl dml
查看>>
mysql数据库从库同步延迟的问题
查看>>
1.mysql数据库主从复制部署笔记
查看>>
mysql数据库主从同步的问题解决方法
查看>>
mysql 配置 - on xFanxcy.com
查看>>
MySQL数据库高并发优化配置
查看>>
mysql一: 索引优化
查看>>
测试人员,今天再不懂BDD就晚了!
查看>>
是QA还是AQ?
查看>>
害怕自动化(1)
查看>>
Script and Test Data
查看>>
在ITPub上发表文章《如何进行测试自动化的成本估算》
查看>>
深圳市软件质量提升工程系列活动——安全测试百人大课堂
查看>>
做培训讲师就像做一名导演
查看>>
深圳51testing笔架山一日游
查看>>
LoadRunner如何在脚本运行时修改log设置选项?
查看>>
QC数据库表结构
查看>>