使用QTP的.NET外掛擴充套件技術測試ComponentOne的ToolBar控制元件
對於ComponentOne的ToolBar控制元件,我們可以採用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的錄製功能來錄製和產生ComponentOne的ToolBar控制元件指令碼了,例如:
SwfWindow("New document").Activate
SwfWindow("New document").SwfObject("SwfObject").C1ToolBar_Click "&New"
SwfWindow("New document").SwfObject("SwfObject").C1ToolBar_Click "E&xit"
相關文章
- 6個最佳的Netbeans擴充套件外掛Bean套件
- jQuery擴充套件外掛jQuery套件
- jQuery外掛擴充套件jQuery套件
- [外掛擴充套件]更新IP外掛套件
- [外掛擴充套件]廣告外掛2.0套件
- [外掛擴充套件]附件Attachment外掛套件
- [外掛擴充套件]Ping外掛套件
- [外掛擴充套件]投票外掛1.0套件
- [外掛擴充套件]騰訊分析外掛套件
- [外掛擴充套件]外掛需求徵集套件
- [外掛擴充套件]解決onethink多圖上傳的外掛分享!套件
- [外掛擴充套件]焦點圖外掛套件
- [外掛擴充套件]友情連結——外掛套件
- [外掛擴充套件]qq登入外掛套件
- [外掛擴充套件]修改密碼外掛套件密碼
- [外掛擴充套件]留言版外掛套件
- [外掛擴充套件]單頁管理外掛套件
- [外掛擴充套件]邀請碼外掛套件
- [外掛擴充套件]Blog匯入OneThink套件
- [外掛擴充套件]簡單的IP記錄外掛套件
- [外掛擴充套件]OneThink後臺增刪改查外掛套件
- [外掛擴充套件]jQueryFileUpload套件jQuery
- 外掛擴充套件需求_好友套件
- iOS 通知擴充套件外掛iOS套件
- [外掛擴充套件]百度分享外掛套件
- [外掛擴充套件]微信外掛Wechat1.0套件
- [外掛擴充套件]三級聯動外掛!!!!!!!!套件
- [外掛擴充套件]APP極光推送外掛!套件APP
- [外掛擴充套件]防護雲Iswaf外掛套件
- [外掛擴充套件]返回頂部ReturnTop外掛套件
- [外掛擴充套件]廣告圖片漂浮外掛套件
- [外掛擴充套件]圖片輪播外掛套件
- [外掛擴充套件]計劃任務外掛套件
- [外掛擴充套件]js版本分頁外掛套件JS
- [外掛擴充套件]跪求時間軸外掛套件
- [外掛擴充套件]自己寫的外掛。怎麼後臺?套件
- [外掛擴充套件]圖片牆套件
- 建立VS Code 擴充套件外掛套件