QTP


URL:




QTP Frameworks : Designing QTP Modular Framework from scratch

April 11th, 2012 | Posted by Anish Pillai in QTP Concepts | QTP Framework
In the last article, you had seen how to create test scripts using QTP’s Linear Framework approach. The article discussed its advantages & disadvantages and covered the various components used to design the linear framework. We will now move a step further and discuss QTP’s Modular Framework and see how it overcomes some of the shortcomings of the linear framework approach.
UPDATES
1) You are free to download and play around with the code used for this framework. The download link is available at the end of the article.
2) Just like this, we have written more articles on various other QTP Frameworks. If you wish to have a look at those, please visit QTP Framework main page. The bottom of the page contains links to other QTP Frameworks.

What will be covered in this article?

This article will cover the following aspects of QTP Modular Framework -
  • a) What is QTP Modular Framework and how is it different from the Linear Approach?
  • b) Different components involved in Modular Framework Design.
  • c) Designing QTP Modular Framework from scratch.
  • d) Advantages and Disadvantages of Modular Framework approach.
  • e) Sample Scripts.

Let us discuss each of these aspects in detail.

Why you need QTP Modular Framework?

Before we begin explaining the Modular Framework, let us first revisit the most important disadvantage of linear framework. The most important disadvantage of linear framework is that it lacks re-usability. This lack of re-usability can be classified into 2 types -
QTP Linear Framework Limitations
a) Lack of Code Re-usability. Since the code in the Linear Framework in written step by step in a linear manner, you can’t really reuse it at different places without copy pasting it. We use modular framework approach to overcome this shortcoming of linear framework.
b) Lack of Data Re-usability. You have this limitation in Linear Framework because the data is hard-coded within your script. Hence we can’t use the same code with multiple data values. You can overcome this shortcoming by using Data Driven approach.

What is QTP Modular Framework?

QTP Modular Framework (also known as Functional Decomposition Framework) is the approach where you first identify the re-usable code from your test cases. Then you write this re-usable code inside different functions and call these functions wherever required. The advantage of this approach is that the re-usable code would always stay at one place and thus it would be easy to maintain the code because you would have to make the changes at a single place only. To re-use this piece of code, all you have to do is call the function wherever required.
The only challenging part here is to identify the reusable portions in your test case flow. Once that is done, you have to just create functions and use it wherever required. Let us see an example which would help you understand this concept more clearly.
Consider this scenario where you have to automate 2 test cases. In the first test case, you have to login to the application, create an order and then logout. In the second test case, you have to again login, then you have to modify an existing order and then logout.
Can you identify the re-usable flows from the above 2 test cases? Yes, from the above test cases we can clearly see that there are 2 different re-usable flows that are used in both these test cases – Login and Logout. Let’s see how the flow would look like in the Modular Framework approach.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'- - - - - Login Function - - - - -
Function fnLogin()
  'Open Application
  'Enter Used Id and password
  'Click on Login button
  'Verify successful login
End Function

'- - - - - Logout Function - - - - -
Function fnLogout()
  'Logout from the application
  'Verify Logout is successful
  'Close the application
End Function

'===== Test Case 1 - Create Order =====
'Call Login function
fnLogin()

'Code to create order
' ..........
' ..........
' ..........

'Call Logout function
fnLogout()

'===== Test Case 2 - Modify Order =====
'Call Login function
fnLogin()

'Code to modify order
' ..........
' ..........
' ..........

'Call Logout function
fnLogout()

Different Components involved in QTP Modular Framework

The below image shows the different components that you would mostly use in a Modular or Functional Decomposition Framework.
QTP Modular Framework Components
a) Object Repository: You can use a shared object repository that would store the objects and its properties. You can avoid using this component if you use Descriptive Programming to write your test scripts.
b) Function Library: This would be an external file which would contain all the re-usable functions like Login, Logout etc. This external file can have .vbs, .txt or .qfl extension.
c) Test Scripts: You can have multiple test scripts which would cater to different test cases. You have to associate or map each of your test cases to the function library so that the test cases can call the functions from the function library.

Designing QTP Modular Framework from scratch

Below are few generic points that would assist you to design a basic Modular Framework and then build it up from there.
Step 1) Analyze Manual Test Cases and identify the reusable functions/ flows. Before you actually start building your modular framework, the first task that you should ideally do is to analyze your manual test cases (that have been identified for automation) and note down all the flows that you think are reusable.
The reason why this is important is that once you have the list of reusable flows ready with you, you would script for the flow keeping the re-usability factor in mind. That is, you would know that this flow is reusable and thus you would try to make it as generic as possible so that it can be re-used with other test cases without much changes.
If you don’t do this activity then there is a possibility that you would write the flow as it is in the test case (i.e. you might not create a function for it). Later when you see that the same flow is being used re-used in some other test case, you would then need to change the previous test cases also where you wrote the code as it is. All this will lead to wastage of time for modifying the scripts.
Example (Sample Scenarios): As part of designing the Modular Framework from scratch, we will take a couple of scenarios from GMail which we will automate using the Modular Framework approach.
Test Case 1: Login to Gmail >> Find the number of mails you received today >> Logout from Gmail.
Test Case 2: Login to Gmail >> Find the number of unread emails in the inbox >> Logout from Gmail.
As part of QTP Modular Framework design, we will create 2 test scripts in QTP for the above mentioned scenarios. As you have seen above, the first task that you should do is to identify the re-usable flows from the test cases identified for automation.
From the above scenarios, you can clearly identify 2 reusable flows – Login to Gmail and Logout from Gmail. which will be used in both the test cases. Once you have identified all the reusable flows, you can now move over to the next step shown below.


Step 2) Writing the first Test Script and creating Re-usable Functions: Now, the task is to write your first script in QTP which should include the reusable flows (Login and Logout flows in this case). A very simple process of doing this task is shown below.
a) First of all write the entire test script in QTP as if you were writing a test script in Linear QTP Framework design. So you will have all the code (login, checking for mails received today and logout) written step by step one after the other.
b) In case the test script is very big with lots of lines of code, you can write a few lines of code and then unit test it to verify that this chunk of code is working fine. Once you have confirmed that this code doesn’t contain any errors, you can start writing the next set of code.
c) Run the entire flow and see if it is running fine without any errors. This step would ensure that the logic you have scripted is working fine.
d) Now is the time when you create the re-usable functions. Since you have already written the code, just create a new function inside the action and cut paste the code into it (see the below image for illustration). That is, you create a function named fnLogin() and cut-paste the login code inside this function. Do the same for other re-usable flows in the test case (Logout in this example).
e) Call the re-usable function in appropriate places (places from where you cut the code).
f) At this point, your test case is written according to modular framework approach (with re-usable function calls). Run the test script and make sure that your code with function calls works fine.
NOTE 1: One important point to note here is that the you are saving the reusable function in the same test script only. With this method, these re-usable functions will not be available to the other test scripts. So we have to store these functions in some external file and map (or associate) this function library to all the test cases that want to use the re-usable functions.
g) Create a new function library. Cut-paste the re-usable functions from your action into this new function library. Save the function library and associate it with your test script. (Read the 4th method on how to associate function library to a QTP script)
h) Now at this stage your re-usable functions are getting called from the function library and test case specific code is available in the test case action. Run this test case now and make sure that it runs correctly.
You have now written a test script using QTP Modular Framework approach. :–) Check the below image which would help you understand the above steps (points a to h) more clearly.
·         Flow to create reusable functions in QTP

Step 3: Writing more test scripts and updating the function library in the process. Since you have already written the first test script, writing the remaining ones is a very straightforward task. You will mostly be following the points that we had covered in Step 2. Lets briefly see what you have to do here.
a) Create a new test case in QTP. And associate the shared function library (created in step 2g) to this test case.
b) In this test case we have to count the number of unread mails in the inbox. Since login function has already been created, just call this function in your test case. (At this point, you might want to run the test case and see that the login functionality is working fine for this test case also).
c) After calling the login function, write the code to count the number of unread mails. Then call the logout function.
d) Run your test script and see that it should work fine without any issues.
NOTE 2: Since in this test script, we had to only use the pre-created functions (login and logout), we just called this functions from the shared function library. If you are required to create some other reusable function in this test case, you can do it the same way as discussed in step 2 (writing it in test script first, then creating a function and saving it in the test script itself, and finally adding this function in the function library).
You can use the above mentioned approach (in step 2 and step 3) to write all your test scripts according in QTP modular framework design.
NOTE 3: To create a reusable function, we have advised that you first add it in the main script then move it to the function library once it is working fine from the main test case. This approach is suggested because it is easier to create and debug functions from the main script due to intellisense and other such options which assist you in scripting. Once you are familiar and comfortable with creating functions, you can directly start writing them in the function library itself.

QTP Modular Framework – Advantages and Disadvantages

Advantages
  • a) The amount of time spent on coding is lesser as you are creating re-usable functions and calling them wherever required.
  • b) Script maintenance is relatively easier because the re-usable code is available at a single place only no matter how many times it is called. If there is a change in any re-usable function, you would be required to make the changes at only one place.

Disadvantages
  • a) Additional time spent in analyzing the manual test cases to find out the reusable flows. This is not required in linear framework.
  • b) Users need more technical expertise in automation to work on modular frameworks.
  • c) In case you use only modular framework, the data will still be hard coded in the script only. So you can’t use the same test script for multiple data without changing the values before each run.


NOTE 4: The main issues with linear framework were lack of code re-usability and data re-usability. QTP Modular Framework solves only one of these limitations. The other limitation (data re-usability) still looms large. So, you cannot use QTP modular framework alone in many of your automation projects (especially if your test cases need to be validated against multiple sets of data). To work on any real life automation project, you should really be looking at using a combination of QTP modular framework + data driven framework.
Whats your thought on this article? Do you see any other components that can be added here? Let us know your comments in the comments section..

4 Different Ways to Associate Function Libraries to your QTP Scripts

September 22nd, 2011 | Posted by Anish Pillai in QTP Basic Stuff
Most of the times, when you are creating test scripts or are designing a new QTP Framework, you would be trying to come up with reusable functions which you would have to store in the function library. Now, in order to use this function library with multiple test cases, you need to associate this function library with your scripts. This article explains the 4 methods that will help you in associating the function libraries in QTP Test Cases.


Based on the type of framework you are using, you can use any of the following methods to associate function libraries to your QTP Script -
  • 1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
  • 2) By using Automation Object Model (AOM).
  • 3) By using ExecuteFile method.
  • 4) using LoadFunctionLibrary method.


Let’s see in detail how each of these methods can be used to map function libraries to your test scripts.

1. Using ‘File > Settings > Resources > Associate Function Library’ option from the Menu bar

This is the most common method used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.
Associate function Library to QTP
Associate function Library to QTP

2. Using AOM (Automation Object Model)

QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.
Example: Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.
1
2
3
4
5
6
7
8
9
10
11
12
13
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True

'Open a test and associate a function library to the test
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries

'If the library is not already associated with the test case, associate it..
If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
  objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
End

3. Using ExecuteFile Method

ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file (function library) are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.
1
2
3
4
5
'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"

'Other logic for your action would come here
'.....

4. Using LoadFunctionLibrary Method

LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.
1
2
3
4
5
6
7
8
'Some code from the action
'.....

LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries

'Other logic for your action would come here
'.....




66 comments:

  1. I have been following your posts regularly. It is very informative that I share it with my students.
    QTP Training Institutes in Chennai

    ReplyDelete
  2. Who wants to learn Informatica with real-time corporate professionals. We are providing practical oriented best Informatica training institute in Chennai. Informatica Training in chennai

    ReplyDelete
  3. I found some useful information in your blog,it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Greens Technologies In Chennai

    ReplyDelete
  4. QTP Training in Chennai
    Thank you for the informative post. It was thoroughly helpful to me. Keep posting more such articles and enlighten us.

    ReplyDelete
  5. Pega Training in Chennai
    Brilliant article. The information I have been searching precisely. It helped me a lot, thanks.
    Keep coming with more such informative article. Would love to follow them.

    ReplyDelete
  6. Greens Technology offer a wide range of training from ASP.NET , SharePoint, Cognos, OBIEE, Websphere, Oracle, DataStage, Datawarehousing, Tibco, SAS, Sap- all Modules, Database Administration, Java and Core Java, C#, VB.NET, SQL Server and Informatica, Bigdata, Unix Shell, Perl scripting, SalesForce , RedHat Linux and Many more.

    ReplyDelete
  7. Thank you For tutorials on Testing and the also the other tutorials on Blog are Awosme, It will be Most Usefull For Fresher and Students

    QTP Online Training | Advanced QTP Online Training | Automation Testing Online Training | HP QTP Online Training

    ReplyDelete

  8. Hai if our training additional way as (IT) trained as individual,you will be able to understand other applications more quickly and continue to build your skll set
    which will assist you in getting hi-tech industry jobs as possible in future courese of action..
    visit this blog webMethods-training in chennai



    ReplyDelete
  9. great article!!!!!This is very importent information for us.I like all content and information.I have read it.You know more about this please visit again.
    QTP Training in Chennai

    ReplyDelete
  10. hai you have to learned to lot of information about oracle rac training Gain the knowledge and hands-on experience you need to successfully design, you have more information visit this site...
    oracle training in chennai

    ReplyDelete
  11. I am very impressed with the article I have just read,so nice.......
    QTP Training in Chennai

    ReplyDelete


  12. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u.

    Selenium Training in Chennai

    ReplyDelete
  13. Good job! Fruitful article. I like this very much. It is very useful for my research. It shows your interest in this topic very well. I hope you will post some more information about the software. Please keep sharing!!
    DevOps Training in Chennai
    DevOps certification Chennai
    DevOps certification
    DevOps Training
    DevOps course in Chennai
    DevOps course

    ReplyDelete
  14. Nice post. I learned some new information. Thanks for sharing.

    Guest posting sites

    linuxhacks

    ReplyDelete
  15. It was really a nice article and I was really impressd by reading this.
    Thank you for such amazing post. Keep up the good work.


    PrimaveraTraining in Velachery
    Primavera Courses in Velachery
    Primavera Training in Tambaram
    Primavera Training in Adyar
    Primavera Courses in Adyar

    ReplyDelete
  16. I wanted to thank you for this great blog! I really enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
    Ethical Hacking Course in Chennai 
    SEO Training in Chennai
    Hacking Course 
    Learn Ethical Hacking 
    SEO Course Chennai
    SEO Training near me

    ReplyDelete
  17. Your blog information are really creative and useful for the readers.I ever read such kind of nice article yet.hope you will add more innovative ideas on your post.
    cloud computing courses near me
    cloud computing Training in chennai
    Cloud Computing Training in Anna Nagar
    Cloud computing Training

    ReplyDelete
  18. A tiny grouping of execs are capable of you manually due to they’re absolute to offer the standard services. So, in the event that you face any issue and your QuickBooks Tech Support you don’t need to go anywhere except us.

    ReplyDelete
  19. Virtually every Small And Medium Company Happens To Be Using QuickBooks Enterprise And Therefore Errors And Problems With Respect To It May Be Often Seen. These Problems And Troubleshooted By The Expert And Technical Team Of QuickBooks Enterprise Support Number Could Be Used To Contact. Commercial And Finance Operating Bodies Usually Avail The Services Of The Quickbook Enterprise Support Being That They Are In Continuous Utilization Of Workbook, Sheets, Account Records, And Payroll Management Sheets

    ReplyDelete
  20. QuickBooks Payroll customer service is available and beneficial to many business owners, accountants, CA, CPA to calculate taxes and pay employees. Types of issues and errors arise the necessity to contact the Intuit Payroll support team using QuickBooks Payroll Tech Support Phone Number.

    ReplyDelete
  21. Any user can try to find available these days payroll update when you head to “employee” menu, selecting “get payroll updates” after which option “update”. Within the window “get payroll updates” you can examine whether you're making use of the latest updates or perhaps not. For every information or update, you can contact QuickBooks Payroll Support USA.

    ReplyDelete

  22. Just dial QuickBooks Technical Support Number and inform us the QuickBooks product name for which you need QuickBooks help by our experts. Our QuickBooks customer care team will guide you for every single product of QuickBooks whether QuickBooks Enterprise Support, Accountant, Pro, and Premier.

    ReplyDelete
  23. A little grouping of execs are capable of you manually due to they’re absolute to offer the standard services. So, if you face any issue with your package you don’t have to go anywhere except us. You simply have to build an easy charge less call on our QuickBooks Support Number variety and rest leave on united states country. No doubt, here you will find the unmatchable services by our supportive technical workers.

    ReplyDelete
  24. Let’s speak about our QuickBooks Enterprise Tech Support Number that'll be quite exciting for you personally all. The advanced QuickBooks Desktop App for QuickBooks Support can now act as an ERP system good for medium scale businesses. QuickBooks Desktop Enterprise is not alike to pro, premier & online versions. Capacity and capability can be the reason behind this.

    ReplyDelete
  25. In today’s scenario men and women have got really busy in their lives and work. They wish to grow and learn as many new things as they possibly can. This drive has initiated a feeling of awareness amongst individuals and so they find ways to invent choices for daily tasks. If you should be a small business owner, you should be conscious of the fact that Payroll calculation does demands lot of time and man force. Then came into existence QuickBooks Technical Support Phone Number and Quickbooks Payroll customer care Phone Number team.

    ReplyDelete
  26. You are able That Whenever You Are Using QuickBooks And Encounter Some Errors Then Do Not Hyper Because QuickBooks Enterprise Technical Support Team Is Present Few Steps Far From You.

    ReplyDelete

  27. Have you been encountering issues in running of QuickBooks Support Phone Number Premier? We urge one to not ever suffer from losses due to longer downtime of your respective QB Premier.

    ReplyDelete
  28. We could also help you with the integration of third-party presentations so that you use QB to its maximum potential. If you'd like to be involved in any application or third-party tool then dial our toll-free QuickBooks Support Phone Number Accounting Support Services.

    ReplyDelete
  29. Concerning easy, could you start supposing like not enough usefulness and flexibility yet this is to ensure QuickBooks Support Number has emphasize wealthy accounting programming? Thus, this item package can without much stretch handle the demands of growing associations.

    ReplyDelete
  30. QuickBooks Tech Support Phone Number client Service can be obtained 24*7 Our Professionals have designed services in a competent means so that they will offer the mandatory techniques to the shoppers.

    ReplyDelete
  31. Getting instant and effective help for any matter of concern is exactly what the user’s desire for. With QuickBooks, you can relax knowing about obtaining the most desirable and efficacious help on every issue that you may encounter yourself with. You just need to avail the help from the technical experts by dialing the QuickBooks Tech Support Number.

    ReplyDelete
  32. Craftsmen also deal with your variety of revenue. Sometimes you don't forecast the precise budget. We've got experienced people to offer the figure. We're going to also provide you with the figure of your respective budget which you can be in the near future from now. This is only possible with QuickBooks Customer Service Number.

    ReplyDelete
  33. Now you can get a sum of benefits with QuickBooks. Proper analyses are done first. The experts find out of the nature associated with trouble. You will definately get a complete knowledge as well. The support specialist will identify the problem. The deep real cause is likely to be found out. All the clients are extremely satisfied with us. We've got many businessmen who burn off our QuickBooks Support service. You can easily come and find the ideal service to your requirements.

    ReplyDelete
  34. QuickBooks is just one of the great accounting software to easily manage all those things. If you employ this great accounting software if you might be struggling with any errors or issues pertaining to QuickBooks like undo reconciliation in QuickBooks online and a lot more. Simply contact our QuickBooks support team through toll-free QuickBooks Tech Support Number.

    ReplyDelete
  35. Search towards the chart of accounts is simple to manage with added search bar right within the chart of accounts. For better information, you can call at QuickBooks Enterprise Technical Support Number.

    ReplyDelete
  36. You might encounter QuickBooks Error Code 6000-301 when wanting to access/troubleshoot/open the company file in your QuickBooks. Your workflow gets hindered with an Error message that says– “QuickBooks Desktop tried to access company file. Please try again.”

    ReplyDelete
  37. The QuickBooks Tech Support Phone Number is toll-free therefore the professional technicians handling your support call may come up with a sudden solution that may permanently solve the glitches.

    ReplyDelete
  38. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Engineering Classes in Mumbai

    ReplyDelete
  39. Banking errors such as Error 9999 can be caused mainly because of several factors which make it important to troubleshoot every possible cause to prevents it from recurring. If you would like to learn How To Resolve Quickbooks Error 9999, you can continue reading this blog.

    ReplyDelete
  40. Be careful, that transaction should not be listed in the list once you disconnect the feed. If you would like to learn How To Troubleshoot Quickbooks Error 9999, you can continue reading this blog.

    ReplyDelete
  41. Quick up the best offer of AWS DevOps Training in Chennai from Infycle Technologies, Excellent software training in Chennai. A massive place to learn other technical courses like Power BI, Cyber Security, Graphic Design and Animation, Block Security, Java, Oracle, Python, Big data, Azure, Python, Manual and Automation Testing, DevOps, Medical Coding etc., with outstanding training with experienced trainers with a fresh environment with 100+ Live Practical Sessions and Real-Time scenario after the finalisation of the course the trainee will able to get through the interview in top MNC’s with an amazing package for more enquiry approach us on 7504633633, 7502633633

    ReplyDelete