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.



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

sampleString="softwareTestingPerfection"
 
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

outputString="noitcefrePgnitseTerawtfos"

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.

sampleString="softwareTestingPerfection"

strlen= len(samplestring)
outputString=""
For i=1 to strlen
   outputString=mid(sampleString,i,1)&outputString
Next
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.

sampleObject("Property1:=Value1",.......,"PropertyN:=Value")

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

MyVar="Submit"
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