Monday, June 29, 2015

Regular Expression

.(dot)* ---- this will help you find any character.

Ex: Page("title:=.*")....

It will retrieve page with any title.



- Other way is by creating object, as we do in VBscripting(macro)

Source: http://uftquestions.blogspot.com/2014/04/qtp-uft-how-to-use-regular-expressions.html

How to use regular expression - code please to find a some sting in a large string
Regular expressions are very handy with Scripting and can be used in multiple ways. I would like to present once scenario on its usage.

Syntax
inputstring = "This Blog helps you with learn and test your skills on UFT"
Set o1 = new RegExp
o1.pattern = "learn"
o1.ignorecase = true
o1.global = true
Set r1 = o1.execute(inputstring)

For Each Match in r1
  Flag =1
  str = str & Match.firstindex & " - "
 Next
If Flag =1 Then
 msgbox "match found at locations " & str
End If

GetROProperty and SetTOProperty


-          Objects are of two types:

1.       Test Objects

2.       Rum time objects

Note: RO in getROProperty is Runtime Object.
 
GetROProperty and SetTOProperty -- is to get all the property values of a object. Like the properties that you see in the Object Repository.

 GetROProperty and SetTOProperty --- to get and set properties of the objects during run time.

Best example to describe about this two methods is while using Calculator.

 

 Browser(“<name>”).Page(“<name>”).WebButton(“<name>”).GetROProperty(“<property name>”) – will return property value of the webutton

Browser(“<name>”).Page(“<name>”).WebButton(“<name>”).SetROProperty(“<Property name”>,”2”) --- will set one of the property value of the button to 2.

 

-           Write a script to evaluate following expression using calculator:
<Not solved>
 

7*21

Why do we get General error in QTP and how to find root cause to fix it.

'learnqtp.com

If you have worked on QTP for some time you might have encountered errors like “General Run Error” which does not give any details regarding the error and testers often resort to using hit-and-try method to get the problem solved.

Instead, you can write a simple command to get the error number using err object. Just include this piece of code after the line where error occurred.

msgbox Err.Number
This will throw the number code of the error. Now in all probability this error would not be documented in QTP’s help VB Script Run time Error Reference. (Otherwise QTP would not have thrown it “General”) Simply Google this error code and you can get the details and possibly how to resolve it.

 

Sunday, June 28, 2015

Descriptive Programming


- WebEx training notes:
Descriptive Programming: Helps you to manipulate objects without use of Object Repository.

Major dis adv --- will need to add everything in the code.

Advantage - Performance will be high.
Two ways of writing Descriptive programming:

1. Descriptive Strings
2. Descriptive Objects

or
1. Static (Strings)
2. Dynamic (Objects)

Descriptive Strings:

Browser("<propertyname1>:=<name>", "<propertyname2>:=<name>").Page("<propertyname1>:=<name>","<propertyname2>:=<name>").Web......

Descriptive Objects:

set browobj = Description.Create

browobj("<propertyname1>").value="<name>"
browobj(<propertyname2>").value="<name>"
....

Set pageobj = Description.Create

pageobj("<propertyname1>").value="<name>"
pageobj("<propertyname2?").value="<name>"
..

Set webelementobj = Description.Create

webelementobj("<propertyname1>").value ="<name>"
webelementobj("<propertyname2>").value ="<name>"
...

Browser(browobj).Page(webelementobj).WebElement(webelementobj).....

'*************************************************************


What is micClass?  --- Not Solved

set obj1 = Browser(browobj).Page(webelementobj).ChildObjects(webelementobj)

obj1.Count '-- this gives the number of webelementobjects under that page

So it saves lot of your time, going to each and every object we can just use childobject method.

And each element could be accessed as below:

For i =0 to obj1.Count-1
obj1(i).set "<value>"    '----sets value to the each of the webelement in a web page.
Next










-
Why to use Descriptive Programming:
Source: http://www.qtpschool.com/2014/09/why-use-descriptive-programming-dp-in.html


Scenario 1. - you need to count how many search result are returned when you search a particular search criteria. For example, you want to see how many 
qtp/selenium/agile/java jobs are posted on a job portal in last 2 days! you then want to select all and apply.

Because you dont know in advance how many checkboxs will be there on search result, you cant use object repository.

Using DP (childobject), you can easily handle this scenario.

Scenario 2. - you are working on automation of an application where latest code is not deployed yet. To use OR, you must wait untill application is up and running. But if know the object descriptions, you can continue to create you automation scripts using DP.

Scenario 3. - your application is having 10 pages and every page has 2 same button i.e. "Previous Page" and "Next Page". So if use OR, it will add 2 objects for each page i.e. total 20 object for 10 pages. Instead of having 20 duplicate objects and making our OR unnecessarily 'bulky, we can simply write 2 DP objects.

Scenario 4. - Descriptive Programming is very useful for tricky objects like blotter grids, auto-hiding menus and embeded/nested objects and advanced string manipulations.

Scenario 5. - It might not sound a great example but suppose your qtp server is crashed and you can not open/access qtp OR for a while (1-2 days). If you use OR, you have wait until server is back, but you can continue to work if you use DP (advanced users).

Hope above are enough reasons to answer why to use DP at all!!

Reason for seeing "Windows" ... when you record an application using QTP.

Can we record a web based application on Mozilla?
A-You can record a web based application only on Internet Explorer and run it on either IE or Mozilla. If you perform record operation on Mozilla then it will treat it as a Window or WinObject as when QTP not able to recognize the objects it records those objects either as a window or winobject.
ex: Window(“Mozilla Firefox”).WinObject(“MozillaWindowClass”).Type “naveen

Friday, June 26, 2015

Training notes


-          Share Repository file extension is  - .tsr

-          Use objects and write code. Drag objects you will be able to use the objects to write the scripts. View- >Available Keywords.

Associate Repository to the scripts. This is nothing but sharing repository.

-          Shared Repository – objects get changed, will get impacted?

-          To report each and every step in test case, do the following:

If Browser("Browser").Page("Page").WebEdit("lastname").Exist(2) Then

Reporter.ReportEvent micPass,"The Edit box should be displayed","The Edit box is displayed"

Else

Reporter.ReportEvent micFail,"The Edit box should be displayed","The Edit box is not isplayed"

End If

-          Create object to reuse the path

Object variable

Set Obj1 = Browser(“dsf”).Page(“dfd”)

Obj1.WebEdit(“df”).set = “Srikanth”


Here you can use the Obj1 instead of Browser……


-          Desktop.Capturebitman(“<path>”) ----provision to capture screenshot

Ex:

If (obj1.Exist(2)) then

Desktop.Capturebitman(“<path>”)

Else

Desktop.Capturebitman(“<path>”)

End if

-          Tools Options -> Run->Screen Capture ---- through this also you can save the test case screen print or video

-          Check Syntax --- Icon on the menu bar will help you fix the syntax error

-          WebTable  --- 4 Important methods are RowCount, ColumnCount, GetCellData, ChildItem

-          WebTable is used where you cannot store too many objects in objectrepository

Set obj = Browser(“a”).Page(“a”).WebTable(“Passengers”).ChildItem(“<row>”,”<col>”, WebEdit, )

Obj.


Real time: Sometimes when you try to add objects using object spy from a portal where you have to select an object which you need to dig a lot, during that process too many objects get added to the object repository. To avoid that set a obj for a webtable child, that way you need not add that object in webtable to object respository, but just add childitem to the created object.

rc = Browser("Browser").Page("Page").WebTable("Emergency Contact").RowCount

 rownum=1

     For i = 2 to rc

         cc =  Browser("Browser").Page("Page").WebTable("Emergency Contact").ColumnCount(i)

         DataTable.SetCurrentRow(rownum)

        For  j = 1 to cc

                If j =1 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebEdit",0)

                    obj.set DataTable.Value("EmergencyContact")

                End If

                  If j =2 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebEdit",0)

                    obj.set DataTable.Value("Telephone")

                End If

                        If j =3 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebList",0)

                    obj.Select "sibling"

               

                End If

        Next

        rownum =rownum+1

    Next

-          Changing the object property in runtime---- using SetToProperty(“<object>”, “<value>”)



-          'Use calculator, write a function to evaluate the following expression (Just use one object)

'71+29=


http://www.tutorialspoint.com/qtp/

-          Descripting programming is writing code without building object Repository

Browser(“name=”<name>”)).Page…..


Completely avoiding object Repository

-          Two types of Descriptive programming  -- Descriptive Objects and Descriptive Strings.


   Descriptive.Strings

Descriptive.Objects ---- Descriptive.Create



-          Descriptive.Create --- is used to create object for a web object

-           

'1. Descriptive Programming:

'1. Descriptive Strings

 Browser("title:=Sample.html").Page("name:=.*").WebEdit("name:=firstname").Set "Hello"

2. '. 2. Description Objects

Set oDesc = Description.Create()

oDesc("micClass").Value = "Browser"

oDesc("title").Value = "Sample.html"

Set pDesc = Description.Create

pDesc("micClass").Value = "Page"

pDesc("title").Value = ".*"

Set eDesc = Description.Create

eDesc("micClass").Value = "WebEdit"

eDesc("name").Value = "firstname"

 Browser(oDesc).Page(pDesc).WebEdit(eDesc).Set "GDGSGSG"


-          Finding objects on desktop like Calculator ?


CTSC0192



-          Set oDesc = Description.Create()

-oDesc("micClass").Value = "Browser"

-oDesc("title").Value = "Sample.html"

-Set pDesc = Description.Create

-pDesc("micClass").Value = "Page"

-pDesc("title").Value = ".*"

-Set eDesc = Description.Create

-eDesc("micClass").Value = "WebEdit"

-Set objColl = Browser(oDesc).Page(pDesc).ChildObjects(eDesc)

-For i = 0 to objColl.Count-1

-objColl(i).Set "Hello Programming"

-Next

-

-          Write a Program to print the number of

-1. Text boxes

-2. Radio Group

-3. Links

-4. WebElements

-5.Check Box

-2. Write a Program to select  third drop down value from all the Listboxes present in a page

-Hint:

-Browser("Browser").Page("Page").WebList("cars").Select "#1"

-          Using xml in QTP:

QTPworld.com

Load --- to load the xml

Ø  http://www.qtpworld.com/index.php?cid=86    ----- reading xml

-          Connecting to DB:


‘MS Access DB

strDBPath = "C:\Users\sarathi\Desktop\Training\Sample.accdb"   

Set ObjConnection1 = CreateObject("ADODB.Connection")

    ObjConnection1.ConnectionString = _

        "Provider=Microsoft.ACE.OLEDB.12.0;" & _

        "Data Source=" & StrDBPath & ";" & _

        "Persist Security Info=False"

    ObjConnection1.Open

    StrQuery = "SELECT * FROM Table1 ORDER BY 1 ASC"

    Set objRecordSet1 = ObjConnection1.Execute(StrQuery)

    Do Until objRecordSet1.EOF

   

        For LngField = 0 To objRecordSet1.Fields.Count - 1

            Msgbox objRecordSet1.Fields.Item(LngField).Value

         

        Next 

        objRecordSet1.MoveNext

    Loop



-          Dis adv  of Des programming – too much coding.

-          Adv of Des programming – childobjects

-          Descriptive Programming:

Ø  Static

Ø  Dynamic

-          Childobjects – To retrieve all objects present under a parent

-          Descriptive Programmin'g
'1. Static
'2. Dynamic

'Static :

'Browser("title:=Sample.html").Page("title:=.*").WebEdit("name:=firstname").Set "Hello"

'Set bdesc = Description.Create

'bdesc("micClass").Value = "Browser"
'bdesc("title").Value = "Sample.html"

'Msgbox Browser(bdesc).Exist

'Child Objects:

Set textdesc = Description.Create

textdesc("micClass").Value = "WebEdit"

set ocoll = Browser("title:=Sample.html").Page("title:=.*").ChildObjects(textdesc)


For i = 0 to ocoll.count-1

If i = 4 Then
oColl(i).Set "This is 4th text box"
End If

Next

-          Lbound() and UBound() for finding size of an array

-          Conversion functions – to connver one data type to another

-          Dim will help variables to change the its data type as per the data you feed into it.

-          LTRIM(), RTRIM(), LEN(), TRIM(), MID(), SPLIT() --- important functions

-          Description Properties

-          Disable smart identification  in object repository. Its always better to define object instead totally depend on QTP

-          Index – 0 – will select first test box

-          Save repository -> Manage repository- > Add repository -> add actions to link to use that repository

-          Resouce-> Add library to use the function library

-          Connecting MSAccess, design script. Pick the data from excel and post in MSAccess DB

-          Library function – includes – Business flow(login page) functions, Report functions, Framework related – folder creation

-          Framework – Library folder, Object repository, Results

-          Environment variables are for library functions?

-          Environment variables are declared using double quotes?

Ex: Environment. Value(“Name”) = “value1”

-          Starttime = Timer()

Lines of code

Endtime = Timer()

Total time = Endtime- Starttime

Timer - Timer returns the number of seconds from 12:00a.m. This function is very useful for evaluating time spent in performing an activity by taking timer at the start and end of the activity and subtracting the time between two.

-          Watch View ---- helps to findout the values of functions and variables during run time????

-          You can also do Add to Watch --- by right clicking on Function or variable to add to Add to watch

-          Use F11 --- while running the script this will help you to identify the functions tagged to the script

-          Click method when you used, one need not use Wait method because it automatically includes that feature?

-          For Iterator = 1 To 1 Step 1
  
Next


The Step Keyword

With the Step keyword, you can increase or decrease the counter variable by the value you specify.

In the example below, the counter variable (i) is INCREASED by two, each time the loop repeats.

For i=2 To 10 Step 2
some code
Next

To decrease the counter variable, you must use a negative Step value. You must specify an end value that is less than the start value.

In the example below, the counter variable (i) is DECREASED by two, each time the loop repeats.

For i=10 To 2 Step -2
some code
Next


-          Apparently there is no direct method to determine the length of an array in VBScript. The best way I could find is to use UBound(ArrayName). This will return the upper limit of the array. Unfortunately, it doesn’t account for empty items in the array.

-          I am unable to stop QTP script, it is running uninterruptedly even after I click the stop button.

-          Do Until i=10
some code
Loop

Monday, June 22, 2015

Desktop applicaiton access - like Calculator using QTP

6/22/15:

I was trying to connect to open the calculator and record actions ???

Solved: Generally when you record the application, go to Record -> Record and Run settings->Windows applications -> Select "Applications opened via desktop.


When you select the above option, user should be able to record the applications opened on desktop.


 

Wednesday, June 17, 2015

Difference between Action, Procedure, Function and Sub...

Difference between Action, Procedure, Function and Sub?
I believe that many QTP newbie’s are confused about Action, Procedures, Function and Subs. Am I right?

No worries! Here we are going to discuss all of them in detail to eliminate all the confusions!

In QTP, there are two ways (on broad level); we can break up the code into logical units. Logical unit is nothing but a 'Piece of code' or ‘a series of VBScript statements’, to perform specific activity in QTP. These two ways are -

1. Actions - specific to QTP
2. Procedures - vbscript provided


Okie.. but what about Functions and Subs? Wait guys! we'll come there.

We know that we use vbscript as scripting language in QTP. (To read about vbscript, Click Here>> )

VBScript has two kinds of procedures: Sub procedure and Function procedure

So, in brief, its goes like this..

1. Actions
2. Procedures
2.1. Subs/Subroutine
2.2. Function

Now we know that Action and Procedures are the two things. Procedure is further devided in two types - Function & Sub.

Feeling batter? Great!!

So, Lets start with actions..

1. QTP Actions:-

Action is specific to QTP and not the part of vbscript. Every QTP test has at least one Action(default name is Action1).
Action can have an object repository associated with it. Action can return multiple values in form of 'output parameters'.

2. Procedures:
2.1. VBScript Sub Procedures:-

A Sub procedure:

  • is a series of statements, enclosed by the Sub and End Sub statements
  • can perform actions, but does not return a value
  • can take arguments
  • without arguments, it must include an empty set of parentheses ()

Sub mysub()
Print "my Sub Procedude"
End Sub

or

Sub mysub(argument1,argument2)
Print "my Sub Procedure"
End Sub

How to call Sub Procedures:

To call a Sub, you will use Call statement by enclosing arguments (if any) in parentheses.


The Call statement is not necessary to call a Sub, but if you want to use Call statement (Recommended), you must enclose arguments (if any) in parentheses.

Call mysub(argument1,argument2)

You can call a Sub without using Call statement as well, but not recommended.

mysub argument1,argument2


2.2. VBScript Function Procedures:-

A Function procedure:

  • is a series of statements, enclosed by the Function and End Function statements
  • can perform operations and can return a value
  • can take arguments that are passed to it by a calling procedure
  • without arguments, must include an empty set of parentheses ()
  • returns a value by assigning a value to function name itself

Function myfunction1()
Print "my fuction1"
End Function

or

Function myfunction2(a,b)
myfunction2=a+b 'assign value to function name
End Function


How to call Function Procedures:

Call myfunction1() 'calling 1st function, without any return value

abc=myfunction2(argument1,argument2) 'calling 2nd function, with a return value

Here you call a Function called "myfunction2", the Function returns a value that will be stored in the variable "abc".

Monday, June 8, 2015

Addins, Patches and Extensions


Add-in:


QTP supports various applications. But it won't support all the applications by default. We need to load the corresponding add-in.

For example, if you are going to use QTP for a java application  you need to load java add-in.

This add-in concept will help QTP to support wide-range of applications without compromising the performance. And, it will improve object identification reliability.


Default Support
  1. Standard Windows applications (invisible in the add-in manager)
  2. Web objects / Applications
  3. ActiveX controls
  4. Visual Basic applications
 
In the previous versions, below add-ins should be loaded separately. 

  Additional QuickTest add-ins Support
  1. Java
  2. Oracle
  3. SAP
  4. .NET
  5. Web Forms
  6. Siebel
  7. PeopleSoft
  8. Web services
  9 Main frame (Terminal Emulator)

You can select the required Add-ins while starting the QTP.

Note: Need to download IE Addin when worked with QTP and IE 9.0 version.

 Patch:

 Patch (computing), a piece of software designed to fix or improve a computer program or its supporting data

Extensions:


  • Software extension, a file containing programming that serves to extend the capabilities of or data available to a more basic program  Note: Have come across extensions when i was working with Mozilla with QTP.