QTP scripts examples for beginner

By | July 3, 2009

QTP scripts examples for beginner:Hi friends, This post is useful for fresher who are looking for QTP scripts examples so that they can understand the qtp automation better. If you are advance users than just go through this blog you will get lots of advance QTP VB scripts examples which will be useful for your automation project.

I have listed here two QTP scripts examples specially for fresher, one is related to webpage and other is related to simple GUI (Graphical user interface).

Sample QTP script 1:

SystemUtil.Run “notepad”,””,””,””
Window(“Notepad”).WinEditor(“Edit”).Type “yes”
Window(“Notepad”).WinEditor(“Edit”).Type micCtrlDwn + “s” + micCtrlUp
Window(“Notepad”).Dialog(“Save As”).WinEdit(“File name:”).Set “test”
Window(“Notepad”).Dialog(“Save As”).WinButton(“Save”).Click

Above sample script will open notepad type yes and save as named test at default location.

Note: This is just sample script, This will not work if you just copy and paste it to QTP. You have to first record it. Please Refer to know how to record above script : Getting started to QTP.

Sample QTP script 2:

SystemUtil.Run “http://google.com/“,””,””,””Browser(“Google”).Page(“Google”).WebEdit(“q”).Set “mba”Browser(“Google”).Page(“Google”).WebEdit(“q”).SubmitBrowser(“Google”).Page(“mba – Google Search”).SyncBrowser(“Google”).Close

Above sample script will open google.com and type mba in search box and close it.

Note: This is just sample script, This will not work if you just copy and paste it to QTP. You have to first record it. When you record any webpage its objects will be automatically stored to object repository. Please Refer to know how to record above script : Learn to Automate Webpage.
Visit here to get detail knowledge of QTP object Repository and Learn QTP Step by Step.
Keep visiting this blog, I will share some more advance QTP VB script examples. You are always welcome to give feedback that will improve my blog. I am always trying to give 100% perfect knowledge about QTP.

If you like this article, You can subscribe through mail.

39 thoughts on “QTP scripts examples for beginner

  1. Anonymous

    Hi,

    Good Stuff.
    Can you please provide one example script for Login page where all the conditions are applied like…
    1)Leaving Username/password field blank.
    2) Entering wrong username/password.
    3) Entering valid login details.

    Actually these are some test cases that i want to convert to qtp script. could you please use the login page of simple flight application and provide the script so that i can follow the guidelines and proceed further.

    Thanks in advance

    Reply
  2. Neelkanth

    Hi,

    You have to record the script on your web application in different scenario,
    1. Just click on login without entering Username and password.
    2. Enter wrong user name and password and then see how your web application reacts it gives pop-up window or any message to enter valid user name.
    3. Enter valid user name and password and then click on login.

    You can apply your logic to combine above three different scenario.

    I hope your doubt is solved, Let me know in case of any issue.

    Thanks,
    Neelkanth

    Reply
  3. Anonymous

    Hi Neelkanth,

    I did like the way u said…

    I recorded the script as follows:

    ‘Blank Username and Password
    Dialog(“Login”).Activate
    Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
    Dialog(“Login”).WinEdit(“Password:”).Type micTab
    Dialog(“Login”).WinButton(“OK”).Click
    Dialog(“Login”).Dialog(“Flight Reservations”).Activate
    Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click

    ‘Again leaves Username field blank
    Dialog(“Login”).WinEdit(“Agent Name:”).Type micTab
    Dialog(“Login”).WinEdit(“Password:”).SetSecure “4ab7a2d45ab7f90a0279430e6836a126be044819”
    Dialog(“Login”).WinButton(“OK”).Click
    Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click

    ‘Enters valid Username
    Dialog(“Login”).WinEdit(“Agent Name:”).Set “xyz”

    ‘Again enters invalid Password and then Valid password
    Dialog(“Login”).WinEdit(“Password:”).SetSecure “4ab7a30e3dbc0045618cadbeddd91a436bba513d3632”
    Dialog(“Login”).WinButton(“OK”).Click
    Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
    Dialog(“Login”).WinEdit(“Password:”).SetSecure “4ab7a3162eda9514506206d258cec02e4e57fb1f”
    Dialog(“Login”).WinButton(“OK”).Click

    I just ran the script and it was successful. Let me know if i am going in right direction or is there any other way of doing it…Like using “IF…EndIF” loop.
    And if there is any please guide me.

    Thanks in advance

    Reply
  4. Neelkanth

    Good,
    Now you can put checkpoints as you want, like when you login with valid user name and password then put checkpoints which verify that login is successfully done. You can put different types of checkpoints. Please go through checkpoint post and then go through “Step by Step procedure to getting started with QTP” post. This post is very useful for beginner like you.
    If you still find any issue than mail me at quicklearnqtp@gmail.com.
    Practice as much as you can.
    Best Luck!!

    Reply
  5. raphael

    Greetings,

    I have to create a QTP script that will populate the following webedits:
    Email Address
    Re-enter Email Address
    Member Name
    Choose Password
    Re-enter Password

    then click submit button.

    Here is the tricky part. The script must loop and the text for the Email Address, Re-enter Email Address, and Member Name must be different in every single iteration.

    Any ideas?

    Reply
  6. Anonymous

    Not so much hard,

    If you want to enter 50 entries, than put that entries in excel sheet or csv file and parse it with VB script, so you will get three things email address,password and member name. Then pass this as a argument to the QTP function.

    Try this and let me know.

    Reply
  7. Shetty

    This is shetty I too working in QTP any queries/trainings required call me 8008866693,I am staying in Hyderabad

    Reply
  8. Anonymous

    Hi shetty,

    This is Srilatha.I want to know QTP just i am beginner, if u provide any training then i want to join with u.plz tel me ur contact no and mail id as early as possible.

    Thanks&Regards,
    Srilatha.

    Reply
  9. Anonymous

    Hi shetty,

    This is Srilatha.I want to know QTP just i am beginner, if u provide any training then i want to join with u.plz tel me ur contact no and mail id as early as possible.

    Thanks&Regards,
    Srilatha.

    Reply
  10. Anonymous

    Hi,
    I am a beginner in QTP and im using QTP 11.0 verion,i tried automating google search with some word typed in it,but when i run the test its not showing me the script for the word which i’d entered.could you please guide me

    Thanks in advance.

    Reply
  11. KathyJ

    What does the “mic” part of the MicCtrlUp mean? I have seen that other places, too, referring to keyboard actions (e.g., micTab) and wonder what the “mic” part means. Searching online has not yielded any explanation, just more examples.

    Reply
  12. Jan

    @ KathyJ,
    To the best of my knowledge MIC means “Mercury Interactive Control”

    Reply
  13. Cryptolog

    Hi Guys,
    you are doing really good,
    I am on a project, and honestly it is my FIRST project in this area (I mean Software Testing).I need your help;
    My assignment is;
    In stall and configure a reference computer (OS,drivers,patches,updates and 3rd party applications and other applications) and create a vbscript and convert it to .EXE (for using it on the other computers) and TEST them all.
    Ccan you give me some ideas/helps how can I do that.Thank you.

    Reply
  14. sathish.M

    hi friends..
    this is sathish
    iam having 3+ of experience in manual testing and in automation (QTP)..
    also am having experience in online training..
    and one advantage is i will give training on SQL also free of cost..

    totally real time scenarios will be provided and resume preparation and material will be provided.

    if any one is interested let me know
    send me a mail @ maddelasathish@gmail.com
    9963253168

    Reply
  15. sathish.M

    hi
    srilatha,
    this is sathish..
    iam having 3+ of experience in manual and automation..
    online training will be provided..with low cost
    SQL training also will be provided its free of cost..just conatct me @maddelasathish2gmail.com
    9963253168

    Reply
  16. Anonymous

    Can anyone tell me the solution for the 2 errors which is mentioned at the end of the script?

    Set objDialog=Description.Create
    objDialog(“micclass”).value=”Dialog”
    objDialog(“text”).value=”Login”

    Set objAN=Description.Create
    objAN(“micclass”).value=”WinEdit”
    objAN(“attached text”).value=”Agent Name:”

    Set objPW=Description.Create
    objPW(“micclass”).value=”WinEdit”
    objPW(“attached text”).value=”Password:”

    Set objOK=Description.Create
    objOK(“micclass”).value=”WinButton”
    objOK(“text”).value=”OK”

    Set objFR=Description.Create
    objFR(“micclass”).value=”Dialog”
    objFR(“text”).value=”Flight Reservation”

    Set objErrMsg=Description.Create
    objErrMsg(“micclass”).value=”Static”
    objErrMsg(“native class”).value=”Static”

    Set objCL=Description.Create
    objCL(“micclass”).value=”WinButton”
    objCL(“text”).value=”Cancel”

    Dialog(objDialog).Activate
    wait 1
    Dialog(objDialog).WinEdit(objAN).Set “brij”
    wait 1
    Dialog(objDialog).WinEdit(objPW).Set “mercury1”
    wait 1
    Dialog(objDialog).WinButton(objOK).Click
    wait 1
    var_ErrMsg = Dialog(objDialog).Dialog(objFR).Static(objErrMsg).GetROProperty(“text”)
    If var_ErrMsg = “Incorrect password. Please try again” Then
    print “Passed”
    Reporter.ReportEvent micPass,”Verify Incorrect Password”, ” Enter incorrect password and check if the Error message = Incorrect password. Please try again”
    else
    print “Failed”
    Reporter.ReportEvent micFail,”Verify Incorrect Password”, ” Enter incorrect password and check if the Error message = Incorrect password. Please try again”
    End If
    wait 2
    Dialog(objDialog).Dialog(objFR).WinButton(objOK).Click
    wait 2
    Dialog(objDialog).WinButton(objCL).Click
    wait 1

    1.Cannot find the “[ Static ]” object’s parent “[ Dialog ]” (class Dialog). Verify that parent properties match an object currently displayed in your application.

    Line (37): “var_ErrMsg = Dialog(objDialog).Dialog(objFR).Static(objErrMsg).GetROProperty(“text”)”.

    Tip: If the objects in your application have changed, the Maintenance Run Mode can
    help you identify and update your steps and/or the objects in your repository.

    2.Cannot find the “[ WinButton ]” object’s parent “[ Dialog ]” (class Dialog). Verify that parent properties match an object currently displayed in your application.

    Line (46): “Dialog(objDialog).Dialog(objFR).WinButton(objOK).Click”.

    Tip: If the objects in your application have changed, the Maintenance Run Mode can
    help you identify and update your steps and/or the objects in your repository.

    Reply
    1. Narendra S

      Close the application and open it again qtp won’t detect the previous running programs.

      Reply
  17. Anonymous

    Hi,
    can anybody tell me concept of framework. Where and how to use it. I beginer to qtp.
    Plz plz plz explain i am confused.

    Reply
  18. deepa

    Hi all,
    ‘m just beginner in QTP can u mail me the study materials,
    ‘m not getting scripting part in QTP.

    Thank you,
    Deepa

    Reply
  19. Nagaraj

    Hi Karthik,

    could you please send me the sample scripts for QTP beginners.

    Reply
  20. lingaraj

    Hi Karthik,

    could you please send me the sample scripts for QTP beginners.

    Reply
  21. Sudipta

    could u plz post the script to register in gmail

    Reply
  22. Kiran

    Hi, could you please sent be a sample of QTP frame work script

    Reply
  23. Subash

    Hi,
    I am Subash I have 1+ years experience in Manual Testing I am willing to learn Automation tool Please anyone Suggest me which tool is best for Future Vacancies and career growth!
    Thanks

    Reply
  24. shalini

    Hi,

    I am trying to find out a script for login gmail and the case is…
    As i open the IE browser get default browse dialog with message ” Do you want to make IE as default browser”, and this is not sure when it will get this dialog,that means it may be get as quick as open the browser or it may get after hit the browser. so this is very difficult to handle. Please Provide me any script for that.

    Reply
  25. nidhi

    hi,
    i m a beginner in qtp..i m not getting the study material which is easy to understand and work with..plz send me some samples wid examples wid procedure..my email address is-nidhisaraf2009@gmail.com
    thanking all

    Reply
  26. Pallavi

    hi am learning QTP scripting. can u plss plsss send me study material for scripting and frame work

    Reply
  27. Vaibhav Chaurasia

    Script for gmail login :

    ​Set IE=CreateObject(“InternetExplorer.Application”)
    IE.Visible=True
    IE.Navigate “http://www.gmail.com”

    Browser(“Title:=Gmail.*”).Page(“Title:=Gmail.*”).Sync

    Browser(“Title:=Gmail.*”).Page(“Title:=Gmail.*”).WebEdit(“name:=Email”).Set
    “abc@gmail.com”
    Browser(“Title:=Gmail.*”).Page(“Title:=Gmail.*”).WebEdit(“name:=Passwd”).Set
    “12345”
    Browser(“Title:=Gmail.*”).Page(“Title:=Gmail.*”).WebButton(“name:=Sign
    In”).click

    Browser(“Title:=Gmail.*”).Page(“Title:=Gmail.*”).Sync

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *