Top Banner
SilkTest: The Extension Kit
28

SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Mar 26, 2015

Download

Documents

Stephanie Hunt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

SilkTest:The Extension Kit

Page 2: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 2Confidential

What is the Extension Kit?

• The Extension Kit provides an end-user with the means to implement additional automation functionality for those applications or controls that SilkTest has difficulty working with.

• The Extension Kit is aimed at programmers who are familiar with C or C++.

• What types of application can the SilkTest Extension Kit be used to provide additional support for?

• Client/Server applications• .Net applications

Page 3: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 3Confidential

How do I install the Extension Kit files?

• When installing SilkTest you will encounter the following dialog:

• Simply check the “Extension Kit” check-box to install the Extension Kit files and documentation

Page 4: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 4Confidential

What files are installed with the Extension Kit?

• The following files are installed to the EKWIN32 directory in the SilkTest install directory:

• qapwinek.h• assist.dll• assist.lib

• Tutorial files are also installed to the EKWIN32 directory as well as some example implementations

• The following documentation files are also installed:• Extension Kit Guide for Windows• Extension Kit Guide for .Net

Page 5: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 5Confidential

Extension Kit, Good to knows

• The Extension Kit is currently only compatible with Visual Studio 2003 and 2005

• The Extension Kit merely provides functions that allow a developer to communicate with the SilkTest Classic Agent

• This allows information to be passed from SilkTest to your extension dll

• It also allows your extension dll to pass information back to SilkTest

• An extension dll can only be implemented in C or C++

Page 6: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

The Extension Kit:A Worked Example

Page 7: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 7Confidential

The MonthCalendar Control

• The MonthCalendar control has no in-built support with SilkTest. We will now examine what functionality we would like to add to SilkTest that will allow us to interact with this control.

Page 8: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 8Confidential

What can we do with the MonthCalendar?

• The MonthCalendar control has the following functionality available:

• It displays the “Today Date” indicated by a red circle around a day of the Calendar

• We can select a singular day on the Calendar• We can also select a range of successive days, a maximum of

seven days from the first selected day• We can increment the Calendar by month or year• We can decrement the Calendar by month or year

Page 9: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 9Confidential

Automation Support

• Now that we know what we can do with the MonthCalendar, we must now define what functionality should automation support be provided

• Get/Set the “Today Date”• Get/Set a singular day on the Calendar• Get/Set a range of successive days on the Calendar• Increment/Decrement the currently displayed month on the

Calendar• Increment/Decrement the currently displayed year on the

Calendar

Page 10: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 10Confidential

Getting started

• We will start simply, our initial functionality will simply provide us with the means of getting the “Today Date”

• Let us define our function prototypes• We require a function that will register our “extension” functions

with the SilkTest Agent. This will be called “RegisterClassFunctions”

• We will also require a function that will return the “Today Date” of the MonthCalendar control, this function will be called “GetTodayDate”

• void RegisterClassFunctions();• void GetTodayDate(PARGS pArgs);

Page 11: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 11Confidential

Registering the MonthCalendar functions

• To register our extension functions with the SilkTest Classic Agent we make use of the function QAP_RegisterClassFun which is provided by the SilkTest Extension Kit

• In the above code excerpt, we register the C++ function GetTodayDate with the SilkTest Agent.

• For further information on the QAP_RegisterClassFun function refer to the Extension Kit Documentation

void RegisterClassFunctions(){QAP_RegisterClassFun("SwfMonthCalendar", "GetTodayDate", GetTodayDate, T_LIST_INTEGER, 0);

}

C++ function Return typeNumber of parameters to the 4test method

Name of the 4Test method

4Test class name

Page 12: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 12Confidential

GetTodayDate()

• The below code demonstrates how we retrieve the “Today Date” from the MonthCalendar control

void GetTodayDate(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

//retrieve pointer to the MonthCalendar controlpControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){//Cast the Control type to the MonthCalendar typeMonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);

//Get the today date from the MonthCalendar controlDateTime dt = tMonth->TodayDate;

//Create a list with the Day, Month and Year values of the Today DateQAP_ReturnListOpen(RETVAL);QAP_ReturnInteger(RETVAL, dt.Day);QAP_ReturnInteger(RETVAL, dt.Month);QAP_ReturnInteger(RETVAL, dt.Year);QAP_ReturnListClose(RETVAL);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 13: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 13Confidential

Defining our winclass

• In SilkTest we must subsequently define the winclass for the MonthCalendar control.

• As you can see from the above code, the 4Test class name and 4Test method name matches that which we specified in our RegisterClassFunctions function

[-] winclass SwfMonthCalendar:CustomWin[ ] tag "[System.Windows.Forms.MonthCalendar]“[ ] [ ] extern list of integer GetTodayDate()

Page 14: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 14Confidential

Making sense of our data

• Our GetTodayDate function returns a list of integer values representing the Day, Month and Year which is perhaps not the best way in which to return the information in an understandable format.

• Therefore we may want to further refine our winclass to return the information in an understandable format:

[-] winclass SwfMonthCalendar:CustomWin[ ] tag "[System.Windows.Forms.MonthCalendar]“[ ] [ ] extern list of integer GetTodayDate()[-] string GetTodayDate_As_String()

[ ] List of INTEGER dateVals = this.GetTodayDate()[ ] return "{dateVals[1]}/{dateVals[2]}/{dateVals[3]}"

Day Month Year

Page 15: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 15Confidential

Finally

• Lastly we must tell our dll to register the class functions when it is loaded into the virtual address space of the current process.

• If this is not done we will not be able to call our Extension Kit functions

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){switch (ul_reason_for_call){case DLL_PROCESS_ATTACH:

/*** REGISTER WITH THE SILKTEST AGENT ***/RegisterClassFunctions();break;

case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break;}return TRUE;

}

Page 16: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 16Confidential

Extension Kit in Action

• This is the application that we will be testing:

• As you can see we have two MonthCalendar controls in the application and our extension should differentiate between them

Page 17: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 17Confidential

Interact with Calendar 1

• The following is a simple testcase which will call our 4Test function GetTodayDate_As_String() which subsequently calls our extension function GetTodayDate()

• We must call LoadLibrary, to load our Extension Kit dll into the application

• And the results from the above testcase

[-] testcase Get_MonthCalendar1_Date() appstate none[ ] Form1.SetActive()[ ] Form1.LoadLibrary("C:/EK_.Net/SwfMonthCalendar.dll")[ ] print("The ""Today Date"" is: {Form1.MonthCalendar1.GetTodayDate_As_String()}")

[-] Testcase Get_MonthCalendar1_Date - Passed[ ] The "Today Date" is: 2/7/2008

Page 18: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 18Confidential

Interact with Calendar 2

• To verify that we can differentiate between the Calendar controls, I created a 2nd Extension Kit function which sets the “Today Date”. This function was called SetTodayDate (see source code):

• During the execution of the testcase the “Today Date” of Calendar 2 is set

[-] testcase Change_And_Get_MonthCalendar2_Date() appstate none[ ] Form1.SetActive()[ ] Form1.LoadLibrary("C:/EK_.Net/SwfMonthCalendar.dll")[ ] Form1.MonthCalendar2.SetTodayDate(2008,7,13)[ ] print("The ""Today Date"" is: {Form1.MonthCalendar2.GetTodayDate_As_String()}")

Page 19: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 19Confidential

Interact with Calendar 2 cont’d

• And when we call the GetTodayDate_As_String, we receive the following in our results file

• Try implementing the additional functionality, that we outlined earlier to provide comprehensive support for the MonthCalendar control

[-] Testcase Change_And_Get_MonthCalendar2_Date - Passed[ ] The "Today Date" is: 13/7/2008

Page 20: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

The Extension Kit:Source Code

Page 21: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 21Confidential

MonthCalendar Source Code

// SwfMonthCalendar.cpp : Defines the initialization routines for the DLL.//

#include "stdafx.h"#include <afxdllx.h>#using <mscorlib.dll> #using <System.Windows.Forms.dll>#using <System.Drawing.dll>#using <System.dll>using namespace System::Windows::Forms;using namespace System::Runtime::InteropServices;using namespace System;using namespace System::Reflection;

/*** Include EK header files here ***/#include "qapwinek.h"

#ifdef _DEBUG#define new DEBUG_NEW#endif

static AFX_EXTENSION_MODULE SwfMonthCalendarDLL = { NULL, NULL };

void RegisterClassFunctions();void SetTodayDate(PARGS pArgs);void SetSelectedDate(PARGS pArgs);void SetSelectedDates(PARGS pArgs);void GetTodayDate(PARGS pArgs);void GetSelectedDate(PARGS pArgs);void GetSelectedDates(PARGS pArgs);

Page 22: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 22Confidential

MonthCalendar Source Code cont’d

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){switch (ul_reason_for_call){case DLL_PROCESS_ATTACH:

/*** REGISTER WITH THE SILKTEST AGENT ***/ RegisterClassFunctions(); break;

case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break;}

return TRUE;}

void RegisterClassFunctions(){QAP_RegisterClassFun("SwfMonthCalendar", "GetTodayDate", GetTodayDate, T_LIST_INTEGER, 0);QAP_RegisterClassFun("SwfMonthCalendar", "SetSelectedDate", SetSelectedDate, 0, 3, T_INTEGER,T_INTEGER,T_INTEGER);QAP_RegisterClassFun("SwfMonthCalendar", "SetTodayDate", SetTodayDate, 0, 3, T_INTEGER,T_INTEGER,T_INTEGER);QAP_RegisterClassFun("SwfMonthCalendar", "SetSelectedDates", SetSelectedDates, 0, 6,

T_INTEGER,T_INTEGER,T_INTEGER,T_INTEGER,T_INTEGER,T_INTEGER);QAP_RegisterClassFun("SwfMonthCalendar", "GetSelectedRange", GetSelectedDates, T_LIST_INTEGER, 0);QAP_RegisterClassFun("SwfMonthCalendar", "GetSelectedDate", GetSelectedDate, T_LIST_INTEGER, 0);

}

Page 23: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 23Confidential

MonthCalendar Source Code Cont’d

void GetTodayDate(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);

DateTime dt = tMonth->TodayDate;QAP_ReturnListOpen(RETVAL);QAP_ReturnInteger(RETVAL, dt.Day);QAP_ReturnInteger(RETVAL, dt.Month);QAP_ReturnInteger(RETVAL, dt.Year);QAP_ReturnListClose(RETVAL);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 24: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 24Confidential

MonthCalendar Source Code cont’d

void SetSelectedDate(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

long iYear, iMonth, iDay;

iYear = GetArg(0,lValue);iMonth = GetArg(1,lValue);iDay = GetArg(2,lValue);

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);DateTime myDT = DateTime(iYear,iMonth,iDay,0,0,0);tMonth->SetDate(myDT);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 25: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 25Confidential

MonthCalendar Source Code cont’d

void SetTodayDate(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

long iYear, iMonth, iDay;

iYear = GetArg(0,lValue);iMonth = GetArg(1,lValue);iDay = GetArg(2,lValue);

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);DateTime myDT = DateTime(iYear,iMonth,iDay,0,0,0);tMonth->TodayDate = myDT;tMonth->SetDate(myDT);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 26: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 26Confidential

MonthCalendar Source Code cont’d

void SetSelectedDates(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

long sYear, sMonth, sDay;long eYear, eMonth, eDay;

sYear = GetArg(0,lValue);sMonth = GetArg(1,lValue);sDay = GetArg(2,lValue);

eYear = GetArg(3,lValue);eMonth = GetArg(4,lValue);eDay = GetArg(5,lValue);

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);

DateTime startSel = DateTime(sYear,sMonth,sDay,0,0,0);DateTime endSel = DateTime(eYear,eMonth,eDay,0,0,0);

tMonth->SelectionStart = startSel;tMonth->SelectionEnd = endSel;

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 27: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 27Confidential

MonthCalendar Source Code cont’d

void GetSelectedDates(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);

DateTime startSel = tMonth->SelectionStart;DateTime endSel = tMonth->SelectionEnd;

QAP_ReturnListOpen(RETVAL);QAP_ReturnInteger(RETVAL, startSel.Day);QAP_ReturnInteger(RETVAL, startSel.Month);QAP_ReturnInteger(RETVAL, startSel.Year);QAP_ReturnInteger(RETVAL, endSel.Day);QAP_ReturnInteger(RETVAL, endSel.Month);QAP_ReturnInteger(RETVAL, endSel.Year);QAP_ReturnListClose(RETVAL);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}

Page 28: SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user.

Copyright © 2008 Borland Software Corporation. 28Confidential

MonthCalendar Source Code cont’d

void GetSelectedDate(PARGS pArgs){Control* pControl = NULL;HWND hWnd = pArgs->hWnd;

pControl = System::Windows::Forms::Control::FromHandle(hWnd);

if(pControl){MonthCalendar * tMonth = dynamic_cast<MonthCalendar*>(pControl);

DateTime dt = tMonth->SelectionStart;QAP_ReturnListOpen(RETVAL);QAP_ReturnInteger(RETVAL, dt.Day);QAP_ReturnInteger(RETVAL, dt.Month);QAP_ReturnInteger(RETVAL, dt.Year);QAP_ReturnListClose(RETVAL);

}else{

QAP_RaiseError(1, "Unable to map the window handle to the .NET control");}

}