18.3.5 测试DevComponents的hScrollBarAdv控件(1)
前面我们已经看过测试DevComponents的vScrollBarAdv和hScrollBarAdv控件的一种方法,是利用键盘操作来处理的。在这里,我们尝试用QTP.NET插件扩展技术来处理。
用C#编写插件扩展代码如下所示(在Visual Studio中创建.NET插件扩展代码的方法与前面介绍的一致):
- using System;
- using Mercury.QTP.CustomServer;
- using System.Windows.Forms;
- using DevComponents.DotNetBar.ScrollBar;
- namespace QuickTestCustomServer_vScrollBarAdv_hScrollBarAdv
- {
- [ReplayInterface]
- public interface IScrollBarReplay
- {
- #region Wizard generated sample code (commented)
- void SetValue(string NewValue);
- #endregion
- }
- /// <summary>
- /// Summary description for ScrollBar.
- /// </summary>
- public class ScrollBar :
- CustomServerBase,
- IScrollBarReplay
- {
- // You shouldn't call Base class methods/properties at the constructor
- // since its services are not initialized yet.
- public ScrollBar()
- {
- //
- // 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
- }
- /// <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()
- {
- }
- #endregion
- #region Record events handlers
- #region Wizard generated sample code (commented)
- public void OnMouseDown(object sender, System.Windows.Forms. MouseEventArgs e)
- {
- string NewValue = ((DevComponents.DotNetBar.ScrollBar. HScrollBarAdv)sender).Value.ToString();
- // Record line in QTP.
- if(e.Button == System.Windows.Forms.MouseButtons.Left)
- {
- RecordFunction("SetValue", RecordingMode.RECORD_SEND_LINE, NewValue);
- }
- }
- #endregion
- #endregion
- #region Replay interface implementation
- #region Wizard generated sample code (commented)
- public void SetValue(string NewValue)
- {
- DevComponents.DotNetBar.ScrollBar.HScrollBarAdv oScrollBar = (DevComponents.DotNetBar.ScrollBar.HScrollBarAdv)SourceControl;
- oScrollBar.Value = Int32.Parse(NewValue);
- }
- #endregion
- #endregion
- }
- }