For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
UFT + UFTPro 20th September 2017 7.30 AM - 9.00 AM IST 25Days Classroom + Online Hitech City
Selenium+Appium 4th October 2017 4.30 PM - 6.00 PM IST 40Days Online -

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Tuesday, April 27, 2010

Using one Library Functions / Variables in other Library

As we all know that we can automate the Web Applications by using only DOM + VBScript without having any automation tool. In this process we have to write the global functions to handle webobjects like links, edit boxes, radio buttons …etc.
I have got a requirement to automate an application only by using DOM + VBscript. For this process I have created all the global functions to handle every web object and stored all the functions in a library. Find some of the functions here to handle link, Edit, Radio buttons… etc.
This is the plan I thought to Automate the Testcases Using DOM

  • Develop Global Functions to handle Web Objects
  • Write scripts by calling global functions (scripts will be stored as VBS files)
I thought of using filesystem object and execute statements to call functions in . But those are not fully capable for some of the situations. And the next one immediately came in my mind is Microsoft Script Control.
Using Microsoft Script Control you can call one library functions in another library. For this you have to follow below steps.
  1. Read and store all the text from source library file using filesystem object
  2. Add the source library code as vbscript in MSScriptControl
  3. Call the functions using MSScriptControl methods
Source Library Code
Dim a
Function demo ()
MsgBox "QTP Sudhakar"
End Function
Function demo_add (x,y)
    demo_add = x+y
End Function
Calling the Functions in other libraries
'Create file system object
Set fso=CreateObject("scripting.filesystemobject")
'Open library file
Set sFile=fso.OpenTextFile("C:\Documents and Settings\sudhakar kakunuri\Desktop\Script Control\source.vbs")
'Read the complete data from library file
'close the file
'Create Script Control Object
Set scrControl=CreateObject("msscriptcontrol.scriptcontrol")
'Specify the language to be controlled
scrControl.Language = "VBScript"
'Add the source library code
'Diplay the number of procedures in th source library
MsgBox scrControl.Procedures.Count,,"Total Procedures Count"
'Display value of a variable in source library
Msgbox scrControl.Eval("a"),,"Value of Variable 'a'"
'Executing the function source library function
scrControl.Run "demo"
'Executing the function source library function with parameters
msgbox scrControl.Run("demo_add",10,20),,"demo_add function Result"
This is how we can use one Library functions / Variables in other libraries.
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

1 comment :

  1. Thank you so much, You've helped me a lot!!