|
||||||||||||||||||
Test automation involves creating of many test cases and scripts to fulfill the testing requirements. Maintaining those scripts and test cases is very important. Script maintenance involves better planning on categorizing scripts based on usage and modularizing scripts based on application under test. While automating an application we should also keep in mind that the application might change in future versions. Automation will be successful when it offers more flexibility to future application changes, so that the scripts can be easily modified. In this paper we will present how the script maintenance can be made simple by creating reusable scripts with QEngine. Also we will detail how power of jython and Java API can be used inside the scripting. Introduction:The purpose of this paper is to explain how to create reusable scripts with QEngine and make script maintanability simple. It will be easy to debug any problem by reusing the scripts. Preface:QEngine is a test automation tool, that can be used to automate web applications by recording the user interaction with the web application and playing back it as recorded QEngine script is a collection of step by step actions carried out by the user while interacting with the web application in a script format. Upon recording the user interaction with the web application, QEngine will generate the script in human readable format. QEngine uses popular scripting language “Jython” as the scripting language for QEngine scripts. Jython is the Java Extension ofPython language. You can utilize the power of jython in the QEngine scripts to make it more powerful. How QEngine Recording works ?For example, If the user searches for “web functional testing” keyword in google, QEngine will record the interaction in the script as below,
The above script is in a better human understandable format. During replay of the script the actions recorded in the script will be performed step by step. Similarly we can create and record any number of scripts as required. The recorded scripts can be replayed as needed. Problem Definition: Let us assume, the web application under test requires a user login to access any of its resources. Normally you will record the login actions in all the scripts before doing any script specific operation. The potential problem here is that Script Maintenance will become more cumbersome as modifying the script with respect to changes in the application will be difficult. What is Script Maintenance ?Script Maintenance is a mechanism of providing simplicity for script storage. It should have flexibility in modifying the scripts for future application changes. What is the problem with Script Maintainability ?The main problem if the script is not properly designed is that if there are minor changes to the application UI (login page) in the future, it will become difficult to incorporate the changes in the scripts already created. For example: Assume an application requires user login to access its resource, then if the scripts were designed in such a way that login action is present in all the scripts, then any changes to the login UI of the application in the future will make the script modification difficult. How to solve the above problems ?The above problems can be resolved by planning script maintenance in such a way that any repetitive tasks can be grouped under a function and can be reused anywhere in the suite. For example: In the above scenario, the login actions can be grouped under a single function so that all the scripts can call the login function to perform the login action in the script. This is called reusing of the scripts. There are two ways to create reusable scripts in QEngine,
Reusing Scripts through External Jython Function: For example: Logging into the web application is a common thing that needs to be done before doing any operation in a web application. If the login action can be recorded in a separate script and reused in all other scripts, it will be easy to maintain / debug the scripts. Following are the script lines that do login action in the web application,
As per the first method, the above script lines can be grouped under the an External Jython function named “login” in the custom.py file so that it can be called from any QEngine scripts. In the custom.py file define a function named login and define the actions recorded, The custom.py file will look like below,
The above function will take user name and password and login to the application. In the QEngine script where it requires to login to the application, simply call the above function as shown below,
This will perform the login operation in the web application. Where should the custom.py file be kept under QEngine?The custom.py file can be placed under QEngineWebTest\jars folder. If the file is kept under QEngineWebTest/jars folder, it can be accessed directly inside QEngine scripts. Incase, if you wish to place the custom.py file under a different folder than the above, the path needs to be defined in the PY_PATH variable in the setCommonEnv.bat file. To define the PY_PATH variable, follow the instructions given below:
This will properly load the required custom files from the specified path while running the QEngine scripts. To add multiple location in the PY_PATH, add multiple paths with ;(semicolon) as separator between paths. Reusing Script through “callScript“:
Now the login can be called in other QEngine scripts as below,
The above script line will invoke the login script. The login actions will be stored in a single place, So it will be easy to make any changes to login script alone without affecting the scripts requires login operation. Calling Jython API Functions:Jython / Python has more inbuilt capabilities which can be used inside QEngine scripts for efficient usage to meet the automation requirements. We shall discuss on how to use those capabilities inside QEngine Scripts. Here we shall discuss on generating random numbers using Jython API,
The above function getRandomInt will receive two arguments and generate a random int with in the given range of a,b. How to access the above defined function inside the QEngine script ?The above defined function can be accessed in QEngine Script after importing the functions in to QEngine Script. You can access the the above-defined function as shown below:
The above code will get the random int value within the range of 10 and 20. Similarly, we can use the various Jython API as per our needs and use the power of Jython in QEngine scripts. You can use the following links to get help on Jython / Python, Python Tutorial - http://www.python.org/doc/tut/tut.html How can the Standard Java Classes be invoked inside the QEngine script ? We can access the standard Java API's inside the jython script to perform customary operations. For example:
In the above-defined function, it takes two arguments - path of the file and content to write in the file. The above function can be called in the QEngine scripts as below:
The above function call will invoke the writeInFile function and write the given content in the file. How to customize the script using custom java class inside the script ?We can access our own Java API to perform any customary actions inside the QEngine scripts. For example: Let us write a Java API which will sort the array of integer values in ascending / descending order and return it back. Below is the content of Sort.java package com.mytest; Below is the content of custom.py import com.mytest.Sort as sort The above functions can be accessed inside QEngine script as below, values= [45,12,33,55,50] The above snippet will get the integer array stored in “values” sorted in ascending order and print the same. This paper concludes on reusing QEngine scripts for better script maintenance and script debugging . We hope that you now have a better understanding of the designing, maintaining and reusing scripts in QEngine and also a better understanding of using Python API and Java API inside QEngine scripts for better efficiency. For any clarification on this article mail srinivasar@zohocorp.com Visit our website www.qengine.com for more information.
|
|||