site
stats
By Anish Pillai Anish Pillai Posted under QTP Concepts | QTP Framework

QTP Frameworks : Designing QTP Modular Framework from scratch

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

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.

'- - - - - 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..




If you enjoyed this article, you can join our blog to get new articles delivered directly in your inbox.

Visit QTP Frameworks Main Page more articles on QTP Frameworks. You can also visit our QTP Tutorials page for more QTP Tutorials.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • Amit

    Hi Anish

    Thanks for the wonderful article. Please send me the code with example of Modular+data driven approach

    Regards
    Amit
    (email id removed)

    • Anish10110

      Hi Amit,

      I have emailed you the code for Modular Framework. Please let me know if you face any issues with it.

      Also no need for mentioning the mail id in the comments. This can be misused by spammers. While commenting, if you provide your id in the email field, i will receive it through email.. 🙂

    • vikas

      HI,
      Can you send me the code of modular frame work…..

      • Anish10110

        emailed you the code..

  • Pingback: QTP Frameworks – An Introduction - Automation Repository - Automation Repository()

  • Praveen

    Hi, This is really helpful. May i hav sample code of this.

    • Anish10110

      Hi Praveen,

      I have emailed you the code. Please let me know if you have any doubts/issues with it.

  • mamatha

    Hi Anisha

    Thanks for the article. Please send me the code with example of Modular+Functional decomposition and keyword driven frame work.

    • Anish10110

      Hi Mamatha,

      I have emailed you the code for functional decomposition framework. Please have a look at it and let me know if you have any queries. I'm still working on keyword driven framework code. Once done, I will definitely share the code.

  • Aman

    Hi anish,
    It is possible for you to email the code for the modular automation framework? Thank you.

    • Anish10110

      Hi Aman, Mailed you the code. Please have a look at it and let me know if you have any queries.

  • Hi Anish

    Thanks for the wonderful article. Please send me the code with example of Modular+data driven approach

    Thanks,
    Rahul
    <email id removed>

    • Anish10110

      Hi Rahul,

      I have emailed you the complete code for Modular Framework. Please let me know if you have any issues with the code.

      • gajendra

        could you please send me the framework for Keyword driven approach to jbs.gajendra@gmail.com?

        • Anish10110

          Gajendra, I am still working on Keyword Approach and its not completed yet. I will send it to you once its ready.

  • ammu

    Hi Anish

    I Clarified lot of doubts from your blog it is a wonderful blog. Please send me the code with example of Modular+data driven approach
    amrutharaju9@gmail.com

    Thanks,
    Amruth

  • ammu

    Hi Anish

    I Clarified lot of doubts from your blog it is a wonderful blog. Please send me the code with example of Modular+data driven approach
    amrutharaju9@gmail.com

    Thanks,

    • Anish10110

      Hi Amruth, thanks for the appreciation.. 🙂 I have emailed you the code for modular framework. Please have a look at it and let me know if you have any queries.

  • Krishna

    Hello Anish,
    Thanks for a wonderful post. can you help us in providing the sample code so that we can practice
    – Kris

    • Anish10110

      i have emailed you the code…

  • vidyasagar

    Can you please send the sample code for Modular framework

    • Anish10110

      I have emailed you the code..

  • Pingback: Data Driven Framework in QTP : The Complete Guide – Part 1 - Automation Repository - Automation Repository()

  • Prashant

    Hi,

    I too use modular test framework approach in our proiect..
    but i would like to review one of my approach from you.

    i have modularise operation like clicking on btn, getting the value from text box…etc.
    I.e i have written functions for each operation.

    Is this a gud approach ?
    let me know your thought on this..

    • Anish10110

      Hi Prashant,
      This is a very good approach and even we are using it in all our projects. The modular framework code that i have uploaded is a basic version just to provide an idea of how things work. So I didn't use the concept you mentioned in this framework.

      In our project, we are using function like fnClick and then binding it to different controls using RegisterUserFunc. We are using different alias names like fnButtonClick, fnLinkClick, fnImageClick etc and all of them point to the same function – fnClick. Are you using a similar approach or using separate click functions for different objects like button, link etc?

  • Srikanth

    Hi Anish,

    Can you please share the code to the email id that i subscribed.

    Thanks

    • Anish10110

      Hi Srikanth, I have emailed you the sample code. Please let us know in case of any issues.

  • Pupun

    Hi Anish

    Thanks for the article. Can you send me the code with example of Modular+data driven approach

    Thanks,
    Pupun

  • Pingback: Basics of Keyword Driven Framework in QTP - Automation Repository()

  • Abhishek

    Dear Anish….Your blog is wonderful. I really appreciate the way you convey the explanation.
    You truely deserve an appreciation.

    • Anish10110

      Thank you Abhishek.. 🙂

  • prashant

    Hi Anish

    Excellent work…..It is really awesome
    Please send me the code with example of Modular+data driven approach

    Thanks

  • shankar

    Hi Anish

    Can you please share the code to the email id that i subscribed.

    Thanks

    • Anish10110

      I have emailed the code to you. Please reply back if you face any sort of issues with it.

      • pupun

        i didn't receive any email from you Anish.

        • Anish10110

          I have sent you an email now. Please check and confirm..

  • Vinod

    Hey Anish,

    Could I also have the code for the modular and data dirven framework? My email ID is vinocj@gmail.com.

    Thanks a ton Anish.

  • Pingback: Keyword Driven Framework in QTP | QTP Framework()

  • durga

    hi

    It is really awesome …Excellent work

    • Anish10110

      Thank You.. 🙂

  • Pingback: Designing Keyword Driven Framework mapped at Functional Level – Part 1 - Automation Repository - Automation Repository()

  • sneha singh

    hii cn u send me code for modular+driven

  • nai

    thank you

  • Venkat

    Hi Anish,
    Can you mail me the sample code of modular test automation frame work and other frame works like Data Driven frame work, keyword driven frame work, hybrid frame work and BPT frame work.

    Thanks,
    Venkat.

  • Girish

    Hi Anish,

    Can u please send me the code to create dash board and Pie chart for passed and failed criteria.

    Thanks,
    Girish

    • Anish10110

      Hi Girish,

      I have not worked on this feature. So I wont be able to provide any code for this. Try to see if you find something on the internet. There should be some good reporting functionalities available.

  • Pingback: complete real time scripts of qtp « TESTING HUB()

  • Pradeep Singh

    Could you send me please the result or reporting excel file or any other file which you use to report the result ? I want to see how it is really used in Industry. Right now I am using excel reporting but dont know (also confuse) whether it is right way or should I use different approach?

    • Anish10110

      Hi Pradeep,

      Even I'm using excel for reporting. And there is no specific format which I use. It mostly depends upon the project only. Also I'm not aware if there are any industry specific standards around this. But I have also seen many people using HTML files for reporting, which in many cases has been pretty good.

  • Azhar Jafri

    Hello anish , ur blog is very helpful. Can u plz mail me the code for modular + data driven framework . It ll be very helpful for my learning 🙂

    My email Id is jafri.azhar7@gmail.com

    Thanks a ton sir !!

    • Anish10110

      emailed you the framework codes.

  • kavya

    Hi Anish, your explanation is very good and easy to follow…Thanks a lot for posting this. Iam not able to download code. can u pls mail me the code for modular, data driven and keyword driven frameworks.

    • Anish10110

      emailed to you…

  • Sapna

    Hi Anish,

    Really good explanation. Thanks for posting it.. Also can you please fwd me modular, data driven and keyword driven frameworks. I am working on a project and need to start from scrach on my own.

    Thanks

    • Anish10110

      Hi,

      I have emailed you the frameworks.

  • anand

    how to retrieve data from all the college’s email id and paste in excel sheet using qtp http://www.indiacollegesearch.com/ page page page

  • soumya

    Hi Anish,

    can u please send me the script for modular framework.

    • Anish10110

      Hi Soumya, Emailed you the code..

  • Ryan

    Hi Anish,

    Please forward me the data driven framework code . The code in which i want to read and write multiple values from excel sheets only.

    Thanks in advance.

    • Anish10110

      emailed you the code

  • Srinu Raghupatruni

    Hi Anish

    Could you please send me the script for the modular framework
    Thanks in Advance

  • Pingback: Designing Hybrid Framework in QTP - Part 4 [Final Part] - Automation Repository - Automation Repository()

  • Ajinder Singh

    Hi Anish

    Thanks for helping people in learning automation.
    Could you please send me the script for the hybrid and modular framework
    Thanks in Advance

  • Stephan Coetzee

    Hi Anish.

    Thank you for the informative article on modular programming.

    I do however have one question: What is the best way to update the function library if I were to update object names in the OR (Object Repository)? According to me the function library is not automatically updated when making changes to the OR, which would mean that I will have to update the function library manually every time objects' name or position changes inside the OR.

    To overcome this problem I am currently storing all of my re-usable actions (i.e. functions that references the objects in the OR) in a QTP script. This QTP script then serves as my library for re-usable actions. Then I reference these re-usable actions in all of my other QTP scripts.

    I currently only use my external function library to store functions that don't reference the OR (e.g. mathematical/date functions). I do this because then there is no need to manually update the function library every time the objects in the OR is updated.

    Any comments on this will be appreciated.

    Regards, Stephan Coetzee

    • Hi Stephan,

      Your point is absolutely correct.. In these kind of situations I use 'find and replace all' one by one on the objects where there was a name change..

      And your method of putting these reusable functions in a QTP test is also good..

      I think if there is a high probability of such changes happening in the code.. then I would also prefer your approach…

      • Stephan Coetzee

        Hi Anish,

        Thank you for the reply.

        I guess it is safe to say that both approaches have both advantages & disadvantages.

        Saving the re-usable actions in a function library:
        Advantage: Calling these functions is very fast while executing a QTP script. The loading of the function library is also very quick. Disadvantage: Maintenance/updates of the functions is manual (i.e. copy & replace).

        Saving the re-usable actions in a QTP test:

        Advantage: The code is updated automatically when making changes to the OR.
        Disadvantage: The call to re-usable actions (which are stored in a QTP script) are much slower during runtime than it is to call re-usable actions from a function library.

        I guess its a toss-up between ease of maintenance vs script execution speed.

    • Santhosh

      Hi Stephan, Could you please share the script details or clear steps like how you are calling your reusable actions in your framework, as currently i'm using function library to recall and not sure how the action can be called in a framework.

      Thanks in advance.

      Cheers,
      Santhosh

  • Sachin

    Hi Anish,

    can u please send me the script for modular framework.

  • Arjun

    Hi Anish,
    Thanks helping people….please send code for modular and data driven and keyword framework.
    Thanks in advance…

  • sai goutham

    MAy i know the difference between the comibantion of datadriven + keyword & datadriven+modular frameworks

  • amey24

    Hi Anish,

    Can you pls send me the script for Modular framework

  • Alex Makhalane

    Very well put !! 🙂

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×