Results 1 to 9 of 9

Thread: User defined function in QTP library

  1. #1
    Expert Member
    Join Date
    Oct 2006
    Answers
    209

    User defined function in QTP library

    How to put any user defined function in QTP library? Now this function should become inbuilt function and can be used anytime I use QTP. Is this possible? If yes then how?

    NOTE : [This question was asked by Renu]


  2. #2
    Junior Member
    Join Date
    Apr 2006
    Answers
    7

    Re: User defined function in QTP library

    Yes this possible..
    You have to write the function in a note pad and save it in Test settings >resource tab as an attachment.
    Then you can call the function in ur program.
    You can write as many functions as u can in that note pad nas save.
    Thanks
    Prasanna


  3. #3
    Junior Member
    Join Date
    Jan 2007
    Answers
    3

    Thumbs up Re: User defined function in QTP library

    Quote Originally Posted by JobHelper View Post
    How to put any user defined function in QTP library? Now this function should become inbuilt function and can be used anytime I use QTP. Is this possible? If yes then how?

    NOTE : [This question was asked by Renu]
    hi friend this is ramu iam happy to answer u r question .first let me explain what is function the actions which are more repeatable for that we are defyining as in function and we are calling that functions very freequently whereever we want . the main advantage of function is code reasubility
    to make use define function first of all make one script with function and run it in qtp to find logical errors and copy that script and paste it in notepad file with .vbs extention again come back to qtp and load that script using
    executefile"filepath" u can load this file any where i hope u got the answer
    if u have any query please consult me


  4. #4
    Junior Member
    Join Date
    Aug 2006
    Answers
    8

    Re: User defined function in QTP library

    Hi Prasanna,
    A very good thing you have mentioned in your above post.

    But i don't think this is the reply to the post. The approach you said is "adding a user defined library function or functions to your script."
    We can have a library file and we can use it at any time.

    But now my concern is how can we make a permanent function like "MsgBox".
    We can use it in any script, no need to attach any file.
    are you getting me,..

    I think there might be some approach for creating any ".dll" file and to register..
    I hope people will come up with any idea for this post.

    Let me know if i am wrong.

    Thanks, Jitu


  5. #5
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: User defined function in QTP library

    Hi All,

    There is an alternate way to make available a user defined function for all tests (as a build-in function). This approach doesn’t require a function library to be associated to a test. We need not to work with .vbs files and execute or include them in our QTP script either. This is a good approach but could be risky.

    We can copy our function definition (in VBScript) to common.txt file in Program Files\Mercury Interactive\QuickTest Professional\dat\BPT_Resources. We may even register this function to a windows or web object. Be careful not to change any other content from the text file. This is a text content, but it contains the definitions of the built-in functions for QTP. Don’t do it if you don’t know VBScript coz if you change any other content from the file knowingly or unknowingly, you should be able to correct the changes. It is better to keep a copy of the original file before you copy your function definition into the file… just in case.

    After you copy your function definition, save and close the file. Close QTP and restart it again. Now, your user defined function should be available for all tests as a built-in function.

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  6. #6
    Expert Member
    Join Date
    Jun 2008
    Answers
    204

    Re: User defined function in QTP library

    prasanna.sabat ,

    If I have a function "test" in a file which saved as myfunctiontest.vbs and loaded to test|Setting|Resource, How do I call the function?


  7. #7
    Junior Member
    Join Date
    Jul 2009
    Answers
    1

    Re: User defined function in QTP library

    Hi All,

    I am new to QTP. I am trying to write functions in QTP. Help me with the basics to write functions.

    Thanks
    Ameesha


  8. #8
    Expert Member
    Join Date
    Apr 2008
    Answers
    1,859

    Re: User defined function in QTP library

    hai friend,

    Here is the sample to write a function.

    Set obj_WebEdit = Description.Create()
    obj_WebEdit ("Class Name").value = "WebEdit"
    obj_WebEdit ("name").value= strWebEdit1
    obj_WebEdit ("html tag").value="INPUT"
    Browser(strBrow1).Page(strPage1).WebEdit(obj_WebEdit).Set strInValue1

    1. You should convert the above script as a function.
    2. Save the above script with .vbs extension
    3. Attach the function in the File->Settings ->Resources
    4. Then call the function where ever necessary.

    Thanks
    Deepa

    Arise Awake And Stop Not Till The Goal Is Reached

  9. #9
    Junior Member
    Join Date
    Sep 2009
    Answers
    1

    Re: User defined function in QTP library

    Yes user defined function in qtp is possible. How we can do that. I will give you one small example. Being on qtp , click file-> new->test->"test". Test will be your file name. Next again file->new->function library->"testfunction.qfl". Next is being on "testfunction.qfl" insert-> "functiondefinitiongenerator" . Inside the function definition generator window, select tab -> function generator and type name of function as "my_sum". From right hand side argument click on "+" symbol and pass arg1 , arg2 by clicking twice in "+" symbol. Click on additional information tab and supply name as "addition function" and click ok to close the function definition generator window. Being on file "test function.qfl -> select file menu-> associate library function with "test"-> click on it. Now open file test->and type as my_sum 1,3 and click on run to execute the script, it will print the result as 4, hence the assumption is my_sum is now become public and it can be associate with any test to get the result. /cheers jayanta


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact