Friday, 30 August 2013

String And Array Manipulations in VB Scripting: Part2: String Function

Most Useful String Functions:

Hello folks,, I will be discussing few string function which are very useful in our day to day automation coding.
1. InStr([start, ]string1, string2[, compare])
most use variant of this function is as below
This function searches the occurrence of the str2 in the string str1, and returns the first occurrence of the str2.

str1="This world is good world"
msgbox Instr(str1,str2)

:OutPut 6
Notice that it is the position not the index or the subscript as one can confuse it with arrays in which the base is 0.
Now the more advanced version

str1="This world is good world"
msgbox Instr(7,str1,str2)
:output 20
Here the first parameter '7' is optional, it shows the starting point of the search.So the first occurrence of "world " is ignored....
The second optional parameter  in below is for comparison mode(0,1).'0 ' means the exact matching(case sensitive, binary comp), '1' means textual comp(case insensitive,textual comp)

str1="This world is good world"
msgbox Instr(7,str1,str2,0)
msgbox Instr(7,str1,str2,1) 
:output 0
:ouput 20
This completes the Instr Function 

2. InStrRev([start, ]string1, string2[, compare]): Identical to Instr but the search is reversed it search the string from the right side, rest all is same.

Hope it helped..

3.Mid(string, start[, length]): It is one of the very very very important functions in VbScripting.
it gives any specific part of the string .


now i want to extract the second letter in it. As it is not a array so we cant use str(1).
So we use

msgbox str2

Output: e 
Now in this statement
Instructs the VB engine that it has to start from the second element(2 as second parameter) and extract the 1 element(1 as the third parameter) from the string str1(first parameter).

This function is used mostly in reversal of string without using reverse function.
see post.
Hope this helped

String And Array Manipulations in VB Scripting: Part1

Array Declaration: .Array declaration are of two types,depending upon the use of the array and the fact whether we know the size of array in advance.
Below are described these one by one.
Static Declaration: In this we must know the exact size of the Array we are gonna use.Below is syntax for the array declaration
Dim Ary(10)..

Array are zero based in VBScriptig so the total no of element in the above mentioned array is 10+1=11 elements.
During declaration of the array we mention the maximum subscript we are gonna use.

data can be assigned  using the indexed



and in same manner it can be retrieved too.
msgbox var1

Output: 50
Arrays can be multidimensional (maximum 60 dimensions). Below is an example of 2-D array with 10 rows and 11 columns.
Dim Ary(9,10)

Dynamic Array Declaration: In this we don't need to know the exact size of array we can change the size of array as we move further.
Dim DynamicAry()

Redim DynamicAry()

Now when we use dynamic array we dont mention sige subscript in Dim statement.
Instead each time while using we mentioned the increased size.
Dim DynamicAry()

Redim DynamicAry(0)
Redim Preserve DynamicAry(1)
msgbox DynamicAry(0)
msgbox DynamicAry(1)




Preserve is a keyword which tells the VBScript engine to use preserve the content the of array while changing the size of the array.

I will be posting more on String and Array manipulation in future posts.Keep watching.... :)
Please comment for any query or concerns.

Query to return only test sets with Non Closed defects

HI ,
Below query will give the result for all the test set , which will have linked defect status as non closed status.

Please  notice that this query will account the defects which are conntect to test set only. (there miight be some defect which are linked to test case or test step.)

SO this will give us the name of the Test Set and Ensure that these Test Set have doesnt have any closed defect.
select cy_cycle_id as 'Test Set Name',BG_status 'BUG Status' from cycle,link,bug
where cy_cycle_id=LN_ENTITY_ID and LN_ENTITY_TYPE='CYCLE' and ln_bug_id=bg_bug_id
and cy_cycle_id not in (select ln_entity_id from link,bug
where LN_ENTITY_TYPE='CYCLE' and ln_bug_id=bg_bug_id and bg_status='Closed') 

Please comment if you have nay issue or the cpncern with the result set

Reversing a String: How to reverse a string without using a reverse function

Hi Folks,
I am certain the most of you have come accross the situation like this, This is one of the most common interview question of any programing interview(No matter whether it is Scripting Lang or Prog Lang, you are gonna get this question).

No  in my question I have below example

Notice that the data is used in String and not in Array and this is where it gets intresting
Now I want the output as


Now in conventional way we would have the stirng stored in variable array but that is the main feature in this example.We will index the each element of the string without using the actual array.


strlen= len(samplestring)
For i=1 to strlen
msgbox outputString

Hope this will help!!!!!!

for any query/comment please write on the section below

Tuesday, 27 August 2013

QTP Basics Part2: Recording modes:Analog Mode

Recording Mode Continued....

Analog Mode: This mode enables user to capture exact mouse movement and the action performed.
For an example if you are gonna click on submit button.It wont capture the submit button and the properties of the object ,instead it will capture the co-ordinate movement and the action performed .So it will capture the info that the a click action is performed at the location.(300,468).
Now again this mode has some drawbacks

Once the a script is recorded with analog mode , we cant edit the Analog Recorded Steps within the QTP.

Steps to use Analog mode:

1. Click on the Red recording button, as in Normal recording mode.
2. once the recording is started . Click on mouse like icon as shown in below screen shot.
Please notice this button is disabled by default.Once we click on the recording button then only it will be enabled.

3. After clicking on the analog Mode recording button. A new window will be    displayed with analog recording options as shown in below snapshot.This has two option.the first option lets QTP capture co-ordinates with reference to the screen itself.
If you want to make QTP store the script capture relative to any specific window(And yes this is more reliable, because you can run several window in this case and those wont conflict )SO it is good practice to use the second option and store analog mode for relative screen capture.(Click on the hand button to specify the window)
4. Once the Proper option is selected, click on the Start Analog Record.
5. perform the action you need to perform and record

6.After recording is done. Click on the stop recording button.

Now Please notice you have received just a one line of statement,instead of multiple line of code specifying each step like in Normal Recording Mode.It just shows a call statement for Analog Capture function, which store the entire story covered till now.
This statement may look as 

Desktop.RunAnalog "Track2" 

And yes we cant see the content of "Track2" .Actually the RunAnalog is a QTP Defined function
which stores the reference of the information storage of the screen capture.(This is similar to
references for checkpoints and sync keywords, but more on those will come in later posts)
And this is the reason we cant modify the steps recorded by Analog method.

Till you I believe you might have noticed that isn't very good technique for scripting as ,in real word 
scenarios You will need to modify the recorded step to a certain extent which is impossible in this 
approach. So advise is to use this   approach for very elementary steps(to capture a couple of basic
operation provided Normal mode is not working for that screen.) and continue rest of the code 
through normal mode.

Hope this Helped....

Please comment for any queries/suggestions regarding the above posts.

QTP Basics Part2: Recording modes:Normal Mode

One of major features of QTP is the ability to record the user's action and play those actions/modified actions back.
Now there are more then one recording mode available in QTP.

1 Normal  Mode
2 Analog Mode
3 Low Level Mode

Now I am going to discuss each of these in detail one by one.

Normal Mode: Record/Playback is one of basic functionality in QTP, and  similarly  Normal mode is the most basic normal mode in QTP.
for normal recording , user need to click on red button as shown in below snapshot.

This mode is the default recording mode of QTP.This mode uses fully the advantage of QTP's Object Test Model.
But again here comes some drawbacks too along with the simplicity of the normal mode.

Actually, when we use the normal mode the complete hihierarchy of the complete Object tree .Which makes the OR unnecessarily bulky.So instead of using this recording mode( as matter of fact we don't prefer using any of the recording modes), we manually add the objects.

Monday, 26 August 2013

Understanding Descriptive Programming: Part 2

Continuing from... Understanding Descriptive Programming: Part 1
Now till this moment I expect reader are aware of the Objects and how the object are stored in OR(Object Repositories). Now it is time to come to real point.
Till now we were referring the Object by indicating the QTP that the definition of the particular object is stored in OR  
Idea Behind DP: The basic idea behind DP is to access Object without referring to OR.

How to implement: To implement such feature we describe the properties with which the object can be defined within the code instead of storing those in ORs.

Where to use DP/Why not Object Repositories: It can be used to perform operation on the objects which aren't stored in OR or to perform operation on the object whose properties matches a set of description properties which we can determine at run time.

Ways to implement DP  : DP can be implemented by two way. Static and Dynamic Descriptive Programing.

Static Descriptive Programing: In this type of DP, we mention the description properties within
 the Vb Script statement.


Please notice we have used ":=" instead of usual "=".
This is the General Syntax.Please notice that each "property:=value" must be separated by comma.

Below is a sample Vb Script statement which uses static DP, and a practical use of the static DP

Browser("BrowserName").Page("PageName").Webtable("TableNAme").Webedit("name:="&MyVar).Set "SampleText"

Now please notice that in above statement we have used a variable Myvar for sting. *a very imporatant thing in static DP is that u cant have static DP object in middle of OR based statment.Means
Browser("BrowserName").Page("PageName").Webtable("TableNAme").Webedit("name:=Submit").Set "SampleText"
is prefectly valid syntax , but we cant use
Browser("BrowserName").Page("PageName").Webtable("htmlid:=inventroyform").Webedit("Submit").Set "SampleText"
is an invalid syntax, as we cant get reference for the Submit button from DP based object as it is expecting OR based reference.
I will be discussing on dynamic DP in later posts

How to use Increment/Decrement Operator feature in QTP using VBScript

Hi friends, I have been involved with Software Testing and QTP automation for almost 3 years , and I have noticed that in Vb scripting we don't use increment and decrement operator.

We don't have any language support form VB Script itself for increment/decrement operator.It means we cant use below

msgbox i++

we need to do i=i+1 and sometime when writing long chunk of modules this lack of feature is quite trouble some.
For this we can implement feature by using OOPS architecture.

1. Create a new .qfl file (A New function Library) .you can use the existing qfl too, but i recommend to use a new qfl for all CLASS related code.(We say the file name as modifiedOperator.qfl)

2. Now We will create a new Class which will support the this feature, add the below code in your .QFL file.

Class GenericNumber

 Private numberValue

 //Below function will handle the code for PreIncrement function
 Public function [++]()
 End Function

 //Below function will handle the code for Predecrement function
 Public function [--]()
 End Function

 Public default property get result()
 End Property

 Public property let result(n)
 End Property

 Sub Class_Initialize()
 End Sub

End Class

Now the Above mentioned code will handle the operation for PreIncrement/Predecrement Operations. now we need to implement a constructor like operations so that we can actually use this class

Function [customOperation](x)
   Set [customOperation]=New GenericNumber
   If isnumeric(n) Then
   End If
End Function
The Function [customOperation] actually enable the user to use the Class we used now store both class and Function customOperation in modifiedOperator.qfl file Step 2. Now we are goin to use the code we written into our tests/programes.Please remember that we need to include the qfl file into your test ,Application area to use this feature now instead of using a normal integer variable we use a GenericNumber type variable.(We make an object of class GenericNumber for which we use the function customOperation . ) this functions returns the object of the class GenericNumber
// the variable num will hold the a object of type GenericNumber  with value as 5
Set  num=[As Num](5)

msgbox num.[++]
//We use .[++] instead of ++ as was in c/c++ languages.

//now run this code and the answer will be 6 
msgbox num.[--]
//now run this code and the answer will be 5

I hope this helped.

Sunday, 25 August 2013

Understanding Descriptive Programming: Part 1

HI Folks..
In This Post I will be describing what is descriptive Programming in using VBScript(QTP), and define the various types of descriptive programming.

What is Descriptive Programing(DP):   Before understanding the DP, we must first know what is Object.
In QTP , Object is anything with a set of properties and methods(functions).
It can be any visual entity displayed on the screen as WebPage,Button,Dropdown(Weblist), all of these are type of Objects.(Although it is not necessary that each object should be visual too, this is done with a specific property .)
Now every object has a set of property with which it is defined, such as a WeButton named as "Submit" will have a set of propertys such as 'name', 'htmlid','innertext','outertext',etc
QTP understanding the entire given script in terms of Objects and the operation performed upon them .
Such as click on the submit button, then within the code we specfiy the object and perform the operation.

now the code might look as

Set buttonObj=Browser("sampleBrowser").page("samplePage").WebButton("Submit")


both of the statments are virtually same.

now if we are not using the DP methods then the properties of the submit button are  stored in Object repositories.and we can directly specify the name and the location of the object.The properties of the submit button are specified within the OR itself and user does not require to provide the information regarding submit button in code .(As shown in the code above).

But When we use the DP the properties through which object is described in the application(Description properties) will be specified within the code.(Without using the OR)

We will be looking deep into the DP in later parts of the Post.

QTP Basics Part1: Features and Usability of QTP

Hi folks !!!!!

In this series I am gonna describe the basics of the QTP step by step.

First I will be covering the QTP basics then I will be moving to more advanced step.

What is QTP (Quick Test Professional)?:

QTP is software testing automation tool provided by HP.
Main advantages/Reason for using QTP for automation as per below......

1.Fast test creation.(By Use of Keyword views,as well as the provision of modularity)
2.Easier maintenance.
3. Extremely powerful data validation capabilities within the tool.(features provided from the tool it self  in form of checkpoints*).
4 Smart Identification* support from tool.
5. Tool Based provision for recovery scenarios*.
6.Auto documentation*.

* Will be explained in later posts

How to use ByRef parameter calling in Vb Scripting.

Most of the time automation personnel don't use the ByRef parameter functionality.
They use normal function calling with which is by default byVal.

Now actually most of the time tester don't know these two first I m gonna explain there two one by one.

1.ByVal Function calling.



Function ADD(val1,val2)


End Function

Function ADD(ByVal val1,ByVal val2)


End Function

now in this case the parameter calling is ByVal.In fact both of the statements are identical.

when we byval prefix , it means only a copy of the parameter is going within the function.Any Changes made within  the parameter wont reflect the in the actual called value.
but if we use below syntax

Function ADD(ByRef val1,val2)


End Function

in this case any changes made in val1 will reflect in parameter1 too.

QTP Tutorial

Hi Folks  a page is getting launched , which will be dedicated to QTP Tutorials
This is collect step by step process to learn QTP Automation, within BPT Framework.

A New Page Dedicated to DataBase Testing

Hi Folks this is a page which will be dedicated to Database Testing

A New Page Dedicated to HP-Quality Center

Hi Folks this is a page which will be dedicated to HP-Quality Center .
We will discuss about HP-QC/HP-ALM along with HP OTA related topics here

Function Calling In VB Scripting, use of parenthesis

In VB scripting we notice two type function call syntex as per below

Object.func1 parm1,param2


Now the question is what is difference between these two syntax.The answer is quite simple , it depends on the context . NO matter what the function is , if you are going to assign the return value to some variable or the result of the function call is used as input for some other function then the function should have the parameters in parenthesis.

msgbox "Hi"
msgbox trim(" Hi ")