18.3.5 测试DevComponents的hScrollBarAdv控件(1)

18.3.5  测试DevComponents的hScrollBarAdv控件(1)

前面我们已经看过测试DevComponents的vScrollBarAdv和hScrollBarAdv控件的一种方法,是利用键盘操作来处理的。在这里,我们尝试用QTP.NET插件扩展技术来处理。

用C#编写插件扩展代码如下所示(在Visual Studio中创建.NET插件扩展代码的方法与前面介绍的一致):

  1. using System;  
  2. using Mercury.QTP.CustomServer;  
  3. using System.Windows.Forms;  
  4. using DevComponents.DotNetBar.ScrollBar;  
  5.  
  6. namespace QuickTestCustomServer_vScrollBarAdv_hScrollBarAdv  
  7. {  
  8.     [ReplayInterface]  
  9.     public interface IScrollBarReplay  
  10.     {  
  11.         #region Wizard generated sample code (commented)  
  12.         void  SetValue(string NewValue);  
  13.         #endregion  
  14.     }  
  15.     /// <summary
  16.     /// Summary description for ScrollBar.  
  17.     /// </summary
  18.     public class ScrollBar :  
  19.         CustomServerBase,  
  20.         IScrollBarReplay  
  21.     {  
  22.         // You shouldn't call Base class methods/properties at the constructor  
  23.         // since its services are not initialized yet.  
  24.         public ScrollBar()  
  25.         {  
  26.             //  
  27.             // TODO: Add constructor logic here  
  28.             //  
  29.         }  
  30.  
  31.         #region IRecord override Methods  
  32.         #region Wizard generated sample code (commented)  
  33.         /*      /// <summary
  34.         /// To change Window messages filter implement this method.  
  35.         /// The default implementation is to get only Control's window messages.  
  36.         /// </summary
  37.         public override WND_MsgFilter GetWndMessageFilter()  
  38.         {  
  39.             return WND_MsgFilter.WND_MSGS;  
  40.         }  
  41.  
  42.         /// <summary
  43.         /// To catch window messages you should implement this method.  
  44.         /// Please note: This method is called just in case the CustomServer is running  
  45.         /// under QuickTest process.  
  46.         /// </summary
  47.         public override RecordStatus OnMessage(ref Message tMsg)  
  48.         {  
  49.             // TODO:  Add OnMessage implementation.  
  50.             return RecordStatus.RECORD_HANDLED;  
  51.         }  
  52. */  
  53.         #endregion  
  54.         /// <summary
  55.         /// In case you extend Record process, you should add your Events handlers  
  56.         /// in order to listen to Control's Events.  
  57.         /// </summary
  58.         public override void InitEventListener()  
  59.         {  
  60.             #region Wizard generated sample code (commented)  
  61.             // Notice, You can add as many handlers as you need.  
  62.             // Adding OnMouseDown handler.  
  63.             Delegate  e = new System.Windows.Forms.MouseEventHandler (this.OnMouseDown);  
  64.  
  65.             // Adds an event handler as the first handler of the event.  
  66.             // The first argument is the name of the event for which to listen.  
  67.             //         You must provide an event that the control supports.  
  68.             //         Use the .NET Spy to obtain the list of events supported by the control.  
  69.             // The second argument is the event handler delegate.   
  70.  
  71.             AddHandler("MouseDown", e);  
  72.  
  73.             #endregion  
  74.         }  
  75.  
  76.         /// <summary
  77.         /// At the end of the Record process this method is called by QuickTest to release   
  78.         /// all the handlers the user added in InitEventListener method.  
  79.         /// Please note: Handlers added via QuickTest methods are released by QuickTest infrastructure.  
  80.         /// </summary
  81.         public override void ReleaseEventListener()  
  82.         {  
  83.         }  
  84.  
  85.         #endregion  
  86.  
  87.  
  88.         #region Record events handlers  
  89.         #region Wizard generated sample code (commented)  
  90.         public void OnMouseDown(object sender, System.Windows.Forms. MouseEventArgs  e)  
  91.         {  
  92.             string NewValue = ((DevComponents.DotNetBar.ScrollBar. HScrollBarAdv)sender).Value.ToString();  
  93.             // Record line in QTP.  
  94.             if(e.Button == System.Windows.Forms.MouseButtons.Left)  
  95.             {  
  96.                 RecordFunction("SetValue", RecordingMode.RECORD_SEND_LINE, NewValue);  
  97.             }  
  98.         }  
  99.           
  100.         #endregion  
  101.         #endregion  
  102.  
  103.  
  104.         #region Replay interface implementation  
  105.         #region Wizard generated sample code (commented)  
  106.         public void SetValue(string NewValue)  
  107.         {  
  108.  
  109.             DevComponents.DotNetBar.ScrollBar.HScrollBarAdv oScrollBar = (DevComponents.DotNetBar.ScrollBar.HScrollBarAdv)SourceControl;  
  110.             oScrollBar.Value = Int32.Parse(NewValue);  
  111.  
  112.         }  
  113.  
  114.         #endregion  
  115.         #endregion  
  116.     }  
  117. }  
原文地址:https://www.cnblogs.com/gdg87813/p/10956360.html