Showing posts with label QTPTutorial. Show all posts
Showing posts with label QTPTutorial. Show all posts

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
Instr(str1,str2)..
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"
str2="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"
str2="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"
str2="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 .

str1="Hello"

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

str1="Hello" 
str2=mid(str1,2,1) 
msgbox str2

Output: e 
Now in this statement
mid(str1,2,1) 
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

Ary(0)=15

Ary(1)=50


and in same manner it can be retrieved too.
var1=Ary(1)
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)
DynamicAry(0)=12
Redim Preserve DynamicAry(1)
DynamicAry(1)=13
msgbox DynamicAry(0)
msgbox DynamicAry(1)



:Output

12

13



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.



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.











Sunday, 25 August 2013

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

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.