Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Showing posts with label descriptive programming. Show all posts
Showing posts with label descriptive programming. Show all posts

Descriptive Programming Versus Object Repository In QTP


Which is better Descriptive programming or object repository usage ?

1. Descriptive programming solves many object recognition and maintenance problems that are otherwise going to stay (if we use Object Repository). So, we can rely on Descriptive Programming, ignoring Object Repository.

What happens if we ignore Object Repository
:

All the properties you use in Descriptive Programming will be treated as Mandatory properties. In turn we  are losing the power of Assistive properties in the object recognition mechanism of QTP .

QTP identifies an object using test object description stored in Object Repository. This description is made up of two sets of properties:

1. Mandatory Properties
2. Assistive Properties

For any object you can dictate QTP what properties to consider as mandatory and what properties as Assistive properties in a facility called "Object Identification".

Quick Test learns all mandatory properties by default. If it can't create a unique description for the object using mandatory properties alone, it starts learning one assistive property at a time until it creates a unique description for the object in question.

So, what it means is that just because you told QTP to use several Assistive Properties, it does not mean that it learns them all. It learns only to the extent needed i.e. until a unique object description is created

Also, in Descriptive Programming, you can't make use of the modern technology available in QTP - Smart Identification. You can use this only if have Object Repository.

If an object is not learned into Object Repository, there will be no logical name, no assistive properties, nor there do any base and optional properties to use for smart identification.
2. Descriptive Programming is better than Object Repository in cases where objects in the application are dynamic in nature and need special handling to identify the object.

Objects whose properties change dynamically for each run or depending on input data can be handled equally well by Object Repository.

In both cases you can use global or local sheet parameters, environment parameters as well as regular expressions to parameterize object properties.
3. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing an object. Descriptive Programming is better in such situations.

Size of the Object Repository has very little or nothing to do with performance of QTP. It is rather the nature and number of objects in a given page that impact the performance of QTP. For example if there is one web button on a web page, QTP needs only one property (class name) to uniquely recognize that object right away. If you have, say 100 web buttons in a web page, then QTP has to use additional properties to recognize the object (may be "Value" property). Like this, QTP keeps on using more and more properties until it recognizes the object uniquely and this is what causes performance degradation not the size of Object Repository. However using descriptive programming we can have just one utility function that can be called as and when we want to execute the specific event, by sending the associated set of properties for the corresponding objects. This is how we handle the Submit button click on all the pages in the application. We expect that each scenario requires the submit button to be clicked and parameterizing the properties and calling a single function helps us validate the scenario without increasing too much of the object repository size.
4. Descriptive Programming makes maintenance easy!

No. It is as bad/good as maintaining Object Repository. Just because if we use the traditional abject repository method, we can easily get the object set properties updated by using the tool provided within the QTP, however using descriptive programming, we need to manually alter the [properties and that is a very time consuming one.
5. QTP cannot take action on an object until unless its object description is in the Object Repository. But descriptive programming provides a way to perform action on objects which are not in Object repository

If an object is not defined  in the object repository, you will have to create your own description of that object so that QTP can recognize and act on it. You will have to create the description very carefully otherwise you will get run error.

In Descriptive Programming, creating a workable description for some objects can prove to be very tedious and time consuming some times. Properties that work are not always consistent. Sometimes you have to dig through several combinations of properties to find one that works correctly.

You will be better off adding object to the Object Repository with just click of a button rather than creating a time consuming buggy description all by yourself.
6. Using Descriptive Programming, automation scripts can be created even if the application has not been developed.

If you build object descriptions (and scripts based on those descriptions) without ever spying on the objects, the chances are that, in more than 50% of the cases, the description might fail.  But if you have great development discipline in place, we go for this approach. Several projects utilize the keyword driven aopproach to mae this all successful.

Scripts you create without having the application developed will hardly serve you any purpose. This is because, without having the application developed, you can't have active screens captured, can't insert checkpoints, can't output values.  But Reporter.reportevent is something that serves the purpose with a beauty. You need to be sufficiently expert in the Vbscript usage and optimize the code using it by various combinations of conditional looping and things as such.
Advantages of Descriptive programming

Descriptive Programming Solves redundancy problem.

If you have same objects on many pages, you don't need to add them to Object Repository under each page. You can handle it with Descriptive Programming and avoid redundancy.

Descriptive Programming solves the problem of dealing with large number of objects of same type.

For example, you can't anticipate search results and put them in Object Repository in advance. You can create descriptions for such objects and make QTP act on them based on, for example, ordinal identifier.  A yet another powerful utility in the object recognition mechanism.
Conclusion

Descriptive programming
helps us handle special circumstances which otherwise can't be handled with Object Repository alone. However, in the final analyses, Descriptive Programming should NOT be treated as replacement for Object Repository for it is far from being a viable alternative to object Repository.

Descriptive Programming is a necessary exception rather than a norm. But, at the same time, we can't live without Descriptive Programming.



For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP



Regular expression In QTP :

How To Use : Regular expression to make our search globalize.

To execute the test in QTP every object is searched in the object repository (OR). In
real time applications some object's properties always keep changing so at the
time of execution script fails. To overcome it we use "regular expression " for
that particular object's property. For example:

1) Record a test where you are inserting one order and than faxing the same order.
2) The order number that is generated during recording may 21 and Fax Order window title is generated and saved into OR as Fax Order No. 21
3) Now execute the same test the script will fail because this time order no is modified as 22 and accordingly Fax Order window title is modified as Fax Order No. 22 .
4) This time the object Fax Order No. 22 is not identified or you can understand object is not matched (find) into OR.

5) To make this search better we modify the text property of object into OR as Fax Order No.* this will search all the
occurrences of window that has text as Fax Order No

6) We can also write it as Fax Order No. [0-9] because fax order no is a numerical value and this will search only numbers after Fax Order No.

So this is the purpose of regular expression in QTP.
To handle the dynamics objects either window/web based application. To handle the objects those name having string along with number the number may change in every execution or every particular time. To handle these objects we can use regular expression.
It have 5 types
1. Dot - .
2. regular expression
3. Star - *
4. Carat - ^
5. Range - [ ]
Also Regular Exp is used for pattern matching and replacing of a string.

* : Matches the preceding character zero or more times.
. : Matches any single character except a newline character.

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP

Convert QTP Test Files from one Version to another

'*************************************************************************'
Description:
'
'This example specifies a folder in which tests from an older QuickTest version are
'stored and then loops through each test in the folder (and its subfolders) to open
'each one and save it in the current version format.
'
'***************************************************************************

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim filesys
Dim maindir
Dim testCol
Dim checkfolder

' Create the QuickTest Professional object
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True

' Get the collection of test scripts
Set filesys = CreateObject("Scripting.FileSystemObject")

' TO DO: Sepecify the test script directory....
Set maindir = filesys.GetFolder("C:\temp")
Set testCol = maindir.SubFolders

' Loop through each test in the collection
For Each fl In testCol

    ' Verify the folder is a QTP test
    checkfolder = fl.Path & "\Action0"
    If (filesys.FolderExists(checkfolder)) Then ' The folder is a QTP test folder

       ' Convert test
       qtApp.Open fl.Path, False, False

       ' wscript.sleep 1000

       ' Save converted test
       qtApp.Test.Save

    End If
Next

qtApp.Quit

' Release the File System Objects
Set testCol = Nothing
Set maindir = Nothing
Set filesys = Nothing

' Release the QuickTest Professional application object
Set qtApp = Nothing

 The code above will make a set of sript test files work into a new version of the qtp. It just upgrades the script version compatibilty.

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP

XML File handling Using QTP


QTP Descriptive programming with xml file handling

The following example uses the ItemByName property to confirm that the QTP attribute was added.

Set doc = XMLUtil.CreateXML()

doc.LoadFile "c:\example.xml"

Set root = doc.GetRootElement()

Set attrs = root.Attributes()

msg = "At first I had " & attrs.Count() & " attributes. "

root.AddAttribute "QTP","Great"

Set attr = attrs.ItemByName("QTP")

if attr is nothing then

msgbox "Failed to add attribute!!!"

end if

msg = msg + "Now I have " & attrs.Count() & " attributes. "

root.RemoveAttribute "QTP"

msg = msg + "Again I have " & attrs.Count() & " attributes."

msgbox msg


For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP


Automating Using QTP Day5 Some VbScripting Techniques

Synchronization of the application load with the Script execution :
Wait and WaitRoproperty.
In scenarios wherein the properties of the object changes after some time we use waitproperty.

Object Recognition Mechanism in QTP :

  • Add object in the Object Repository using Object Spy 
  • Creating the same using Descriptive programming.
  • Using the active screen or going into the application and clicking insert new object.
Regular Expression Usage Effectively in the scripting :
After having gone through the Book Ticket scenario in the Flight application . just go into the File menu for Fax order scenario.
Go to file and select Fax the booked tickets.
Select for regular expression option so that the fax order number gets recognised each time on the basis
of this very regular expression
Just put a .* after the point from where the characters is expected to be changed.

Text Checkpoint :
Checked text, Text Before, After text
Match CAse, exact match,

Text Area checkpoint
is for tabular display for any specific row.
namespace standards in xml.
XML Addins
is required for the XML checkpoints.

Test Objects used by web services.
Strat Transaction end transactionm...
Time frames get retunrned
Generally used foir query time out features related to databasae interactions.
Colon is used to combine multiple statement in one line

Important conecpts in Advanced QTP workaround :

  • Parameterization
  • Checkpoint
  • Synchronization
  • Object Repository
Descriptive Programming  is a technique used when an object property changes frequently.
No Object Repository method is used for object identification.

Static are the necessary properties of an objects.
Methods like SET are used for creating references to the objects actually present in the application.

Let us look into describing the Objects in the application. Do remember the hierarchy of the Parent and child objects. Generally  the approach we follow for the description programming  is coding in the hierarchial manner that an object is recognized by the QTP tool during the course of object identification.

 Login Box Which is a dialog box
 Keep your appplication open, Object Spy tool can be useed to spy onto the objects and highlight and  copy the properties of the required objects.
 Individually search for each of the objects associated properties.
 Always use the two things, class name and the text name genuinely very relevant.

 Below we spy for the Login dialog page properties

Parent Objects :
Set oLogin=Description.Create()oLogin("Class Name").Value="Dialog"
oLogin("text").Value="Login"

 Child Objects :
 For Login Fileds Textbox

Set oUserNam=Description.Create() oUserNam("Class Name").Value="WinEdit"
 oUserNam("attached text").Value="Agent Name:"

 For Password Fields Textbox Set opassword=Description.Create()
 opassword("Class Name").Value="WinEdit"
 opassword("attached text").Value="Password:"

For Button to log on OKSet oOKButton=Description.Create() oOKButton("Class Name").Value="WinButton"
oOKButton("text").Value="OK"

 For Button to log on CancelSet oCanButton=Description.Create() oCanButton("Class Name").Value="WinButton"
oCanButton("text").Value="Cancel"

 Now , let us code using VBScript  to execute the events in the application which is expected to be performed for logging into the application.

InvokeApplication
"D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight3a"
Dialog(oLogin).WinEdit(oUserNam).Type"employee"
Dialog(oLogin).WinEdit(oUserNam).Set "employee"
Dialog(oLogin).WinEdit(oPassword).Set "mercury"
Dialog(oLogin).WinButton(oOKButton).Click


Dynamic Descriptive programming :
InvokeApplication  "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight3a"
Dialog("Class Name:= Dialog","text:=Login").Winedit("Class Name:=WinEdit","attached text:=Agent Name:").Set "2039"
Dialog("Class Name:= Dialog","text:=Login").Winedit("Class Name:=WinEdit","attached text:=Password:").Setsecure "4ceb5e5216db248fd801b9d8e2364301e4bafec6"


This is how we do descriptive programming to automate the stable working features of an application. Do always take care of the hierarchy of the application.

Using VBScript Code In QTP


VBScripting in QTP  we will cover the following :
  1. Description. Create.
  2. Function to check if a DataTable sheet exists or not
    
  3. Insert Call to Copy
  4. Insert Call to Existing
  5. Action Parameters
  6. Resources
  7. Environment Variables.  

 
Set oDosW = Description.Create
oDosW("regexpwndtitle").Value = "C:\\Windows\\System32\\cmd\.exe"
oDosW("regexpwndtitle").RegularExpression = False
 
Window(oDosW).Activate
 
'Launch the window with title MyPuttyTesting
SystemUtil.Run "cmd", "/K title MyPuttyTesting"
 
'Launch the window with title MyFTPTesting
SystemUtil.Run "cmd", "/K title MyFTPTesting"
 
'Uniquely Recognize console application simultaneously without any ordinal identifier
Window("title:=MyPuttyTesting").Activate
Window("title:=MyFTPTesting").Activate
 
To get the current script name we can use the below line of code
Msgbox Environment("TestName")
'Description: Function to import the all the sheets present in the file
'Params:
'@FileName - File to import
Function ImportAllSheets(ByVal FileName)
                    Dim oExcel, oBook
 
                    'Launch excel
                    Set oExcel = GetObject("", "Excel.Application")
 
                    'Open the file in read only mode
                    Set oBook = oExcel.WorkBooks.Open(FileName,,True)
 
                    'Enumerate through all the sheets present in the file
                    For each oSheet in oBook.WorkSheets
 
                                         'Check if a DataTable with current name already exists
                                         If Not IfDataSheetExist(oSheet.Name) Then
                                                             'DataTable cannot be imported if the sheet does not exist
                                                             DataTable.AddSheet oSheet.Name
                                         End If
 
                                         'Import the sheet
                                         DataTable.ImportSheet FileName, oSheet.Name,oSheet.Name
                    Next
 
                    Set oBook = Nothing
 
                    'Quit Excel
                    oExcel.Quit
                    Set oExcel = Nothing
End Function
 
'Function to check if a DataTable sheet exists or not
 
Function IfDataSheetExist(ByVal SheetName)
                    IfDataSheetExist = True
                    On error resume next
                    Dim oTest
                    Set oTest = DataTable.GetSheet(SheetName)
                    If err.number Then IfDataSheetExist = False
                    On error goto 0
End Function
 
Smart identification is a algorithm which QTP uses when it is not able to identify a object. 
The algorithm tries to figure out if there is a unique control on the page which matches the some of the properties 
of the failed object.This happens because when QTP SI starts looking for a Logout button there is none, but there is
 only one button on the page. So QTP SI assumes that it is the Logout button which we were looking for.
 
Setting("DisableReplayUsingAlgorithm") = 1
'or using AOM code
CreateObject("QuickTest.Application").Test.Settings.Run.DisableSmartIdentification = True
 
  Insert Call to Existing – User to insert call to a re-usable action located within the same test or some other test.  This inserts the call to the existing action. In case the action in present in some other test case then a read only copy of action is inserted.

Insert Call to Copy - Inserts call to an existing re-usable action and creates an editable copy of that action. Actions cannot be deleted from a Test from Expert view. To delete a action one must go to the keyword view and delete the action.

An action call cannot be inserted directly by writing code in Expert View, it has to be added through the GUI first.

Global Data Table – Data table for Test flow

Local data table – Data table for every action


Environment variables are global variables available to all Actions Environment variables are of two types
1.      Built-in
2.      User-Defined
  • Built in environment variables give information about the system and the current test
  • User-defined Environment variables added in the Environment tab of Test Settings are Read-only during the test run
  • Environment variables can be added during runtime also using code
       Environment.Value("OrderNumber") = "ABCDEF"
  • Environment variables can be loaded at run-time from a XML file using the below code
       Environment.LoadFromFile "C:\TestEnvironment.xml"
  • Parameters provide another way of parameterizing the test cases.
  • There are two types of parameters
1.      Test parameters
2.      Action parameters
  • Test parameters can be set in Test->Settings…->Parameters (Tab)
  • Test parameters value can be provided when replaying the test
  • Test arguments can be accessed in the test using TestArgs(””)
Action Parameters
  • Used to pass parameters to Action
  • Output parameters can only be used when Action is being called for a single iteration
  • Ex – RunAction “Login”, oneIteration, “TestUser”, “TestPass”, out
  • A parameter can be accessed using
Resources
  • Scripts written in VBScript language can be add as a Resource to the test
  • All code written in the script is available across all Actions
  • A VBScript can also be loaded in an Action by using ExecuteFile function. Ex –
ExecuteFile “C:\Init.vbs”
  • In case of multiple files QTP combines all the files into a single one and executes the code. The files are combine in bottom to top order
·         Only Database and XML checkpoints can be inserted in idle mode.
·         Rest all checkpoints can only be added during Recording or through Active screens.

  • Object Based DP
       Set btnSearch = Description.Create : btnSearch("name").Value = "Search"
       Set brwGoogle = Description.Create : brwGoogle("title").value = "Google"
       Set pgGoogle = Description.Create : pgGoogle("title").value = "Google"

       Browser(brwGoogle).Page(pgGoogle).WebButton(btnSearch).Click
  • Description objects can also be used to get all child objects matching a criterion. Ex –
       Set oDesc = Description.Create
       oDesc("name").Value  = "txt_.*"
       oDesc("name").RegularExpression = True
       Set allMatchingObjects = Browser().Page().ChildObjects(oDesc)
       Msgbox allMatchingObjects.Count
       Msgbox allMatchingObjects(0).GetROProperty("name")
  • By default all property values are considered as regular expression patterns
  • When using string description all regular expression must be used with escape character for literal meaning. Ex - …Link(”text:=Logout \(Tarun\)”).Click
  • DP based Object repository can be created in any file
  • Code can be copied from one script to another without copying the object repository
  • Custom implementation of object is easier. Ex –
       objStrDesc = "Browser(""title:=Test"").Page(""title:=Test"").Link(""text:=Login"")"
       Execute "Set obj = " & objStrDesc 
       obj.Click


Automation Testing with QTP

Description:   ''This example starts QuickTest, opens a new test, and adds a new action, which calls a second action.Then it edits the first action's script to move the call to the second action to a new position in the script,validates the syntax of the new script, defines some action parameters, and uploads the modified action script.”

Dim qtApp, ActionContent, ActionName, ActionDescr, NewAction, SecondAction, script

Below line of code creates an object of the Class Application for the QuickTest Software
Set qtApp = CreateObject("QuickTest.Application") ' Create the application object
qtApp.Launch
qtApp.Visible = True
qtApp.New
 In the above line of code just the environment is getting created and then on we can start with the scenarios. qtApp is the instance of the QTP that will be used.

ActionContent = "Window(""Calculator"").WinButton(""1"").Click" & vbCrLf & "Window(""Calculator"").WinButton(""+"").Click" & vbCrLf & "Window(""Calculator"").WinButton(""+"").Click" & vbCrLf & "Window(""Calculator"").WinButton(""="").Click"
ActionDescr = "A new sample action for the test."
ActionName = "Action" + CStr(qtApp.Test.Actions.Count + 1)

CStr is a vbscript function that is used to change any content into string.

Add a new action at the beginning of the test
Set NewAction = qtApp.Test.AddNewAction(ActionName, ActionDescr, ActionContent, False, qtAtBegining)

Here what is being done is instance of the QTP application is availed in qtApp variable as initialized above and in that instance a class named Test which is actually automated Project name in the current context, and then on we add a method name which is different from a function “AddNewAction” : It can be termed as a set of events that may be used by some other events within the project.

Do remember that in oreder to make an Action to be reusable the property must be assigned as reusable, also in case we want to call it from outside the current project, it needs to be defined as Global which has also been discussed in prior posts.

What we do here is Add another action and call it from the beginning of the action that was just added above.

ActionContent = "Function f1(str)" & vbCrLf & vbTab & "msgbox str" & vbCrLf & "End Function"
ActionName = "Action" + CStr(qtApp.Test.Actions.Count + 1)

Set SecondAction = NewAction.AddNewAction(ActionName, ActionDescr, ActionContent, True, qtAtBegining)
qtApp.Test.AddNewAction was used in the previous action creation code.
NewAction.AddNewAction is being used in this very action creation code.

Now we will be using  the Load Script function to store the content of the first new action into the script array
script = Load_Script(NewAction.GetScript())
script = Move_CallAction(script, SecondAction.Name, UBound(script))
ActionContent = Save_Script(script)
scriptError = NewAction.ValidateScript(ActionContent)

'Converts script array to the text
'Sets new script source to the action
Load_Script, Move_CallAction, Save_Script  are user defined function as is availed below after some more logical coding.

Now the below code needs to be called
If Len(scriptError) = 0 Then
    NewAction.SetScript ActionContent
    NewAction.Description = "Check the calculator application and run next Action"
    NewAction.Type = "Reusable" 'Put Reusable type to the new action
    Set aParamDefs = NewAction.ActionParameterDefinitions
    aParamDefs.Add "InParam", "An input action parameter definition", 0, 0, "Input Value"        
    aParamDefs.Add "ResParam", "An output action parameter definition", 0, 1, "Output Value"
    Set resParamDef = aParamDefs.Item ("ResParam")
    resParamDef.Type = 1 'Put the boolean parameter type
    resParamDef.DefaultValue = false
    resParamDef.Description = "Result parameter"
Else
    Err.Raise E_SCRIPT_NOT_VALID, "Validate Script Error", scriptError
End If

Const E_SCRIPT_TABLE = 1
Const E_EMPTY_SCRIPT = 2
Const E_SCRIPT_NOT_VALID = 3

Const is the keyword available with VBScrip which can be used to assign values to variables that can not be overloaded with any other re initializations. Generally we use it in Sheet names and other environment variable names.
·         Public Function Load_Script(src)
If Len(src) = 0 Then
Err.Raise E_SCRIPT_TABLE, "Load_Script", "Script is empty"
End If
Load_Script = Split(Trim(src), vbCrLf)
·         End Function
Len is used to return the length of the string within the parameters. It is in built function with VbScript.
Split is another function name which is used to sub divide a string into individual elements based on separator mentioned [in this case vbcrlf ] and get it stored in an array format.
Trim is a yet another function which is used to remove any extra space that might be preceding or suffixing the string in this case src. Such as a string “  vip  ” string becomes trim(“  vip  ”) as “vip”.
We do have Ltrim & Rtrim functions to remove spaces only from left side or right side, ahich can be used as suits our requirement.
·         Public Function Save_Script(script)
If Not IsArray(script) Then
Err.Raise E_SCRIPT_TABLE, "Save_Script", "Script should be string array"
End If
If UBound(script) - LBound(script) = 0 Then
Err.Raise E_SCRIPT_TABLE, "Save_Script", "Script is empty"
End If
Save_Script = Join(script, vbCrLf)
·         End Function

IsArray is a function that checks if the parameter within braces is an array or not, an according returns as true or false which is VbScript is denoted as 1 or 0. 
UBound and Lbound gives the boundary value of the array index to which the resulting array from the string broken up results. Suppose the array size after string split is 78, then Lbound is 0 and UBound is 77.
Join as the name suggests joins the two strng just like a concatenation operator.

Find_Line, Move_Line,Insert_Line,Delete_Line are some of the functions which will help us demonstrate our conceptual clarity to play with QTP and make ourselves empowered to create any automated testing execution flow with ease, with perfection.
·         Public Function Find_Line(script, criteria)
Dim rExp, I
'Verify that the first argument contains a string array
If Not IsArray(script) Then
Err.Raise E_SCRIPT_TABLE, "Find_Line", "The script should be a string array"
End If
Set rExp = New RegExp
ptrn = ""
If IsArray(criteria) Then
ptrn = Join(criteria, " * ")
Else
ptrn = criteria
End If
rExp.Pattern = ptrn 'Set pattern string
rExp.IgnoreCase = True ' Set case insensitivity.
rExp.Global = True ' Set global applicability.
I = 0
For Each scrItem In script
If rExp.Execute(scrItem).Count > 0 Then
Find_Line = I
Exit Function
End If
I = I + 1
Next
Find_Line = -1
·         End Function

Find_Line  is a function that has a certain return type. We have two types of methods which is of profound interest to our requirement , one being the SubRoutine, and the other being Function . The only difference being that the SubRoutine has no return type and has the keyword Sub prefixed, and the latter Function has the keyword Function associated to it, and has some return values associated with it. In this case the return type being the value 0 or 1 in accordance with the code execution.
Having already discussed about IsArray & join we do not need to revisit it here .
For each Next block is something that is used as a looping control block to execute some loop for our business requirement or in this case just to visit to each index within the array.
Regular expression is something new we have come to in this very code block. It is used to create some sort of pattern matching for our requirements to be addressed with ease. For simple context suppose in a website we have to fill in an e-mail id, so there needs a validation to be performed as to whether the entered e-mail id is in correct format or not. A sort of pattern matching is needed in this context. The same is being done when we do in above code block.
New RegExp is the instantiation of the regular expression that is used to be met.

For each scrItem in Script means that for each index value in the array Script we have some looping that occurs, and the code is indeed self descriptive enough to us.

ExitFunction is the keyword that is used to exit from the execution of the Function block as and whne such condition is met. Similar is the use of ExitFor, ExitIf,ExitWhile.

·         Public Function Move_Line(script, curPos, newPos)
'Verify that the first argument contains a string array
If Not IsArray(script) Then
Err.Raise E_SCRIPT_TABLE, "Move_Line", "Script should be string array"
End If
scrLen = UBound(script) - LBound(script)
If curPos = newPos Or curPos < 0 Or newPos < 0 Or scrLen < curPos Or scrLen < newPos Then
Move_Line = script
Exit Function
End If
tmpLine = script(curPos)
If newPos > curPos Then
For curPos = curPos + 1 To scrLen
script(curPos - 1) = script(curPos)
If curPos = newPos Then
script(curPos) = tmpLine
Exit For
End If
Next
Else
For curPos = curPos - 1 To 0 Step -1
script(curPos + 1) = script(curPos)
If curPos = newPos Then
script(curPos) = tmpLine
Exit For
End If
Next
End If
Move_Line = script
·         End Function

In the function Block Move_Line , we have just reused the functions that were used in the previous function and introduced some new keywords which work in accordance with what we discussed earlier, such For Next loop , If Else condition block, For next with negative iteration as well by using the Keyword Step-1 to customize a back loop with 1 decrement, same can be altered by step-2 and so on and so forth. One binary operator is used “OR” which is same as we might have had acquaintance in the Digital Circuit Gate circuit creation. It equate to true if at least one condition evaluates to TRUE. We have similar Keyword available in AND wherein both needs to be TRUE to make the evaluation return the value as TRUE.

·         Function Insert_Line(script, lineSrc, linePos)
'Verify that the first argument contains a string array
If Not IsArray(script) Then
Err.Raise E_SCRIPT_TABLE, "Insert_Line", "Script should be string array"
End If
scrLen = UBound(script) - LBound(script)
If (scrLen = 0 And linePos <> 0) Or (linePos > scrLen + 1) Then
Insert_Line = script
Exit Function
End If
newScript = Split(String(scrLen + 1, " "), " ")
shiftIndex = 0
For I = 0 To scrLen + 1
If linePos = I Then
newScript(I) = lineSrc
shiftIndex = 1
Else
newScript(I) = script(I + shiftIndex)
End If
Next
Insert_Line = newScript
·         End Function
In the function above for Insert_Line we do not have much of an indifference to the prior code except for the introduction of the operator Not Equal to which is symbolically represented as “<>”.

·         Function Delete_Line(script, linePos)
'Verify that the first argument contains a string array
If Not IsArray(script) Then
Err.Raise E_SCRIPT_TABLE, "Delete_Line", "Script should be string array"
End If
scrLen = UBound(script) - LBound(script)
If (scrLen = 0) Or (linePos > scrLen) Then
Insert_Line = script
Exit Function
End If
If scrLen = 1 Then
Delete_Line = Array()
Exit Function
End If
newScript = Split(String(scrLen - 1, " "), " ")
shiftIndex = 0
For I = 0 To scrLen
If linePos = I Then
shiftIndex = 1
Else
newScript(I - shiftIndex) = script(I)
End If
Next
Delete_Line = newScript
·         End Function
Similar is the code creation as has been already discussed , with nothing new coming into picture. Split is being done for the string, and the separator in this case is blank space.

·         Public Function Move_CallAction(script, actName, newPos)
curPos = Find_Line(script, Array("RunAction", """" & actName & """"))
Move_CallAction = Move_Line(script, curPos, newPos)
·         End Function

Move_CallAction is the main controller within this module as is clearly visible from the above code block. Having read through the complete article carefully and patiencely anyone could have figured out how the control flow can be regulated. I hope the code is self explanatory and at times I have chipped in with some comments which can be definitely understood without much of a hara kiri.

Object Identification by Descriptive Programming

Descriptive Programming Using VbScript

Find All List Objects On a Web Page :


Sub ChildObjects_Example()
'The following example uses the ChildObjects method to find all the
'list objects on a Web page, and then to select an item in each list.

Set oDesc = Description.Create()
    oDesc("micclass").Value = "WebList"
Set Lists = Browser("Mercury Interactive").Page("Mercury Interactive").ChildObjects(oDesc)
    NumberOfLists = Lists.Count()
For i = 0 To NumberOfLists - 1
    Lists(i).Select i + 1
Next

End Sub



Find All Web Edit Objects On a Web Page :


Sub ChildObjects_Example()

'The following example retrieves the collection of
'WebEdit objects in order to find a specific
'WebEdit object in a page and set a value for it.

Dim EditToSearch, ValueToSet, NumberOfEdits

'This is the value of the 'name' property for the WebEdit object we want to find.
EditToSearch = "credit_card_number"

ValueToSet = "3558986773230578"

'Create a description object to help retrieve all WebEdit objects in a specific page.
Set oDesc = Description.Create()
    oDesc("micclass").Value = "WebEdit"
    oDesc("name").Value = "credit_card_number"

'Retrieve all WebEdit objects in this page
Set EditCollection = Browser("Book a Flight: Mercury").Page("Book a Flight: Mercury").ChildObjects(oDesc)

NumberOfEdits = EditCollection.Count

'Search for a specific WebEdit object and set its value
For i = 0 To NumberOfEdits - 1
    If EditCollection(i).GetROProperty("name") = EditToSearch Then
       EditCollection(i).Set ValueToSet
    End If
Next
End Sub



Find All Specific Web Edit Objects On a Web Page :

Sub ChildObjects_Example()

'The following example retrieves the collection of
'WebEdit objects that contain credit card numbers
'and inserts them in an Excel file.

Dim NumberOfEdits

'Create a Description object to help retrieve all
'WebEdit objects in a specific page.
Set oDesc = Description.Create()
    oDesc("micclass").Value = "WebEdit"

'Retrieve all WebEdit objects from this page.
Set EditCollection = Browser("Book a Flight: Mercury").Page("Book a Flight: Mercury").ChildObjects(oDesc)
NumberOfEdits = EditCollection.Count

'Use the GetROProperty to retrieve the "text" property
'(which in this case represents a credit card number),
'and insert all retrieved credit card numbers in an Excel file.
For i = 0 To NumberOfEdits - 1
     CurrentCreditNumber = EditCollection(i).GetROProperty("text")
     WriteToCreditCardNumberExcelFile (CurrentCreditNumber)
Next

End Sub