Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "SilkTest: The Extension Kit. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is the Extension Kit? The Extension Kit provides an end-user."— Presentation transcript:

1 SilkTest: The Extension Kit

2 ConfidentialCopyright © 2008 Borland Software Corporation. 2 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

3 ConfidentialCopyright © 2008 Borland Software Corporation. 3 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

4 ConfidentialCopyright © 2008 Borland Software Corporation. 4 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

5 ConfidentialCopyright © 2008 Borland Software Corporation. 5 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++

6 The Extension Kit: A Worked Example

7 ConfidentialCopyright © 2008 Borland Software Corporation. 7 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.

8 ConfidentialCopyright © 2008 Borland Software Corporation. 8 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

9 ConfidentialCopyright © 2008 Borland Software Corporation. 9 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

10 ConfidentialCopyright © 2008 Borland Software Corporation. 10 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);

11 ConfidentialCopyright © 2008 Borland Software Corporation. 11 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++ functionReturn type Number of parameters to the 4test method Name of the 4Test method 4Test class name

12 ConfidentialCopyright © 2008 Borland Software Corporation. 12 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 control pControl = System::Windows::Forms::Control::FromHandle(hWnd); if(pControl){ //Cast the Control type to the MonthCalendar type MonthCalendar * tMonth = dynamic_cast (pControl); //Get the today date from the MonthCalendar control DateTime dt = tMonth->TodayDate; //Create a list with the Day, Month and Year values of the Today Date 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"); }

13 ConfidentialCopyright © 2008 Borland Software Corporation. 13 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()

14 ConfidentialCopyright © 2008 Borland Software Corporation. 14 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]}" DayMonthYear

15 ConfidentialCopyright © 2008 Borland Software Corporation. 15 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; }

16 ConfidentialCopyright © 2008 Borland Software Corporation. 16 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

17 ConfidentialCopyright © 2008 Borland Software Corporation. 17 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

18 ConfidentialCopyright © 2008 Borland Software Corporation. 18 Interact with Calendar 2 To verify that we can differentiate between the Calendar controls, I created a 2 nd 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()}")

19 ConfidentialCopyright © 2008 Borland Software Corporation. 19 Interact with Calendar 2 contd 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

20 The Extension Kit: Source Code

21 ConfidentialCopyright © 2008 Borland Software Corporation. 21 MonthCalendar Source Code // SwfMonthCalendar.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include #using 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);

22 ConfidentialCopyright © 2008 Borland Software Corporation. 22 MonthCalendar Source Code contd 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); }

23 ConfidentialCopyright © 2008 Borland Software Corporation. 23 MonthCalendar Source Code Contd void GetTodayDate(PARGS pArgs){ Control* pControl = NULL; HWND hWnd = pArgs->hWnd; pControl = System::Windows::Forms::Control::FromHandle(hWnd); if(pControl){ MonthCalendar * tMonth = dynamic_cast (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"); }

24 ConfidentialCopyright © 2008 Borland Software Corporation. 24 MonthCalendar Source Code contd 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 (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"); }

25 ConfidentialCopyright © 2008 Borland Software Corporation. 25 MonthCalendar Source Code contd 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 (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"); }

26 ConfidentialCopyright © 2008 Borland Software Corporation. 26 MonthCalendar Source Code contd 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 (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"); }

27 ConfidentialCopyright © 2008 Borland Software Corporation. 27 MonthCalendar Source Code contd void GetSelectedDates(PARGS pArgs){ Control* pControl = NULL; HWND hWnd = pArgs->hWnd; pControl = System::Windows::Forms::Control::FromHandle(hWnd); if(pControl){ MonthCalendar * tMonth = dynamic_cast (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"); }

28 ConfidentialCopyright © 2008 Borland Software Corporation. 28 MonthCalendar Source Code contd void GetSelectedDate(PARGS pArgs){ Control* pControl = NULL; HWND hWnd = pArgs->hWnd; pControl = System::Windows::Forms::Control::FromHandle(hWnd); if(pControl){ MonthCalendar * tMonth = dynamic_cast (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"); }


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

Similar presentations


Ads by Google