Steps to use the QTP .NET Extensibility sdk

QuickTest .NET Add-in Extensibility is an SDK package that enables you to support testing applications
that use third-party and custom .NET Windows Forms controls that are not supported out-of-the-box by the .NET Add-in.

We need to create a Custom Server (DLLs or control definition XML file) to handle each custom control.

We shall look at the steps to develop a custom server dll using the .net extensibility kit:
  1. Use the QTP Setup program to install the QuickTest Professional .NET Add-in Extensibility SDK on your computer.
  2. Create a new project in VS2008 or above and select the Visual C# > Windows node in the Project types treeVisual C# >














 3.  In the Application Settings page, specify the following settings:
  • Server class name e.g. TrackBarSrv
  • Select the Customize Record process check box.
  • Select the Customize Run process check box.
  • Accept the rest of the default settings.
4.  Click Next. The XML Configuration Settings page opens
In the XML Configuration Settings page, specify the following settings:
  •  Make sure the Auto-generate the XML configuration segment check box
  • In the Customized Control type box, enter the entire reference of the object which you can find in the references in VS for e.g. System.Windows.Forms.TrackBar
  • Accept the rest of the default settings
5.  Click Finish and in VS you will see  In the Class View window, you can see that the wizard created a class like e.g. TrackBarSrv class derived from the CustomServerBase class and an interface like ITrackBarSrvReplay interface.

6. Implement the Test Record Logic

7. Implement the Test Run Logic

8. Configure QuickTest Professional to use the Custom Server - In the Solution Explorer window, double-click the Configuration.XML fileConfiguration.XML file. Copy everything that is between and paste it in the  tag SwfConfig.xml

P.S - SwfConfig.xml file located in \dat..
Make sure that the elements contain the correct path to your Custom Server DLL

Here is the code for Trackbar.csv

using System;using Mercury.QTP.CustomServer;using System.Windows.Forms;namespace
{
[
QTCustServerReplayInterface]public interface ITrackBarSrvReplay{#region
Wizard generated sample code (commented)// void CustomMouseDown(int X, int Y);#endregion
}
void SetValue(int newValue);/// /// Summary description for TrackBarSrv.///

public class TrackBarSrv :CustomServerBase,ITrackBarSrvReplay{
// You shouldn't call Base class methods/properties at the constructor// since its services are not initialized yet.
{
public TrackBarSrv()//// TODO: Add constructor logic here//}#region IRecord override Methods#region

/// To change Window messages filter implement this method.
/// The default implementation is to get only Control's window messages.
///
public override WND_MsgFilter GetWndMessageFilter()
{
return WND_MsgFilter.WND_MSGS;
}
///
/// 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.
///

public override RecordStatus OnMessage(ref Message tMsg)
{
// TODO: Add OnMessage implementation.
return RecordStatus.RECORD_HANDLED;
}
*/
Wizard generated sample code (commented)/* /// #endregion/// /// In case you extend Record process, you should add your Events handlers/// in order to listen to Control's Events.///
{
public override void InitEventListener()#region

// 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);
*/
Wizard generated sample code (commented)/* // Notice, You can add as many handlers as you need.#endregion
AddHandler(
}
Delegate e = new System.EventHandler(this.OnValueChanged);"ValueChanged", e);/// /// 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.///
{
}

{
System.Windows.Forms.
public override void ReleaseEventListener()public void OnValueChanged(object sender, EventArgs e)TrackBar trackBar = (System.Windows.Forms.TrackBar)sender;// get the new value
int newValue = trackBar.Value;// Record SetValue command to the testRecordFunction(
}
"SetValue", RecordingMode.RECORD_SEND_LINE, newValue);#endregion

#region
Record events handlers#region

{
// Record line in QTP.
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
RecordFunction( "CustomMouseDown", RecordingMode.RECORD_SEND_LINE, e.X, e.Y);
}
}
*/
Wizard generated sample code (commented)/* public void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)#endregion
#endregion

#region
Replay interface implementation#region

{
MouseClick(X, Y, MOUSE_BUTTON.LEFT_MOUSE_BUTTON);
}
*/
Wizard generated sample code (commented)/* public void CustomMouseDown(int X, int Y)#endregion
{
System.Windows.Forms.
trackBar.Value = newValue;
}
public void SetValue(int newValue)TrackBar trackBar =(System.Windows.Forms.TrackBar)SourceControl;#endregion}
}
Hope this helps anyone using the extensibility! Will try and post a video if i can of the entire process!

Popular posts from this blog

XPATH for IE / internet explorer

All time good software testing books!