Saturday, August 23, 2014

10 best paying jobs at Google, Keep your fingers Crossed


10. Director of Marketing 
9. Global Creative Director  

8. Director, Product Management
7. Finance Director 

6. Senior Director, Talent Management

5. Director, Global Partnership
4. Senior Director, Product Management

3. Director of Engineering
2. Director of Operations

1. Senior Vice President

Thursday, August 21, 2014

Start An Open Source Project Now



You have a problem. You've weighed the pros and cons of open sourcing your code, and you know you need to start an open-source project for your software. But you have no idea how to do this.
Oh, sure. You may know how to set up a GitHub account and get started, but such mechanics are actually the easy part of open source. The hard part is making anyone care enough to use or contribute to your project.

Here are some principles to guide you in building and releasing code that others will care about.

First, The Basics

You may choose to open source code for a variety of reasons. Perhaps you're looking to engage a community to help write your code. Perhaps, like Known, you see "open source distribution ... as a multiplier for the small teams of developers writing the code in-house." 
Or maybe you just think it's the right thing to do, as the UK government believes. 
Regardless of the reason, this isn't about you. Not really. For open source to succeed, much of the planning has to be about those who will use the software. As I wrote in 2005, if you "want lots of people to contribute (bug fixes, extensions, etc.," then you need to "write good documentation, use an accessible programming language ... [and] have a modular framework." 
Oh, and you also need to be writing software that people care about. 
Think about the technology you depend on every day: operating systems, web application frameworks, databases, and so on. These are far more likely to generate outside interest and contributions than a niche technology for a particular industry like aviation. The broader the application of the technology, the more likely you are to find willing contributors and/or users.

In summary, any successful open-source project needs these things:
1. Optimal market timing (solving a real need in the market);
2. A strong, inclusive team of developers and non-developers; 
3. An architecture of participation (more on that below);
4. Modular code to make it easier for new contributors to find a discrete chunk of the program to work on, rather than forcing them to scale an Everest of monolithic code;
5. Code that is broadly applicable (or a way to reach the narrower population more niche-y code appeals to);
6. Great initial source code (if you put garbage into GitHub, you'll get garbage out);
7. A permissive license—I personally prefer Apache-style licensing as it introduces the lowest barriers to developer adoption, but many successful projects (like Linux and MySQL) have used GPL licensing to great effect.
Of the items above, it's sometimes hardest for projects to actively invite participation. That's usually because this is less about code and more about people.

"Open" Is More Than A License

One of the best things I've read in years on this subject comes from Vitorio Miliano (@vitor_io), a user experience and interaction designer from Austin, Texas. Miliano points out that anyone who doesn't already work on your project is a "layperson," in the sense that no matter their level of technical competence, they know little about your code.
So your job, he argues, is to make it easy to get involved in contributing to your code base. While he focuses on how to involve non-programmers in open-source projects, he identifies a few things project leads need to do to effectively involve anyone—technical or non-technical—in open source:
1. a way to understand the value of your project 
2. a way to understand the value they could provide to the project
3. a way to understand the value they could receive from contributing to the project
4. a way to understand the contribution process, end-to-end
5. a contribution mechanism suitable for their existing workflows
Too often, project leads want to focus on the fifth step without providing an easy path to understand items 1 through 4. "How" to contribute doesn't matter very much if would-be contributors don't appreciate the "why."

On that note, it's critical, Miliano writes, to establish the value of the project with a "jargon-free description" so as to "demonstrate your accessibility and inclusiveness by writing your descriptions to be useful to everyone at all times." This has the added benefit, he avers, of signaling that documentation and other code-related content will be similarly clear.
On the second item, programmers and non-programmers alike need to be able to see exactly what you'd like from them, and then they need to be recognized for their contributions. Sometimes,  "A smart person [may] come[] by with great code, but project members fail to understand it." That's not a terrible problem if the "in" group acknowledges the contribution and reaches out to understand. 
But that doesn't always happen.

Do You Really Want To Lead An Open Source Project?

Too many open-source project leads advertise inclusiveness but then are anything but inclusive. If you don't want people contributing code, don't pretend to be open source. 
Yes, this is sometimes a function of newbie fatigue. As one developer wrote recently on HackerNews, 
Small projects get lots of, well, basically useless people who need tons of handholding to get anything accomplished. I see the upside for them, but I don't see the upside for me: if I where[sic] to help them out, I'd spend my limited available time on handholding people who apparently managed to get ms degrees in cs without being able to code instead of doing what I enjoy. So I ignore them.
While that may be a good way to maintain sanity, the attitude doesn't bode well for a project if it's widely shared. 

And if you really couldn't care less about non-programmers contributing design input, or documentation, or whatever, then make that clear. Again, if this is the case, you really shouldn't be an open-source project. 
Of course, the perception of exclusion is not always reality. As Active State vice president Bernard Golden told me over IM, "many would-be developers are intimidated by the perception of an existing 'in-crowd' dev group, even though it may not really be true." 
Still, the more open source projects invest in making it easy to understand why developers should contribute, and make it inviting to do so, the how largely takes care of itself.

Wednesday, August 13, 2014

Learn QTP Automation Testing by Amit



Quick Test Professional Notes
 
Automation:
Simulation of any human work by a system or a tool with minimal intervention is called ~.

NOTE:
100% automation is not possible. E.g.  mixer grinder, fan, etc…

Advantages:
1.)    Faster, saves time.
2.)    Reusable & repeatable.
3.)    Saves time & reduces human effort.
4.)    Accurate, which improves quality. E.g. soldering of PCB board, lathe machine, etc.

Disadvantages:
1.)    Initial investment is very high.
2.)    Requires more skilled resources.
3.)    Requires constant maintenance.
Latest version of QTP is QTP11, but we use QTP10. (Linux & UNIX not supported)

Installing QTP:
Pre-requisites:
1.)    O.S ► XP,Vista, Windows7
2.)    RAM ► Minimum 1GB
3.)    Browser ► IE6,7,8(IE9 not supported)
4.)    HDD Space ► Minimum 1GB in C:\ drive
5.)    Microsoft Script Debugger
6.)    VC++
7.)    .Net Framework
Procedure:
1.)    Double click
2.)    Click
3.)    Restart
4.)    After
5.)    For Windows 7
6.)    After installation


The QTP main Window has following Sections:
1.)    Menu bar where we can access all the features of QTP.
2.)    Tool bar where we can access frequently used features of QTP.
3.)    Editor window where we write/edit the code, which has two tabs:
Keyword view & Expert view.
4.)    Optional window these are the additional features of QTP such as test flow, data table etc…

Definition: QTP is a GUI functionality testing Automation Tool; it’s a software which is used to simulate the verification of GUI objects.

Record & Playback in QTP:
Step1: open QTP
Step2: goto>automation>select record(F3)
Step3: perform operation
Step4: goto>automation>select stop(F4)
Step5: goto>file>select save(Ctrl+S)
Step6: goto>automation>select run(F5)

NOTE:
1.)    QTP Test is always saved as folder.
2.)    If QTP is not recording any operation then goto automation, select record & run settings, goto windows application tab select the first radio button,(record & run test on any open windows based app), then click OK.
3.)    While recording the QTP script ensure that proper window of the application is opened & it is not minimized.

Keyword View:
In ~ QTP displays the recorded script in table format as shown below:
Item
Operation
Value
Documentation
Login


Activate




Makes “Login” dialog box active
Agent Name
Set
“admin”
Enter “admin” in the “agentname” edit box
where,
·         Item represents GUI object.
·         Operation represents the action performed.
·         Value represents the input.
·         Documentation is the auto generated step description.

Expert View:
In ~ script will be displayed as statements.
E.g.
1:         Dialog(“Login”).Activate
2:         Dialog(“Login”).WinEdit(“AgentName:”).Set “admin”
3:


Data flow diagram of flight reservation:
Q.) How do you invoke the application using QTP?
A.)We use       Systemutil.run statement to launch the application.
Systemutil.run “C:\program files\hp\qtp…”
Systemutil.run “calc”
Q.) WAS to invoke cmd prompt using QTP?
Systemutil.run “cmd”
Q.) WAS to launch Gmail in default browser?
Systemutil.run “www.gmail.com
Q.) WAS to open Google in IE?
Systemutil.run “iexplore”, “www.google.com

Object identification:
In order to perform operation on the GUI object, first QTP has to identify the object uniquely for this QTP uses property values of the object.

NOTE:
Each object has multiple property value, storing all of them will not only consume space, but also reduces QTP performance, in order to overcome this QTP stores minimum property value in a database called object repository. By following object identification setting which is available under tools menu of QTP.
The object identification has three different sections:
1)      Mandatory properties.
2)      Assistive properties.
3)      Ordinal identifier.
During recording QTP will go to mandatory section and reads all the mandatory properties value from the objects. Then it checks whether it is sufficient or not, if sufficient it will be stored in object repository, if it is not sufficient then it goes to assistive properties one by one.

NOTE:
Sufficient in the sense that no other object has the same properties value in the same screen or windows.

NOTE:
If assistive values are also not sufficient then QTP goes to ordinal identifier.

Ordinal identifier location:
>It’s a sequential no. (“0, 1, 2…etc”) generated by QTP based on order in which the object appears on the application.
>This is given only to number in which we have confusion. When mandatory & assistive properties are not sufficient, then we go for ordinal identifier. This is generated by QTP and not by developer. It scans from left corner, whichever comes first it gives 0 & after that 1.

Object spy:
>It shows all property developed by developer of any button which we want to see. It is under the tool menu.
>We can’t see the ordinal identifier properties in it because it is created by QTP itself.

NOTE:
1)      QTP goes to ordinal identifier only if mandatory & assistive property value is not sufficient.
2)      Ordinal identifier values are generated by QTP and not given by developer; hence it will not be displayed in object spy tool.
3)      QTP will start the scanning from the left top corner of the application. It will scan every column from left to right pixel by pixel & generate the number only for the object which is having same mandatory & assistive property value.
4)      While adding the object to object repository QTP will completely scan the application & generate location value for all the object which is having same mandatory & assistive property values. But it will store only the corresponding location value of the object which we are trying to add.
In the above example if we try to add last OK button then QTP will scan the entire screen & generate the location value 0, 1, 2 for 1st, 2nd & last OK button & then it will store the location value of last OK button that is 2.
5)      Ordinal identifier values are generated by QTP twice one is during recording & another one is during run time.


Web application example for location:

        i.            Open the notepad, write the following code save it as mypage.html on the desktop, then close the notepad.                                                                                                                        
<html>
<body>
<input type=text name=a>
<input type=text name=a>
<input type=text name=a>
<input type=text name=a>
</body>
</html>
     
      ii.            Open QTP go to tools ,select object identification, then select environment as web, select web edit under test object classes.
    iii.            Uncheck “enable smart identification” check box, change the “ordinal identifier” to location then click OK.
    iv.            Open above created mypage.html in the internet explorer & maximize it so that textbox will be aligned horizontally.
      v.            Switch to the recording mode & enter a, b, c, d in to the text boxes & stop the recording.
    vi.            For the above operation QTP generates the following code.
With Browser("Browser").Page("Page")
            .WebEdit("a").Set "a"
            .WebEdit("a_2").Set "b"
            .WebEdit("a_3").Set "c"
            .WebEdit("a_4").Set "d"
End With

NOTE:
Use (CTRL+W) to apply the With statement &
Use (CTRL+SHIFT+W) to remove the With Statement.
  vii.            Resize the browser & run the above QTP script.
E.g.
Recording:







Running:










Q.) Which one is better either X & Y or location?
A.) Location is always better than X & Y coordinates because if there is a change in the pixel then QTP cannot identify the object with X & Y (“it requires exact match”) but it works with location (because it is relative position)

NOTE:
If we have X & Y properties in mandatory or assistive then QTP will go to ordinal identifier (“except for overlapping objects”)

Ordinal identifier-index:
It is the sequential number generated by QTP based on order in which the object appears in the source code or memory.
E.g.
Open QTP test, go to tools, object identification select environment as web, then select webedit, change the ordinal identifier back to index, then click OK. Switch to recording mode, enter a, b, c, d in to the text boxes present in mypage.html, stop the recording resize the browser & run the QTP script.
Recording:





Running:






NOTE:
In above example QTP will enter a, b, c, d in the same text boxes irrespective of their physical location.

NOTE:
Default ordinal identifier for most of the windows based objects is location & for most of the web objects the default ordinal identifier is index.

NOTE:
Only “browser” object has creation time ordinal identifier in addition to location & index.
Creation time is the sequential number (“0, 1, 2…etc”) generated by QTP based on the time in which the respective browser is invoked.
Q.) How QTP identifies two send buttons present in Gmail compose page?
A.) QTP will identify the send buttons present on the Gmail with send  &  send_2 as logical name which are having 0 & 1 as their respective index value.
E.g.
With Browser(“gmail”).Page(“gmail”)
            .WebButton(“send”).Click
            .WebButton(“send_2).Click
End With

Dialog(“login”).Activate
                                                                                               
                                                                                Application                     
login
                                                                             
Desc Property
Text:=login
                          Object Repository
Login
           
                                                                       


   In the above example dialog is a QTP object which represent GUI object type which is called as test object.
   “Login” is the logical name generated by QTP which is used only to retrieve the property values stored in object repository.
   Activate is the operation which is to be performed on the specified object, it is called as method.
   Logical name in the script should be same as the logical name & object repository or else we get a “object not found in object repository” error.
   Description properties present in object repository should be same as the property value in the application or else we get “cannot identify the object” error.
Q.) What is object spy? Can we use it to find the index value?
A.) It is a tool available in QTP which is used to view all the property values of the required object, which are given by the developer.
Since ordinal identifier values are given by QTP & not by developer we cannot use the ‘object spy’ to find the value of any ordinal identifier.
Q.) What is Add-in?
A.) It is the additional software used by QTP to identify the GUI object which are developed using specific technology.

NOTE:
When we install the add-in we will get list of test objects along with their object identification setting.
Q.) What are build-in or default add-in available in QTP?
A.)  i) Standard windows.
      ii) ActiveX
     iii) Visual Basic
     iv) Web

NOTE:
Standard windows is not listed in add-in manager window, hence it is also called as “transparent add-in” which is used to identify the object which are developed using VC++.
Q.) Is VB add-in required to write VB scripting in QTP?
A.) No, VB add-in is required only when the application under test (AUT) is developed using VB programming.
Q.) What the other technology supported by QTP?
A.) Delphi, java, .net, oracle(for oracle app), people-soft, power-builder, SAP, Siebel, stingray, terminal emulator(for mainframe), visual-age, flex, silver-light, windows mobile, android etc…




Adding Multiple Objects to Object Repository:
1.)    Open object repository (Ctrl+R), click add objects then click on the parent object (such as window or browser).
2.)    Click OK on object selection.
3.)    Select all object types in ‘define object filter’ & click OK
Q.) What is statement completion?
A.) In expert view of QTP, if we type starting few letters of the statement(e.g. Di) & press Ctrl+Space, then QTP will automatically complete the statement(e.g. Dialog).This is called as ~.

NOTE:
To use ~ ensure that the required objects are added to ‘object repository’ & ensure that statement completion option is selected, which is available under Tools->view options.
Eg. Login code for flight reservation application
With Dialog("Login")
.winedit("Agent Name:").set "admin"
.winedit("Password:").set "mercury"
.winbutton("OK").click
End With
‘Test Objects: Dialog,winedit,winbutton
‘Local Names: Login, Agent Name:, Password:, OK
‘Methods: Set, click
‘Method Argument: “admin”, “mercury”
*We can use Ctrl+M to comment multiple lines & we can use Ctrl+Shift+M to uncomment multiple lines in QTP.

Sample QTP code for Web Application:
With Browser(“Browser”).Page(“Page”)
.webedit(“editbox”).set “text”
.webcheckbox(“checkbox1”).set “ON”
.webcheckbox(“checkbox1”).set “OFF”
.link(“link”).click
.image(“image”).click
.webbutton(“button”).click
.weblist(“list”).select “ItemName”                             ‘case sensitive
.weblist(“list”).select 0                                                ‘numeric index
.weblist(“list”).select “#0”                                          ‘hash index
.webradiogroup(“RadioGroup”).select “value1”        ‘case sensitive
.webradiogroup(“RadioGroup”).select “#0”
End With
‘NOTE: QTP selects the radio button based on its value & not based on its label, to find value of ‘radio button get “all items” using object spy.

QTP script to Login into ActiTime:
With Browser(“actiTIME – Login”).Page(“actiTIME – Login”)
.webedit(“Username”).set “admin”
.webedit(“Password”).set “manager”
.webbutton(“Login”).click
Q.) Write a QTP script to create ‘project1’ for customer1 in ActiTIME application.
A.) With Browser(“actiTIME-Add New Project”).Page(“actiTIME-Add New Project”)
.Weblist(“Customer”).select “Customer1”
.Webedit(“ProjectName”).set “Project1”
.Webedit(“Project Desc”).set “Description1”
.WebRadioGroup(“RadioGroup”).select “#1”
.WebButton(“Create Project”).click
End With
Q.) What is the difference between normal & fast run mode.
Normal
Fast
1.) Execution marker is displayed.
1.) Not displayed.
2.) We can specify the step delay(milli-sec)
2.) We cannot.
3.) MS Script debugger is required.
3.) Not required.


NOTE:
The above options are available under Tools->Options->Run->Run mode.

Dynamic Object:
The objects whose property values are changing during runtime are called as dynamic objects.
E.g. Fax Order Dialog, inbox link, Gmail subject link, email-id link etc.
*Handling Dynamic objects using object repository is very tedious, which drastically increases the maintenance, in order to overcome this limitation we write a script without using object repository which is called as Descriptive Programming.
E.g. If we write a script to check 10 mails & delete it in Gmail & if the same script we run for next time where inbox has 20 mails then script will not delete all the 20 mails.
Or if we run the same script where inbox has only 5 mails then script will check 5 checkboxes & it will throw the error for 6th checkbox.
In the above example number of checkboxes itself is keep changing, using object repository in this scenario is also very difficult.

Descriptive Programming:
The process of specifying description properties of the object in the program itself is called as Descriptive Programming.
E.g. Dialog(“text:=Login”).Activate

NOTE:
Since we are ‘hard coding’ the property values it is called as Static Descriptive Programming.
We can also write Descriptive Programming using descriptions objects as shown below which is called as “Object Oriented Descriptive Programming”.
E.g. Set a=Description.Create
       a(“text”).value=”Login”
       Dialog(a).Activate
Q.) WAS to close the middle calculator(it can also be a notepad or browser) out of the three which are opened on desktop.
Window(“text:=calculator”,” Location:=1”).close
Q.) WAS to activate the 5 notepads present on the desktop one by one in reverse order.
For i=4 to 0 step -1
Window(“nativeclass:=Notepad”, “Location:=”&i).Activate
Next
Q.) WAS to close all the five notepads present on the desktop in diagonal order from top to bottom.
For i=1 to 5
Window(“nativeclass:=Notepad”,”Location:=0”).close
Next
Q.) WAS to close all the five notepad present on the desktop diagonally from bottom to top.
For i=4 to 0 step -1
Window(“nativeclass:=Notepad”, “Location:=”&i).close
Next
Q.) WAS to close all the notepads opened on the desktop.
Do While Window(“nativeclass:=Notepad”, “Location:=0”).Exist(1)
Window(“nativeclass:=Notepad”, “Location:=0”).close
Loop
‘Note: if notepad exists it returns TRUE or else it returns FALSE
Q.) WAS to close all the browsers opened on the desktop.

NOTE:
If we use Descriptive Programming for parent object then we cannot use object repository for child object.
E.g.
‘Invalid
Dialog(“text:=Login”).WinButton(“OK”).click ‘DP->OR
‘Valid
Dialog(“Login”).WinButton(“OK”).click ‘OR->OR
Dialog(“text:=Login”).WinButton(“text:=OK”).click ‘DP->DP
Dialog(“Login”).WinButton(“text:=OK”).click ‘OR->DP
Q.) WA QTP Script to handle Fax Order Dialog for different orders.
For i=1 to 5
Window(“FR”).WinMenu(“Menu”).Select “File;OpenOrder…”
Window(“FR”).Dialog(“OpenOrder”).WincheckBox(“OrderNo”).set “ON”
Window(“FR”).Dialog(“OpenOrder”).Winedit(“Edit”).set i
Window(“FR”).Dialog(“OpenOrder”).WinButton(“OK”).click
Window(“FR”).WinMenu(“Menu”).select “File;FaxOrder…”
Window(“FR”).Dialog(“text:=FaxOrderNo. ”&i).close
Next
Q.) WA descriptive progg code to Login into ActiTIME application.
With Browser(“title:=actiTIME-Login”).Page(“title:=actiTIME-Login”)
.WebEdit(“name:=username”).set “admin”
.WebEdit(“name:=pwd”).set “manager”
.WebButton(“name:=Login now”).click
End With
Q.) WA descriptive progg code to create a project in ActiTIME application.
With Browser(“name:=actiTIME_Add New Project”).Page(“title:=actiTIME_Add New Project”)
.WebList(“name:=CustomerID”).select “customer1”
.WebList(“name:=name”).set “Project1”
.WebRadioGroup(“name:=afterCreateAction”).Select “#1”
.WebButton(“name:=CreateProject”).click
End With
Q.) What is Regular Expression?
A.) It is a combination of wild cards & characters which is used for pattern matching.

NOTE:
In QTP, we use “.*” to identify dynamic object, which means any character any number of times.
E.g. Window(“FR”).Dialog(“text:=FaxOrderNo.*).close
Q.) WAS to click to click on “inbox” link present in Gmail?
Browser(“name:=gmail”).Page(“title:=gmail”).Link(“name:=Inbox.*).click
Q.) WAS to logout from any ActiTIME page.
Browser(“name:=actiTIME.*”).Page(“title:=actiTIME.*”).Image(“alt:=Logout”).click
‘Use of .* -> code will be generic(reusable) & it also reduces length.

NOTE:
We can use Regular Expression only for property value & not for property name.
Q.) When we can’t use Regular Expression?(Limitations)
A.) If there are multiple objects which are having similar property values displayed on the application at the same time then we can’t use R.E, because QTP can perform the operation only when it identifies the object uniquely, so if more than one object is matching with the specified R.E then QTP will display the following error message:
E.g.
For Inbox link we can use R.E because it is only one link but its property value is changing.
For checkboxes present in Gmail we can’t use R.E. If we have multiple objects then we go for dynamic descriptive programming.

Handling Multiple Objects using dynamic descriptive programming:
Child Objects: This method will retrieve all the child objects present in given parent object.
E.g.
QTP script to count & highlight all the objects present in “Login Dialog”
Set a=Dialog(“text:=Login”).ChildObjects
msgbox a.count
For i=0 to a.count-1
a(i).Highlight
Next
Q.) WAS to count number of objects present on calculator.
A.) set a=Window(“text:=calc.*”).ChildObjects
msgbox a.count
Q.) WAS to count number of objects present on the web page.
Set a=Browser(“title:=acti.*”).Page(“title:=acti.*).ChildObjects
msgbox a.count

NOTE:
By default ChildObjects method will retrieve all the objects presents in given parent object, in order to get only required type of object we have to specify the filter name condition with the help of description object as shown below:
Set d=Description.Create       ‘Create Description Object
d(“Class Name”).Value=”WinEdit”   ‘Specify condition
Set a=Dialog(“text:=Login”).ChildObjects(d)           ‘Pass it to child Object method
For i=0 to a.count-1
a(i).Highlight
Next
‘Note: ChildObjects takes only Description Object as argument & it is optional.
Q.) WAS to count number of buttons present on Calculator.
Set d=Description.Create
D(“Class Name”).Value=“WinButton”
Set a=Window(“text:=calc.*”).ChildObjects(d)
msgbox a.count
Q.) WAS to count number of links present on given web page?

NOTE:
Use “micclass” instead of “classname” while writing descriptive programming code for web application.
Mic stands for “Mercury Interactive Constant”
Set d=Description.Create
d(“micclass”).Value=“Link”
set a=Browser(“title:=acti.*”).Page(“title:=acti.*”).ChildObjects(d)
msgbox a.count
Q.) WAS to count the number of buttons present on given web page.
Set d=Descriptive.Create
d(“micclass”).Value=“WebButton”
Set a=Browser(“title:=acti.*”).Page(“title:=acti.*”).ChildObjects(d)
msgbox a.count
Q.) WAS to enter user specified input into all the text boxes present in a web page.
Input=inputbox(“input?”)
Set d=Description.Create
d(“micclass”).Value=“WebEdit”
Set a=Browser(“title:=acti.*”).Page(“title:=acti.*”).ChildObjects(d)
For i=0 to a.count-1
a(i).set input
Next
Q.) WAS to select(check) all the checkboxes present on given webpage.
Set d=Description.Create
d(“micclass”).Value=“WebCheckbox”
Set a=Browser(“title:=acti.*).Page(“title:=acti.*”).ChildObjects(d)
For i=0 to a.count-1
a(i).set “ON”
Next

NOTE:
While writing script for Web application it is mandatory to include the “Webtable” present in hierarchy of the object.
Q.) WAS to highlight the WebTable inside browser?
1.) Browser(“title:=acti:*”).Page(“title:=acti.*”).WebTable(“name:=All”).Highlight
2.) Browser(“title:=acti:*”).Page(“title:=acti.*”).WebTable(“text:=TaskName.*”).Highlight

Accessing or getting the object present inside the WebTable:
In order to retrieve the object present inside required cell of a “WebTable” we use “ChildItem” method which takes row,column,micclass,index as mandatory argument where row & column are numeric inputs which starts from 1, “micclass” in string input.
“Index” is numeric input which starts from 0
E.g.      WebTable1
In order to access “text1” present inside the “WebTable1” we need to pass following values as argument for “ChildItem” method.
Text1: 1,1, “WebEdit”,0
Similarly for “Text3” we should pass 1,2, “WebEdit”, 1
& for “link1” 2,2, “link”,0
E.g.
QTP script to click on “All” link present in customer table of ActiTIME application:
Browser(“title:=acti.*”).Page(“title:=acti.*).WebTable(“name:=All”).ChildItem(1,6, “Link”,0).Click
Q.) WAS to check/select all the checkboxes present in customer table of ActiTIME in reverse order.
Set T=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebTable(“name:=All”)
Rc=T.Rowcount
For i=rc to 2 step -1
T.ChildItem(i,6, “WebCheckBox”,0).Set “ON”
Next
Q.) WAS to select billing type as billable in all the list boxes of AddnewTaskTable of ActiTIME.
Set T=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebTable(“text:=TaskName.*”)
Rc=T.RowCount
For i=2 to rc
T.ChildItem(i,3, “WEbList”,0).Select “billable”
Next
Q.) WAS to select two items “billable & free” alternatively in the listboxes present in addnew
Task of the ActiTIME.
Set T=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebTable(“text:=TaskName.*”)
Rc=T.RowCount
For i=2 to rc Step 2
T.ChildItem(i,3, “WebList”,0).Select “Billable”
Next
For i=3 to rc Step 2
T.ChildItem(i,3, “WebList”,0).Select “Free”
Next
‘Write the above code using single for loop

Smart Identification:
It’s an alternative mechanism used by QTP during Runtime only when QTP is not able to identify the object using description properties stored in object Repository.

NOTE:
1.)    Smart identification is used only during runtime.
2.)    Smart identification is used only iff description properties are not sufficient during runtime.
3.)    If smart identification is disabled or not sufficient then only QTP goes to ordinal identifier. Tools->object identifier->Winbutton

Enabling & Configuring Smart Identification:
Goto-> tools->object identification, Select WinButton
Check “enable smart identification” check box
Click configure, add required properties to Base filter & optional Filter property section
E.g.
Base Filter Properties  Option Filter Properties
Optional Filter Properties
Nativeclass(button)
Abs_y(422)

Enabled(-1)
Then Click “OK” twice.
Enabled -1  True
              0  False

During “Runtime” QTP will always try to identify the object using description properties, if it is not sufficient then QTP goes to smart identification. In smart identification, first it uses base filter properties to identify the object. If it is not sufficient the nit goes to optional filter properties one by one.
Even if optional filter is not sufficient then QTP goes to ordinal identifier.
NOTE:
If the property value is not matching with any of the object then QTP will skip the respective property itself in smart identification.
NOTE:
If QTP is able to identify the object uniquely then “it ignores” the remaining properties of smart identification.
Q.) What are the limitations of smart identification?
1.) Its mandatory to use object repository so it consumes time for maintaining multiple objects.
2.) We can’t edit smart identification property value in object repository, every time we must delete & read the object, which again consumes time.
3.) Smart identification configuration need to be done by individual object separately which is also time consuming.
4.) To handle dynamic object we always go for descriptive programming.
Q.) WAS to check or select the checkbox of specified customer table of actiTIME application?
eCN=inputbox(“CustomerName?”)
Set T=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebTable(“name:=All”)
Rc=T.RowCount
For i=1 to rc
CN=Trim(T.GetCellData(i,1))
If CN=eCN then
T.ChildItem(i,6, “WebCheckBox”,0).Set “ON”
Exit for
End if
Next
Q.) What is debugging? & how do we debug QTP script?
A.) Process of executing the script step by step in order to detect the “bug”(to find the error) is called as “debugging”. In order to debug QTP script we use “F11”

NOTE:
Debugging is also done to understand the logic of the code. While debugging we use variables tab of debug viewer which will display the value of the variable.

Validation using QTP:
It is not just sufficient to perform the specified operation by entering required input. When we say testing it is also important to perform validation, which involves following steps:
1.)    Get the expected value.
2.)    Get actual value.
3.)    Compare expected & actual value.
4.)    Report the status (pass or fail).
We use variable to store expected & actual values, then we may use “if statement” to compare them, then we may use “msgbox” or “print” statement to display the status.

Getting the actual value:
To retrieve the actual value from the application during run time, we use “GetRO Property”. e.g
Dim Ev,Av,Status
Ev= “admin”
Av= Dialog(“text:=login”).WinEdit(“attached text:=Agent Name:”).GetROProperty(“text”)
If Av=Ev then
Status= “Pass”
Else
Status= “Fail”
End if
Msgbox status

NOTE:
1.)    “GetROProperty” method is used to get “Runtime object” property value, which takes property name as input & returns its value during runtime.
2.)    It can return only one property value at a time & property name must be always given between “ ” double quotes.
Q.) WAS to verify that we can’t maximize the calculator?
Ev=False
Av=Window("text:=calc.*").GetROProperty("maximizable")
If Av=Ev Then
            Status="Pass:We cant maximize calc"
else
            Status="Fail:We can Maximize calc"
End If
msgbox status
Q.) WAS to verify that we can maximize the notepad?
maximizable=Window("nativeclass:=notepad").GetROProperty("maximizable")
If maximizable Then
            Status="Pass:We can maximize notepad"
            else
            Status="Pass:We cant maximize notepad"
End If
msgbox Status

Login Function for ActiTIME:
>Function(UserName, Password)
Systemutil.Run "iexplore","http://127.0.0.1/login.do"
With Browser("title:=acti.*).Page("title:=acti.*)
.WebEdit("name:=useraname").Set usename
.WebEdit("name:=pwd").Set Password
.WebButton("name:=Loginnow").Click
End With
End function

>Call Login("admin","manager")
eTitle="actiTIME-OpenTasks"
aTitle=Browser("title:=acti.*).GetROProperty("title")
If aTitle=eTitle Then
            Status="Pass"
            else
            Status="Fail"
End If
Msgbox Status

Tools->Options->Run->view result->Automation->Results
Q.) What are the disadvantages of “msgbox” & “print” statements? & how do we overcome it?
A.) “msgbox” statement requires manual intervention & info displayed will vanish after clicking on “OK” button of msgbox.
“Print” is a QTP statement which will write the info into QTP print log which donot require any manual intervention but the info will vanish if we close the print log.
To overcome the above limitation we will write the result into QTP Result window, which don’t require any manual intervention & info is stored permanently.
In order to do this we use “Reporter.ReportEvent” statement which takes event status(Es), Reporter Step Name(RSN) and details as argument.
ü  Where “EventStatus” is a QTP constant & possible values are
micPass(0)
micPass(1)
micPass(2)
micPass(3)
ü  “ReporterStepName” & “details” message are string inputs.
ü  Mic stands for “mercury interactive constant”
ü  If the verification is successful we use micpass or 0, which will report the info as passed with Green checkmark.
ü  If the verification is failed we use micfail or 1, which will report the status as fail, indicated by Red Cross mark.
ü  To write additional info we use micdone or 2, which donot have any symbol.
ü  To report error handling we use micWarning, which will be reported with Orange Exclamation(!) mark.
E.g.
Call login("admin","manager")
eTitle="actiTIME-OpenTasks"
aTitle=Browser("title:=acti.*).GetROProperty("title")
If aTitle=eTitle then
Reporter.ReportEvent micPass, “login”, “login is successful”
Else
Reporter.ReportEvent micfail, “login”, “login is failed”
End If
Q.) How to make QTP to display Result window automatically after the script execution?
A.) Goto Tools-> Options-> Run-> check the ->“view results when Run session ends”-> Click apply & OK.
Q.) What is synchronization & how do we synchronize QTP script?
A.) Process of matching QTP execution speed with application is called as “synchronization”
We can synchronize the QTP script by using “Wait” statement.
E.g. Script to capture newly generated orderno.
Call InsertOrder()
Wait 10           ‘makes the QTP to wait for 10 seconds
New OrderNo.=Window(“FR”).WinEdit(“OrderNo:”).GetROProperty(“text”)
Msgbox NewOrderNo

NOTE:
To synchronize QTP script we can use “Wait” statements but it always makes the QTP to wait for specified amount of “seconds” exactly.
In order to make the QTP to wait till specific operation is completed, we have to use “synchronization point” available under insert menu.
E.g.
Call InsertOrder()
Window(“FR”).WinButton(“InsertOrder”).WaitProperty “enabled”, False, 20000
NewOrder=Window(“FR”).WinEdit(“OrderNo:”).GetROProperty(“text”)
Msgbox NewOrder

ü  The Synchronization point is the “wait property” method which takes three(3) arguments:
PropertyName, PropertyValue, Timeout in milliseconds.
ü  The default value for timeout is 1000 milliseconds(10 seconds)
File->Settings->Run->Object Synchronization timeout=20seconds
ü  The timeout is optional, if it is not specified then it takes object synchronization timeout, which is available under
File->Settings->Run (Its default value is 20sec)
This is called as Global Timeout.
ü  In the above e.g. after performing insert order the synchronization point makes the QTP to wait till “enabled” property of insert order button becomes “False” within the timeout.
Exists --> VBS
Exist --> QTP


Q.) WAS to verify that error msg is displayed for invalid login for ActiTIME application?
Dim MsgExist, errMsg, ErrObj
Call Login(“abc”, “abc”)
Set ErrObj=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebElement(“Class:=errormsg”, “Index:=0”)
MsgExist=ErrObj.Exit(3)
If MsgExist then
errMsg=ErrObj.GetROProperty(“innertext”)
Reporter.ReporterEvent micPass, “Invalid Login”, errMsg
Else
Reporter.ReportEvent micFail, “Invalid Login”, “Error Msg is not displayed”
End if
Q.) WA function to verify the error msg(1st) displayed in any ActiTIME page?
Function Verify ErrMsg()
Set ErrObj=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebElement(“Class:=errmsg”, “index:=0”)
MsgExist=ErrObj.Exist(3)
If MsgExist then
errMsg=ErrObj.GetROProperty(“innertext”)
Reporter.ReportEvent micPass, “VerifyErr”, errMsg
Else
Reporter.ReportEvent micFail, “VerifyErr”, “No ErrMsg”
End if
End Function
Q.) WAS to verify “success message” displayed in any ActiTIME page?
A.) Function Verify SuccessMsg()
Set SuccessObj=Browser(“title:=acti.*”).Page(“title:=acti.*”).WebElement(“Class:= Successmsg”, “index:=0”)
MsgExist=SuccessObj.Exist(3)
If MsgExist then
SMsg=SuccessObj.GetROProperty(“innertext”)
Reporter.ReportEvent micPass, “VerifySuccessMsg”, SMsg
Else
Reporter.ReportEvent micFail, “VerifySuccessMsg”, “No SuccessMsg”
End if
End Function
ü  In the above function “SucessObj” is the user defined object which represents any success Msg present in any ActiTIME page of type “WebElement”.
ü  “Exist” wll check whether the success object is present in the application or not, if it is present it returns “TRUE” , if it is not present it returns “FALSE” after the timeout(in this e.g. 3 seconds). The returned value will be stored in a user defined variable “MsgExist”.
ü  If “MsgExist” is “TRUE” then control will go inside the “if” part where the success msg text(innertext) will be captured using GetROProperty method, which will be stored in another user defined variable “SMsg” which will be reported into QTP result window with passed status.
ü  If “MsgExist” is “FALSE” then control goes to else part where we are reporting that there is no success msg with status as “Fail”.
Q.) WAS to display all the items present in a WebList one by one in reverse order?
a=Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebList(“name:=customerId”).GetROProperty(“all items”)
b=Split(a, “;”)
For i=ubound(b) to 0 step -1
Print b(i)
Next

NOTE :           a is a variable and b is a dynamic array.
Q.) WAS to display all the items present in a weblist one by one in reverse order without using “Split” function?
Set L=Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebList(“name:=customerId”)
ic=L.GetROProperty(“items count”)
for i=ic to i step -1
print L.GetItem(i)
Next

NOTE:           L is object and ic is variable.
Q.) WAS to display the last item of a WebList?
Set L=Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebList(“name:=customerId”)
ic=L.GetROProperty(“items count”)
print L.GetItem(ic)
‘Note: for GetItem method index starts from 1.
Q.) WAS to search for a required item in a WebList?
eItem= “IBM”
Msg= “Not Found”
Set L=Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebList(“name:=customerId”)
ic=L.GetROProperty(“items count”)
for i=1 to ic
aItem=L.GetItem(i)
If aItem=eItem then
Msg= “Found”
Exit For
End If
Q.)WAS to verify that Popup dialog is displayed when we ‘click’ on delete customer button in ActiTIME application?
Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebButton(“name:=Delete This Customer”).Click
DialogExist=Browser(“title:=acti.*”).Dialog(“text:=Microsoft Internet Explorer”).Exist(3)
If DialogExist then
Reporter.ReportEvent micPass, “VerifyPopup”, “Popup is displayed”
Else
Reporter.ReportEvent micFail, “VerifyPopup”, “Popup is not displayed”
End if
Q.) What is check point & what are its types?
A.) It is the built-in option available in QTP to perform verification & we have 8 types of check points:

1)      Standard
2)      Text
3)      Text Area
4)      Bitmap
5)      Database
6)      Accessibility
7)      XML Checkpoint(from app)
8)      XML Checkpoint(from resource)
Q.) How do you insert checkpoint?
A.) Switch to recording mode
Goto-> insert-> checkpoint-> select the required type of checkpoint
Such as standard checkpoint, then click on the required object in the application
Click OK on object selection, Click OK on checkpoint properties
Stop recording.
E.g. Window(“Calculator”).Check checkpoint(“Calculator”)
Q.) What are the limitations of check point & why we don’t use check points?
1.)    To insert checkpoint we will switch to recording mode & the check points are stored in object repository.
2.)    Using a check point we can verify property value of only one object i.e. if we have multiple objects, we have to check multiple check points which increases the maintenance.
3.)    Using check points we can’t verify all the properties values e.g. we can’t verify maximizable property.
4.)    Using check point we can’t search the item.
5.)    Using check point we can’t verify whether an object is exist or not.
6.)    We can’t customize the check point results.
To overcome limitations of check point we use GetROProperty method & Reporter.ReportEvent to perform the validation which is called as user defined check point.
Q.) How do you Export the QTP result?
A.) Goto->Automation->select the file type(HTML,DOC,PDF)-> click OK-> specify the name-> click save.

Action:
Action is an entity which is used to group logically related set of statements (it is similar to functions)

NOTE:
1)      Every QTP test contains one or more actions.
2)      To create a new actions goto->insert->call to new action->click OK.
3)      To rename the action, select the required action & press “shift+F2”.
4)      To delete the action, select it & press delete.
5)      If we delete all the actions, then QTP will automatically create a new blank action after displaying the warning message.
6)      The order in which actions gets executed is called as test flow & we can change it by dragging & dropping the action.
7)      We can drag and drop any action to any location but it works only iff the test flow is as per the functionality of the application.
8)      In the keyword view we can see all the actions at a time & they are listed based on the test flow, which we can change it using drag n drop option.
9)      In expert view we can view only one action at a time & they are listed in alphabetical order & we can’t change the test flow.
10)  QTP will always execute the script based on the test flow even if we are in expert view.

ü  Every action has its own object repository called as “local object repository” (LOR).
ü  Objects present in “LOR” can be accessible only by respective action & not by any other action.
Q.) What is the disadvantage of LOR?
A.) Redundancy i.e. same objects will be present in multiple LOR which will not only consume space but also increases maintenance.

 NOTE:
To overcome the above limitation we can go for “shared object repository”.

Shared Object Repository:
It is the centralized object repository which can be shared by multiple actions
Steps to create “SOR”:
1.)    Goto resources & select “object repository manager” (Alt+R+R).
2.)    Click on add objects then click on required object in the application, click OK on object selection.
3.)    Save the “SOR” at required location(Ctrl+S)

NOTE:
“SOR” will be saved with .tsr(test shared repository) as the file name extension.

Steps to Associate “SOR”:
1.)    Goto resources & select “associate repositories” (Alt+R+E).
2.)    Click add repository (+) browse & select the required .tsr file then click open.
3.)    Move the actions from available actions to associated actions then click OK.

NOTE:
Object repository window (Ctrl+R) can be display not only the local object but also the shared objects but we can edit only the local objects & not the shared objects (shared objects are displayed in grayed out color).
ü  In order to edit “SOR” we have to open it in object repository manager then we have to select “enable editing” option available under file menu of object repository manager.
Q.) If the same object is present in “LOR” & “SOR” then QTP uses which object?
A.) QTP uses object present in “LOR”.
Q.) How do we export/convert “LOR” into “SOR”?
A.) open object repository (Ctrl+R), then goto file, select export local object, specify the name & click save.
Q.) How do we merge the “shared object repositories”?
A.) To do this, goto resources, select “object repository manager”(Alt+R+R), then goto tools, select “object repository merge tool” , specify the complete path of primary & secondary “SOR” files, then click OK.
Close the statistics window & save a newly merged SOR (Ctrl+S).

NOTE:
We can merge only two “SOR” at a time & when merge it, a new file will be created, and original file will not be modified.
Q.) What are the types of conflicts that occur while merging the “SOR”?
A.) There 3 types of conflicts:
        i.            Similar description conflicts.
      ii.            Same name different description conflicts.
    iii.            Same description different name conflicts.
Q.) What are the advantages of action/function?
A.)
        i.            Reduces the number of lines of code & space.
      ii.            Reduces the maintenance (single point updation).
    iii.            Reusability, which saves time.
Q.) What is nested action & how to create it?
A.) Action present inside the other action is called as nested action.
To create an nested action (child action), first select the required action, then go to insert call to new action, select the location as “After the current step” then click OK.

NOTE:
To copy-paste an action we can use “call to copy of action” but it will not only consume space, but it also increases maintenance instead of copy-pasting, it is better to “call the existing action”.
Q.) What is external action?
A.) The action called from a different test is called as external action.

NOTE:
Action present within the same test is called as internal action.
ü  The actions which can be called multiple times are called as reusable action, which is indicated by reusable action checkbox, present in action properties window.
ü  If the checkbox is uncheck we can’t call that action multiple, which is called as non reusable action.

NOTE:
External action are always reusable, but internal actions can be reusable or non reusable.

NOTE:
External actions are always “read-only”.
Q.) Can we create nested action for external action?
A.) No, because it’s read-only.

NOTE:
For external actions we can’t change the code, we can’t modify the local object repository, we can’t record.
To do any changes we open it from the original test.
Q.) What are the types of actions available in QTP?
A.)
        i.            Reusable - nonreusable.
      ii.            Internal – external.
    iii.            Independent - nested.




Parameterization:
Replacing hard coded values by parameters which takes the value from external source such as text file, csv file, excel file etc is called as ~.
Q.) WAS to login into ActiTIME app by taking the UN & PWD from the text file.
A.) ‘Precondition: There should be login.txt file in your system(d:\ or any drive)
Set fso=create object(“Scripting. File System Object”)
Set F=fso.open Text File(“d:\login.txt”)
UN=F.readline
PWD=F.readline
F.close
Call login(UN,PWD)
Q.) WAS to login into ActiTIME app by taking the UN & PWD from csv file.
A.) ‘Precondition: There should be login.csv file in your system(d:\ or any drive)
Set fso=create object(“Scripting. File System Object”)
Set F=fso.open Text File(“d:\login.csv”)
a=F.readline
b=split(a,”,”)
UN=b(0)
PWD=b(1)
F.close
Call login(UN,PWD)
Q.) WAS to login into ActiTIME app by taking the UN & PWD from excel file.
A.) ‘Precondition: There should be login.xlsx file in your system(d:\ or any drive)
Set xl=create object(“excel.application”)
Set wb=xl.workBooks.open(“D:\login.xlsx”)
Set ws=wb.worksheets(1)
UN=ws.cells(1,”A”).value
PWD= ws.cells(1,2).value
wb.close
xl.quit
Call login(UN,PWD)
Q.) WAS to create multiple customer in ActiTIME app by taking the data from excel file.
A.) Function createCustomer(cname,cdescription,cRadioValue)
With  Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebEdit(“name:=name”).set cname
.WebEdit(“name:=description”).set cdescription
.WebRadioGroup(“name:=after createAction”).select CRadiovalue
.WebButton(“name:=create customer”).click
End with
End Function
Precondition: There should be customers.xlsx file in d:\
Set xl=create object(“Excel.Application”)
Set wb=xl.workbooks.open(“D:\customers.xlsx”)
Set ws=.wb.worksheets(1)
RC=ws.usedrange.Rows.Count
For i=2 to RC
CN=ws.cells(i,1).value
CD= ws.cells(i,2).value
CRB= ws.cells(i,3).value
Call create customer(CN,CD,CRB)
Next
Wb.close
xl.quit
Q.) WAP to create multiple projects in ActiTIME application by taking data from excel file.

Data Table:
It is a built-in excel file available with every QTP test which is used to perform “data  driven testing” i.e testing the application with multiple sets of data.

NOTE:
*     Every QTP test has built-in excel file which is called as “data table” & to use the data table MS office excel s/w is not required.
*     “data table” has two types of sheets i) Global ii) Action also called as local sheets.
*     “data table” contains only one global sheet & data present in global sheet can be accessible by all the Actions.
*     No. of local sheets will be same as no. of Actions in the test & data present in local sheet can be accessible only by respective Action.
*     If we create an excel the local sheet will be created , if we rename the Action local sheet gets renamed, if we delete the action local sheet gets deleted.
*     We should always start entering the data from the first row-first column & we should continue in sequential order both in row & column wise.
*     The row in which data is present are called as “Action Rows” (highlighted rows)
*     To rename the column “double click it” specify the new name & click OK, each columns are also called as data table parameters.
*     Just pressing delete will make the cell content as empty but the row still remains active, in order to delete the active row, select the entire row & press “Ctrl+K”.
We can also delete the entire column using “Ctrl+K”.
*     To read the data from data table we have to use the following syntax: Variable=DataTable(“columnName”,sheetID) where, sheetID can be dtGlobal sheet or dtLocal sheet. If we don’t specify the sheetID, then QTP reas the data from Global sheet.
*     Column name is CASE sensitive.
Eg: to read data from both global & local sheet by multiple Actions.
Step1: Open new QTP test & create another action(Action2)
Step2: Goto->view->data table and enter the values into data table as shown below:
                                                            Data Table
A                                             B                                                         C
Qspiders
Bangalore
Pune









Global
Action1
Action2
Sheet1                                           Sheet2                                           Sheet3
Step3: Write the following code in both Action1 & Action2.
G=DataTable(“A”,dtGlobalSheet)
L=DataTable(“A”,dtLocalSheet)
msgbox G&L
If we run the above script we get the output as:
                       
by Action1                                              by Action2

Test Iterations:
If the data is present in Global sheet then QTP executes the script by taking the data present in all the rows of Global sheet one by one, this is called as ~.
In order to change this :
Goto->file->settings->run->select the required option under data table iteration option, which has got following three option:
i.)                  Run one iteration only: execute the script by taking the data from first row.
ii.)                Run on all rows: execute the script by taking the data from all the rows.
iii.)              Run from row: execute the script by taking the data from specified range.

NOTE:
*     Default test iteration setting is “Run on all rows” & using these built-in option we can’t execute the script by taking the data in reverse order or we can’t skip the rows in between, this is possible only by writing code.
Q.) WAS to print data present in Global sheet in reverse order.
A.)  rc=DataTable.GetRowCount ‘Get Active Row Count from global sheet
For i=rc to 1 step -1
DataTable.SetCurrentRow i ‘Set the current row to i in data table
print DataTable(“A”) ‘Print the value
Next
‘Note: Test iteration setting should be “Run one iteration only”
Q.) WAS to print the values present in alternative rows(odd values) of Global sheet.
A.) rc=DataTable.GetRowCount
For i=1 to rc step 2
DataTable.SetCurrentRow i
print DataTable(“A”)
Next

Action Iteration:
If the data is present in local sheet, by default the QTP executes the Action only one time by taking the data present in 1st row of local sheet, this is called ~.
In order to change this:
Goto->keyword view->select-> test flow or
Goto->view->select ->test flow, then right click on respective action->select “Action call properties”-> select the required option under data table iteration section & click OK.

NOTE:
*     Here also we have same three options, but the default setting is “Run one iteration only”.
Q.) WAS to print the data present in alternative rows of local sheet in reverse order.
A.) rc=DataTable.LocalSheet.GetRowCount
For i=rc to step -2
DataTable.SetCurrentRow i
Print DataTable(“A”,dtLocalSheet)
Next
When we create a “nested action ” we get “run action statement” in the parent action which has two argument:
i.)                  Action Name
ii.)                Action Iteration
Action Iteration can be “one iteration” or “all iteration” or “range”(“starting value-ending value”)
Q.) WA QTP script to Login, Open the order & Logout with multiple inputs.
Step1: Open new QTP test & create two Actions as “nested” for Action1.

Step2: Rename the Action as Login, Open order & Logout as shown above in 2nd figure
Step3: Select the Login Action & record Login related operations.
            Select the Open Order Action & record Open Order related related operations.
            Select the Logout Action & record Logout related operations.
            Stop the recording.
Step4: Open the data table & enter the values into the data table as shown below:

AN
PWD
Order Number

admin
mercury
1
manager
mercury
2
guest
mercury
3
10
          Global                                Login                          Open Order                         Logout
Step5: Replace the hard coded values present in login & open order action by respective data table parameter.
Eg: System UtilRun “C:\program files\HP\QTP\Samples\Flight\application”
Login
Dialog(“Login”).WinEdit(“Agent Name:”).Set DataTable(“AN”,dtlocalsheet)
Dialog(“Login”).WinEdit(“Password:”).Set DataTable(“PWD”,dtlocalsheet)
Dialog(“Login”).WinButton(“OK”).Click
RunAction”OpenOrder”,allIterations
RunAction”Logout”,oneIterations
Open Order
Window(“FR”).Dialog(“Open Order”).WinEdit(“Edit”).Set DataTable(“Order No”,dtlocalsheet)
In Test Flow change the Action Iteration setting of both login & open order Actions to “Run on all rows”.
Q.) WA QTP script to login ,insert new order, logout in multiple inputs.
Q.) How do we take data from database?
A.) We can take data fom database into data table sheets using DSN(data source name):
Step1: Goto->views->select data table & goto the required sheet,global or local Right click on the data table,select ->sheet->import->From database,click  next & Ok, Select the required DSN from the list(eg QT_flight32), click Ok, move the required table to the  right side,click next, if required specify the filter data condition,click next, if required select the  sort order, click next, Finish.

Error Handling:
During runtime,if Vb script or QTP encounters any error then they will display the pop-up error message & haults the script execution, “in order to continue” the script execution first we should suppress the runtime error message displayed by QTP or VBScript & then take necessary action to continue the script execution with proper output.
To suppress the error message we use “On Error Resume Next” & to detect whether error is occurred or not, we can use “Err.Number” statement which returns 0,there is no runtime error or else it returns non-zero value.
Eg: VB Script to handle divide by Zero(0) error.
On Error Resume Next
Dim=a, b, c
a=12
b=0
c=a/b
If Err.Number=0 then
Print c
Else
Print Err.Description
End if

Handling Item not found error using “On Error Resume Next” while performing insert order operation.
Eg: On Error Resume Next
Window (“FR”).WinMenu(“Menu”).Select “File;NewOrder”
Window(“FR”).ActiveX(“MaskEdBox”).Type 121212
Window(“FR”).WinComboBox(“Fly From:”).Select “Londn”
If Err.Number<>0 Then
Window(“FR”).WinComboBox(“Fly From:”).Select 0
End If
In the above example we are suppressing the error message using “On Error Resume Next” & after performing select operation with the specified input we are checking whether error is occurred or not i.e if error number is other than 0 then we are making the QTP to select the first item in the list & continue the script execution.

Limitations of VB Script Error Handling Options:
1.)    We should write “On Error Resume Next” statement at the beginning of every script.
2.)    We should know the exact line number where error is occurred.
3.)    The error handling code will drastically increase the script length.
To overcome this limitation we can use “Recovery Scenario Manager” which is an option available in QTP.

Recovery Scenario Manager(RSM):
It is a built-in option available in QTP, which is used to handle the runtime errors.

During runtime when QTP starts performing the operations on the application, the “RSM” will start monitoring the QTP for any errors parallel.

If QTP encounters any error then RSM will detect it & takes the control by not allowing the QTP to display the error message & this process is called as ”Trigger Event”.

Then RSM will perform specified operation to handle the error which is called as “Recovery Operation”(RO).

After handling the error the control will be transferred back to QTP to continue script execution, this process is called as “Post Recovery Operation”(PRO).
                                                            QTP                                         RSM
1.
2.
3.
4.
5.
Continue

                                                                                    .
App                                                                             TE


                             

                                                                              PRO                    RO




TE->Trigger Error(Detect Error)
RO->Recovery Operation(Handle Error)
PRO->Post Recovery Operation(Transfer Control to QTP)

NOTE:
*     RSM has following four trigger events
1.)    Pop-up window.(of the application)
2.)    Object state.(object disable)
3.)    Test run-error.(any runtime error displayed by QTP)
4.)    Application crash.

Recovery Operation:
RSM has following four recovery operations:
1.)    Keyboard or mouse operation: which is used to perform any click or type operation.
2.)    Close application process: used to kill the task present in task manager.
3.)    Function call: can be used to perform set of operations by calling the user defined functions.
4.)    Restart MS Windows: can be used to restart the O.S & RSM can automatically continue the script execution after restarting the O.S

Post Recovery Operation:
RSM has six PRO as follows:
1.)    Repeat current step & continue.
2.)    Proceed to next step.
3.)    Proceed to next Action or Component iteration.
4.)    Proceed to next Test Iteration.
5.)    Restart the current test run.
6.)    Stop the test run.

Handling Update error using RSM:
Step1: Open new QTP test & record the following operations of Flight Reservation application.
A.    Login
B.     Open Order No1
C.     Change the name & click update order
D.    Logout
Step2: Run the above script.

NOTE:
*     During runtime QTP changes the name of order no1 & clicks update button, but application will display update error message because previous value & new value are same
*     In order to handle this pop-up error message, we create RSM with following options:
1.)    Pop-up window as trigger event.
2.)    Keyboard operation as recovery operations.
3.)    Repeat the current step as PRO.


Steps to create Recovery Scenario:
1.)    Goto->resourced->recovery scenario manager(ALT+R+S)
2.)    Click new scenario->select pop-up window as trigger event->click next.
3.)    Click on spy button->click on update error message->click next.
4.)    Select keyboard/mouse operation, click next, select click Default button/Press enter key.
5.)    Uncheck Add another recovery operation checkbox, click next.
6.)    Select repeat current step& continue as Post Recovery operation, click next, Specify the scenario name, select add scenario to current test checkbox, click finish, save the Recovery Scenario at  the required location.

 NOTE:
*     Recovery scenario will be saved with .QRS (QTP recovery scenario) extension.
*     We can also associate Recovery Scenario to any required test in file->settings->Recovery Tab, click add(+) browse & select required QRS file ,Click open then click add scenario then click apply & OK.
*     If Recovery Scenario is activated during runtime then it will be reported in QTP result window with warning status.

Handling item not found error using Recovery Scenario Manager:
Step1: Open new QTP test & record insert order operation.
Step2: Specify invalid inputs for both Flight From & Flight To combobox.
Step3: Goto->Recovery Scenario Manager->click new scenario, select Test run error, then select “item in list or menu not found” under test run error, click next
Step4: Select keyboard/mouse operation, click next, select-> press or key combination, place the cursor inside the textbox & press down(↓) arrow key in keyboard then click next.
Step5: Uncheck add another recovery operation, click next, select proceed to next step as Post Recovery operation, click next.
Step6: Specify the scenario name, check add scenario to current test checkbox, click finish, save the recovery scenario, Run the QTP Script.

NOTE:
*     During Runtime QTP will not be able to select the item in “Fly From” combobox a we have specified the invalid input, the error will be detected by RSM, which will take the control & it will select the first item by pressing the down(↓) arrow key as part of Recovery operation then control will be transferred to next step a specified in Post Recovery operation.
*     The same procedure will be repeated for ‘Fly to’ combobox also.
*     We have more than 20 recovery scenarios created in webRecovery.qrs file which is in following location: C:\Program files\HP\QTP\Recovery

Automation Framework:
It is not just sufficient to convery manual test cases into Automation script, it is also important to automate the test execution process which involves following steps:
i.)                  Launch QTP.
ii.)                Open required script.
iii.)              Run the test script.
iv.)              Get the result.
v.)                Close the QTP.

NOTE:
*     For mutiple test scripts step number ii.), iii.) & iv.) will be repeated in a loop.
*     In automation, framework is a structured procedure or standard which is followed to automate the above mentioned test script execution process.
*     In order to automate QTP itself, we can take the information present in the following help document:START->Programs->QTP->Documentation->QuickTestAutomation-> -Reference->ObjectModelDiagram
Eg: VBScript to launch QTP & nexecute multiple test scripts:

Set QTP=create object(“QuickTest.Application”)
QTP.Launch
QTP.visible=True
For i=1 to 3
            QTP.open “D:\Framework\Test”&i
            QTP.Test.Run
            Res=QTP.Test.LastRunResults.Status
            msgbox Res
Next
QTP.Quit

NOTE:
*     Even though the above VBScript will automatically open the QTP & run multiple test scripts, it has got following disadvantages:
i.)                  Script will work only iff name name of the QTP is in sequential order.
ii.)                Msgbox statement requires manual intervention.
In order to solve these problems we can take the help of “excel file”.

Content of RunMe.vbs
Set QTP=create object(“QuickTest.Application”)
QTP.Launch
Set xl=createobject(“excel.application”)
Set wb=xl.workbooks.open(“D:\Framework\TestSet.xlsx”)
Set ws=wb.worksheets(1)

Rc=ws.usedrange.rows.count
For i=2 to rc
            TestName=ws.cells(i,1).value
QTP.open “D:\Framework\”&TestName
QTP.Test.Run
Res=QTP.Test.LastRunResults.Status
ws.cells(i,2).value=Res
Next
wb.save
wb.close
xl.quit
QTP.quit

TestSet.xlsx
          
Before Execution                                After Execution


Folder Structure:
D:\Framework


NOTE:
*     We execute this framework by double clicking on RunMe.vbs which does following steps:
Step1: Launches the QTP.
Step2: Opens TestSet.xlsx file & goes to First sheet.
Step3: Counts the number of Active Rows.
Step4: For each Active Row, it takes the testname present in first column, opens it in QTP, Runs it & gets the result, which will be written into corresponding second column.
Step5: After executing all the scripts, it will save the excel, close the excel & close the QTP.

*     In this framework, we are executing all the scripts one after the other in sequential order, hence it is called as ”Linear Automation Framework”, which is best suitable for performing “Full Regression Testing”.

Flow diagram of Linear Automation Framework
QTP_SOFTWARE
                       







Modular Driven Automation Framework
Process of executing the script based on specified modules is called as ~.
Q.) WAS to display Time stamp(formatted current system date & time)
A.)
TS1=Replace(now,"/","_")
TS2=Replace(TS1,":","_")
msgbox TS2

Content of RunMe.vbs of  Modular Driven Automation Framework
Set QTP=CreateObject(“QuickTest.Application”)
QTP.Launch
Set xl=CreateObject(“excel.application”)
Set wb=xl.workbooks.open(“D:\Framework\Testset.xlsx”)
Call ModuleDriver(“Project”)
Call ModuleDriver(“Customer”)
TS1=Replace(now,"/","_")
TS2=Replace(TS1,":","_")
Wb.saveas “D:\Framework\Results\”&TS2
Wb.close
xl.quit
QTP.close
Function ModuleDriver(ModuleName)
Set ws=wb.worksheets(ModuleName)
Rc=ws.usedrange.rows.count
For i=2 to rc
            TestName=ws.cells(i,1).value
            QTP.Open “D:\Framework\”&TestName
            QTP.Test.Run
            Res=QTP.Test.LastRunResults.Status
            Ws.cells(i,2).value=Res
Next
End Function

Flow Diagram of M D A Fw
Customer
                                                
Project
                                           Pp                                    


Folder Structure of M D A Fw:
D:\Framework



Contents of TestSet.xlsx
            

Description:
We run the framework by double clicking on RunMe.vbs which does the following steps:
1.      Launches QTP.
2.      Opens TestSet excel file.
3.      Calls the Module Driver.
4.      Saves the results with Time stamp.
5.      Closes the excel & QTP.

Module Driver
When the runme calls “Module Driver” by passing required module name a argument it does the following steps:
1.      It goes to specified module sheet.
2.      Counts the number of Active rows.
3.      For each Active rows it takes the test name present in first column, opens it in QTP, runs it & gets the result which will be written into Second column of corresponding testname.

Converting Manual Test Case into Automation Scripts:- BEST PRACTICE
In order to convert manual test case into automation script, we have to follow the following steps
1.      Read all the manual test cases & choose the test cases which we can automate.
2.      Identify repetitive steps, convert them into functions.
3.      Write the Scripts as per manual test case steps by calling the functions.
4.      Data drive the test script if required.
5.      Send it for review & fix any given review comment.
6.      Send it for approval & store it in test case repository after the approval.

Test Case which we can’t Automate:
The test case should not contain any manual interventions.
Eg:  barcode scanner
Biometric scanner
Credit card swipe machine
Entering cvv number
Otp(One time passwd) generator
Printing & scanning
Tool limitations.
Eg: captcha image
Animation
Any flash object
Verification of videos & audios file
Verification of graphs & charts
Virtual keyboard(Login page)
Q.) How do you choose test case for automation?
A.) For automation we choose only regression test case which donot have any manual intervention & tool can recognize those objects.

NOTE:
*     Since regression testing is monotonous & time consuming, we automate only regression test cases. It can be functional, integration or system.
*     Automation testing will always support manual testing  & speed up the entire testing process & it can’t replace the manual test process.

Creating Functions:
After choosing the test cases to be automated we have to execute them atleast once manually which gives more clarity on the test case. After the execution we have to identify the repetitive steps & convert them into function.

NOTE:
*     We can also use reusable actions but performance wise functions are better than actions.

Sample Test Cases:
TestCase1
TestCase2
TestCase3
TestCase4
TestCase5
Login
Login
Login
Login
Login
GotoCustomerCreationPage
GotoProjectCreationPage
GotoCustomerCreationPage

GotoCustomerCreationPage
CreateCustomer
CreateProject



VerifySuccessMsg
VerifySuccessMsg
VerifySuccessMsg For Each Customer
VerifySuccessMsg











Logout
Logout
Logout
Logout
Logout

With respect to above Test Cases we have following repetitive steps(functions)
1.      Login
2.      GotoCustomerCreationPage
3.      GotoProjectCreationPage
4.      CreateCustomer
5.      CreateProject
6.      VerifySuccessMsg
7.      Logout

Function GotoCreateCustomerPage()
With Browser(“title:=acti.*”).Page(“title:=acti.*”)
.Link(“name:=Projects&Customers”).Click
.WebButton(“name:=AddNewCustomer”).Click
End With
End Function

Function GotoCreateProjectPage()
With Browser(“title:=acti.*”).Page(“title:=acti.*”)
.Link(“name:=Projects&Customers”).Click
.WebButton(“name:=AddNewProject”).Click
End With
End Function

Function CreateProject(CN,PN,PD,PRB)
With Browser(“title:=acti.*”).Page(“title:=acti.*”)
.WebList(“name:=CustomerId”).Select CN
.WebEdit(“name:=name”).Set PN
.WebEdit(“name:=description”).Set PD
.WebRadioGroup(“name:=afterCreateAction”).Select PRB
.WebButton(“name:=CreateProject”).Click
End With
End Function

Function Logout()
            Browser(“title:=acti.*”).Page(“title:=acti.*”)
            .Image(“alt:=logout”).Click
            Browser(“title:=acti.*”).Close
End Function

Function Library
Functions present inside the Action are called as local functions which can be accessible only within the same action. In order to call the function by different actions & different test, we must place those functions in function library which are called as global functions.
Test1  
Action1
Function ABC()
End Function
Call ABC()
Action2
Call ABC()

Steps to Create Function Library:
1.      Goto->File->New->Function Library(Shift+Alt+N)
2.      Write the Function code inside the function library.
3.      Save the function library at the required location(Ctrl+S)

NOTE:
*     QTP supports following three formats of function library:
i.)                  .qfl -> QTP function library.
ii.)                .vbs -> Visual basic scripting.
iii.)               .txt -> text file.

Steps to associate function library:
Open->New QTP test, Goto->File->Settings->Resources->Click on add(+) & click browse, select the required function library, click open then click apply & OK.

NOTE:
*     For every test we should separately associate the function library, In order to make the library as default click on set as default button.
 Test                                                    Associate
Action1
Call ABC()

Action2
Call ABC()


Function ABC() …………………………
…………………………
End Function
                                                                                    Library1.qfl
Goto-> framework folder->open TestSet.xlsx->remove all the rows except the first row & save the excel file & close.
If  there are any old scripts(unwanted) delete them.
Goto-> results folder-> delete all the old results.



 NOTE:
*     Ensure that path present in RunMe.vbs is uptodate.
Create a text file inside the framework with the name “library.txt” & copy-paste all the functions which are written inside the Action(all the seven functions)

NOTE:
*     The above step should be done only once & it should contain only three files & one folder:
i.)                  RunMe.vbs
ii.)                TestSet.xlsx
iii.)              Library.txt
iv.)              Results folder

Steps to Write Automation Script:
1.      Open->QTP & associate the above created function library with the test.
2.      Call the function present in function library as per manual test case step.
3.      Save the QTP script inside the framework folder.
4.      Enter the newly created script name into TestSet.xlsx

Automation Script For TestCase1:
Call Login(“admin”,”manger”)
Call GotoCreateCustomerPage()
Call CreateCustomer(“CustomerA”,”DescA”,”#1”)
Call VerifySuccessMsg()
Call Logout()

Call Login(“admin”,”manger”)
Call GotoCreateProjectPage()
Call CreateProject(“CustomerA”,”Project”,”DescA”,”#0”)
Call VerifySuccessMsg()
Call Logout()

Call Login(“admin”,”manger”)
Call GotoCreateCustomerPage()
Call CreateCustomer(“CustomerB”,”DescB”,”#1”)
Call VerifySuccessMsg()
Call CreateProject(“CustomerB”,”Project”,”DescB”,”#0”)
Call VerifySuccessMsg()
Call Logout()

‘PreCondition: TestIteration “Run one Iteration only”
Call Login(“admin”,”manager”)
Call GotoCreateCustomerPage()
 Rc=DataTable.GetRowCount
For i=1 to Rc
            DataTable.SetCurrentRow i
CN=DataTable(“CN”)
CD=DataTable(“CD”)
CRB=DataTable(“CRB”)
Call CreateCustomer(CN,CD,CRB)
Call VerifySuccessMsg()
Next
Call Logout()

Content of data Table

CN
CD
CRB
1
C1
D1
#2
2
C2
D2
#2
3
C3
D3
#2
4





Automation Script For Multiple Projects:
Call Login(“admin”,”manager”)
Call GotoCreateProjectPage()
Rc=DataTable.GetRowCount
For i=1 to Rc
            DataTable.SetCurrentRow i
CN=DataTable(“CN”)
PN=DataTable(“PN”)
CD=DataTable(“CD”)
PRB=DataTable(“PRB”)
Call CreateCustomer(CN,PN,CD,CRB)
Call VerifySuccessMsg()
Next
Call Logout()

Content of data Table

CN
PN
PD
PRB
1
C1
P1
D1
#2
2
C2
P2
D2
#2
3
C3
P3
D3
#2


Flow Diagram of Hybrid Automation Framework









Q.) What is function driven automation framework?
A.) Process of executing the script by calling the function present in function library is called as ~ or function driven testing.
Q.) What is data driven automation framework?
A.) Process of executing the script by taking the dat from data table is called as data driven testing or ~.
Q.) What is hybrid driven automation framework & why do we go for it?
A.) Combination of two or more frameworks is called as hybrid automation framework.
To get the advantages of multiple frameworks we go for hybrid automation framework.
Q.) How do you capture the QTP test environment information?(for compatibility)
A.) In order to capture QTP test environment information we can take the help of environment variable available in the following location.
File-> Settings-> Environment.
Eg:
OS=Environment(“OS”)
OSv=Environment(“OSVersion”)
LHN=Environment(“LocalHostName”)
UN=Environment(“UserName”)
QTP=Environment(“ProductVer”)
Reporter.ReportEvent micDone,”OS”,OS&vblf&OSv
Reporter.ReportEvent micDone,”CompName”,LHN
Reporter.ReportEvent micDone,”User”,UN
Reporter.ReportEvent micDone,”QTP”,QTP
Q.) How do you open three orders randomly?
A.) Using RandomNumber
For i=1 to 3
            N=RandomNumber(1,10) ‘generates a num randomly b/w 1 to 10
            Call OpenOrder(N)
Next
Q.) There are two browsers open,WAS for closing newly opened browser?
A.) Browser(“title:=acti.*”,”CreationTime:=1”).Close
Q.) WAS to close first browser?(or older Browser)
A.) Browser(“title:=acti.*”,”CreationTime:=0”).Close
Q.) WAS to close middle browser out of three?
A.) Browser(“title:=acti.*”,”Location:=1”).Close
Q.) WAS to close all the notepad?
A.) SystemUtil.CloseProcessByName “notepad.exe”
Q.) How do you take the data present in external excel file into data table?
A.) We can take help of “ImportSheet” method available under datatable.
Eg:
DataTable.ImportSheet “D;\book1.xls”,”Sheet1”,”Action1”
‘Note: ImportSheet works for xls & not xlsx.
‘Data imported are temporary, which we can see in RunTime DataTable Present in Result ‘window.

Keyword Driven Automation Framework
Process of executing the script by taking the keyword script by taking the keyword present in keyword Table

Content of Keyword Driver(QTP Script)
SystemUtil.Run “iexplore”, http://127.0.0.1/login.do
For j=1 to 2
            TestName =”Test”&j
            Call ExecuteKeywords(TestName)
            Next
Browser(“title:=acti.*”).Close

Function ExecuteKeywords(TestName)
DataTable.ImportSheet “D:\KeywordTable.xls”,TestName,”Action1”
Rc=DataTable.LocalSheet.GetRowCount
For i=1 to rc
            DataTable.SetCurrentRow i
            ObjType=DataTable(“ObjType”,dtLocalSheet)
            PptVal=DataTable(“PptVal”,dtLocalSheet)
Select Case ObjType
Case “WebEdit”
Browser(“title:=acti.*”).Page(“title:=acti.*”).WebEdit(PptVal).Set Input
Case “WebButton”
Browser(“title:=acti.*”).Page(“title:=acti.*”). WebButton(PptVal).Click
Case “Link”
Browser(“title:=acti.*”).Page(“title:=acti.*”).Link(PptVal).Click
Case “Image”
Browser(“title:=acti.*”).Page(“title:=acti.*”).Image(PptVal).Click
End Select
Next
End Function

OT
PV
Input
WebEdit
n:=V
admin
WebButton
n:=L




                        QTP                 Run

Application





Contents of KeyWordTable.xls
Convert Keywords to Scripts
Browser().PageOT(PV).Method
Input

A
B
B
1
ObjType
PptVal
Input
2
WebEdit
name:=username
admin
3
WebEdit
name:=Login now
manager
4
WebButton
name:=Logout

5
Image
alt:=Logout


Q.) Why QTP is called as Advanced Keyword Driven Testing Tool.?
A.) The keyword view of QTP is similar to keyword table of keyword driven framework with user friendly features such as selecting the object from features such as selecting the object from dropdown, graphical representation of the object(icons) and autogenerated documentation, because of this QTP is called as ~.