Tuesday, October 22, 2013

Performance Testing - Scripting Part 2

When people move from functional test automation to performance test automation, there is always a question on how to handle dynamic data. All functional automation tools provide data driven test, where you feed data in a csv file or spreadsheet. But how to get or extract data that is sent by server? Most of the functional tools provide GetRunTimeValues from UI. This will dump the UI data in an array, from that we can extract the data we want. But in load test, when 1000s of vusers are running, we do not have UI at all. How do we handle dynamic data?

Look at this sequence of events. 

Client sends request REQ1. This is to get the list of purchase orders (PO).
Server sends response RES1. This has a lot of purchase order IDs.
Client must choose the first purchase order from response RES1 and pass that in request REQ2 with a few modified values. 

You do not know what PO ID will come from server. That is purely dynamic data. Unless you send one of those IDs coming in RES1, the REQ2 will fail. All these are happening in background without you seeing UI. To achieve this, you need to do correlation.

Correlation means - extract some details from a response, and pass that as part of subsequent requests. 

All load testing tools use the same principle to handle correlation. The response is a pure html text. See this example. List of POs are coming like this.

<table>
<tr class="po"><td>POID</td><td>CUSTOMERID</td><td>PODATE</td></tr>
<tr class="po"><td>9235</td><td>Navy Corp</td><td>01-10-2013</td></tr>
<tr class="po"><td>9845</td><td>Blue Minds</td><td>10-05-2013</td></tr>
<tr class="po"><td>9876</td><td>Blue Fields</td><td>06-03-2013</td></tr>
<tr class="po"><td>9989</td><td>Red Grove</td><td>07-04-2013</td></tr>
</table>

When I send REQ1, after sometime, the table data may be different in response. Hence every time, it is necessary that we get the first row from the response. How do we extract the row 1? There are 5 rows in the table and the first row is the header. 

Here is the simple trick. "Chase the data". I want to pick up 9235. Locate what appears to its left and what appears to its right. The text <tr class="po"><td> appears to its left and </td> appears to its right. But there are 5 such rows, where I can see the same left and right text. But this 9235 text appears in the 2nd position or ordinal. So if we tell the load test script, to locate the text with <tr class="po"><td> as left boundary and </td> as right boundary, it will give me an array [POID, 9235, 9845, 9876, 9989]. In this array, my text appears in ordinal 2. Look at this command.

locate_dynamic_data(dynavar1, LB=<tr class="po"><td>, RB=</td>, Ordinal=2);

where, dynavar1 is the variable to which it will load the value, LB is left boundary and RB is right boundary. When load test tool sees this instruction/command, it will scan the response, locate the text as per your LB, RB and Ordinal, and will give the extracted data in variable dynavar1. Once it is in variable, you can pass that to subsequent requests.

Everywhere, you see dynamic data, you need to correlate. You need to ensure that the correlation command gets proper data from the response. If response itself is not received or the text you look for is not present, subsequent requests may fail. You need to handle that part in scripting.

In java framework, in web apps, there is usually a dynamic text jessionid; same way, in asp.net apps, you will see a dynamic text __VIEWSTATE__, __VIEWINFO__. Unless you handle these framework related dynamic text, load test script will not work. But the load test tools are intelligent. Whenever the text during recording and text during replay are changing, they give a warning to the tester, that these changing areas are potential correlation areas. Hence pay attention when tools warn you on dynamic data.

For free lessons on automation tools, visit us at http://www.openmentor.net.

Friday, September 20, 2013

Performance Testing - Scripting - Part 1

Web applications will typically follow n-tier architecture, i.e. presentation layer, business logic layer, data access layer, data layer, external interfaces etc. But a website will mostly static pages, may be with javscript. The entry and exit to websites is unpredictable, as every page is a potential entry and/or exit, they are all independent. I a web application (webapp), the sequence of tasks one does is very important, to complete a business transaction. Hence there is a difference between load testing a website and load testing a webapp. As we saw in the previous post, the very first step is to identify the most frequently used scenarios and the steps for those scenarios. From that point, we need to focus on scripts.

Every load test tool provides recording feature. This is the most economical, easy and powerful way of scripting. First the tester must record the sequence of operations, as one user does. This means, start recording, start doing the business transaction steps on the application. The tool will record all the requests and responses, going to server and coming back from the server, using an internal proxy. Ideally every load test tool sniffs the request/response between the browser and the server. The request may be a get or post or ajax request. The tool will identify the url, the query string parameters for the request and will identify the server response data and redirection pages. Soon after recording, if we replay the script, the tool must be in a position to send the request to the server.

Mere recording and replaying will not solve many business rules. Some apps will require unique data, some need random data, some need advanced correlation and that is what we must do as the next step with the recorded script. Also, it is better we organize the requests under folders/containers. This will help towards easy maintenance of the scripts. For example, if our sequence of operations look like the following,
  • Go to home page
  • Fill userid and password, login
  • Navigate to items page
  • Load items list grid
  • Select an item and edit
  • Enter new details and save
  • Refresh items grid
  • Logout
It is better to organize the same like this.

  • Initialize
    • Initialization
    • Go to home page
    • Fill userid and password, login
  • Items Grid Load
    • Navigate to items page
    • Load items list grid
  • Modify Item
    • Select an item and edit
    • Enter new details and save
  • Items Grid Refresh
    • Refresh items grid
  • Finalize
    • Logout
Once the requests/steps are organized, the next step is to provide proper data to the script. We cannot use the same data we gave during recording. There are 2 parts to the data  - static data, dynamic data. Static data is different data supplied/typed by the user on the screen, dynamic data is the data that server sends back to the screen. Providing static data is called parameterization and handling dynamic data is called correlation. 

Static data can be provided thru variables. Tools provide variable manager module. We can create a variable and load the variable with different values, at run time. Some data that we may often use, can be obtained from the system itself, such as current date and time, user name, machine name, random number, random text, etc. 

Some data will be application specific. This data will have dependencies on other application data as well. For this, we usually create a file to have such data and modify the hard coded data values in the script, to use the data variables. The variables will be mapped to the file and specific column in that file. This is very similar to data driven tests in functional test automation.

For example if item creation page requires item code, item name, UOM, price as user supplied data, create a csv file like this.

ITEMCODE,ITEMNAME,UOM,PRICE
1001,Maxx Soap,NOS,18.90
1002,Vixor Biscuits,PCK,12.60
..
1099,Brainee Rice,KGS,14.50

Create a variable in the tool (say myItemData) and map that to this file.
In the script, replace the hard coded values with
myItemData.ITEMCODE, myItemData.ITEMNAME, myItemData.UOM,
myItemData.PRICE. During run time, the tool will read the data from this file and supply the values from the respective columns to the right variables. Usually, the tools will read lines sequentially and send that to the script. This can be changed as well. We will see these in the next post. Stay tuned.

For free lessons on automation tools, visit us at http://www.openmentor.net.



 

Tuesday, September 10, 2013

Performance Testing - Protocol Selection, Script Recording



If you know one load testing tool, it is easy to learn another. You need to be clear in the load testing fundamentals, in order to learn a new tool and to master it. We will help you step by step in achieving that mastery over load testing tools. Let us take the first part of the tools, protocol selection.

Protocol is nothing but the format in which the client and server communicate with each other. Eg., http, https, ftp, smtp, wap, tcpip, rdp, etc. Every application developer must first freeze the protocol and architecture, as changing these at a later stage will mess up a whole lot of things. But for a load testing person, all it needs is to understand what goes as request and what comes as response. Ultimately every thing will go as a stream of bytes; but to operate on the requests for parameterization etc., the load tester must know the parts of the requests and parts of the response. 

It is difficult to manage too many protocols and learning them at the bits and bytes level. Instead, if the tool can parse the request and response, and display the same in a clear user interface, most of the problems for the load tester are solved. The tester must refer to the design documents as well as consult with the development team to identify and choose the right protocols. A few applications may use multiple protocols to carry out a specific transaction; in that case, the tester must select all those protocols before recording the script.

The catch here is, that the load testing tools will charge you based on the protocol modules you want to buy! There will be a base license cost and there will be an add-on cost for every protocol module. You may be thinking that it is a simple web application, but that app may use Google Web Toolkit (GWT) or Flex related formats; without having those protocols as part of the tool, you cannot get a clean script. Hence one needs to be careful why purchasing the tool and add-on licenses.

Once you freeze the protocol, the you need to focus on scripts. We must create load testing script by recording a typical business scenario, as though one user is doing it on the application. For example, a user logs into an HR application, submits a travel request and logs out. The actual load test will send 100s of such requests (simulating 100s of users). The key point here is what scenarios we must record as part of scripting?

Identify the most frequently used user scenarios. All said and done, you and I go to google and do search 80% of the times.  Some other person may go to google stocks page to get stock quotes. So, the user priorities vary. Though google has 1000s of pages, only a small set of pages are more frequently used, by  most of the users. In the same manner, in your application, identify which are the most frequent ones and tabulate the same. How many users will execute those scripts, how long the users will run etc., we will deal with those in subsequent sections.

If you take any ecom site, the most frequently used scenarios are:

  1. Go to home page, type a keyword, do a search, load search results, view an item from the results
  2. Go to home page, type a keyword, do a search, load search results, view an item from the results, add to cart
  3. Go to home page, type a keyword, do a search, load search results, view an item from the results, add to cart, provide payment details, buy
In the above 3 scenarios, many activities are common, but for every one customer actually buying, 100s of other customers, just "surf" and "window-shop" without adding to cart. Though they do not contribute to revenue, they occupy your system and network space. After attracting a customer to the site, thru marketing, it is very hard to see the customer abandoning the shopping cart without a buy! Usually these things happen due to slow response. So, buckle up, and make it faster!


For free lessons on automation tools, visit us at http://www.openmentor.net.

Monday, August 26, 2013

Performance Testing - Basics

Squeeze the app before release. If the app withstands that, it is fit for release. But how to squeeze? How will we determine the number of users, data volume etc.? Let us take this step by step and learn. Performance tests are usually postponed until customers feel the pinch. The primary reason is the cost of the tools and the capability to use the tools. If one wants to earn millions of dollars thru a hosted app, a good, proven and simple way is to increase users and reduce price. If one does this, the business volume will grow - but it brings the performance issues as well along with that.

Most of the tools use the same concept of emulating the requests from the client side of the application. This has to be done programmatically. When one is able to generate requests, processing response is a relatively easier task. When you choose the tools, it is better you look for the must-be-in features and then for nice-if features. 

The must-be-in features are listed below.

  1. Select protocols (HTTP, FTP, SMTP etc.)
  2. Record the user sequence and generate script
  3. Parameterize the script to supply a variety of data
  4. Process dynamic data sent by server side (correlation)
  5. Configure user count, iterations and pacing between iterations
  6. Configure user ramp-up
  7. Process secondary requests
  8. Configure network speed, browser types
  9. Check for specific patterns in the response
  10. Execute multiple scripts in parallel
  11. Measure hits, throughput, response time for every page 
  12. Log important details and server response data for troubleshooting
  13. Provide custom coding facility to add additional logic
The nice-if features are listed below.
  1. Configure performance counters for OS, webserver, app server, database server. This way, you can get all results under one single tool
  2. Automatically correlate standard dynamic texts based on java or .net framework. This will reduce scripting time
  3. Provide a visual UI to script and build logic
  4. Generate data as needed - sequential, random and unique data
  5. Provide a flexible licensing model - permanent as well as pay-per-use will be great
  6. Integrate withe profiling tools to pinpoint issues at code level
When one evaluates a performance testing tool, one must do a simple proof of concept on the above features, to see how effectively the tool handles these features. No need to say, that the tool must be simple to use.


Here are a few simple terms you need to be clear - at least academically. There are so many different definitions for the phrases given below, but we try to take the mostly accepted definitions from various project groups.

Load Testing - Test the app for an expected number of users. Usually customers know their current user base (example - total number of account holders in a bank). The number of online users will be usually between 5% and 10% of customer base. But an online user may be just a logged in user, doing no transaction with server. Our interest is always on the concurrent users. Concurrent users are usually between 5% and 10% of online users. So if 100,000 is the total customer base, then 10% of it, 10,000 will be online users and 10% of that, 1000 will be concurrent users.

Stress Testing - Overload the system by x%. That x% may be 10% more than normal load or even 300% more than the normal load. But usually load tests happen for a longer duration and stress tests happen for a shorter duration as spikes, with abnormally more users. Stress is like a flash flood. 

Scalability/Capacity Testing -  See the level at which the system crashes. Keep increasing users and you will see a lot of failures and eventually crash. Some companies use the term stress testing itself to include the capacity testing as well.

Volume Testing - keep increasing the data size for requests as well as process requests when the application database has 100s of millions of records. This usually checks the robustness and speed of the data retrieval and processing.

Endurance/Availability Tests - test the system for a very long period of time. Let the users keep sending requests 24 by 7 may be even for a week or month. See if system consistently behaves over a period of time.

For free lessons on automation tools, visit us at http://www.openmentor.net.

Monday, August 12, 2013

Non-functional Testing

You are never alone. The environment around you changes every second. Your behavior in a changing environment - is it consistent or is it unpredictable? This is true for software applications also. Testing the behavior for a given input and expecting a definitive output is termed as functionality testing. But the same input, same product, but a different environment or an external factor, need not give a consistent output. Testing that is a non-functional testing. 

There are a variety of non-functional testing topics, that we are going to discuss in detail. The key areas that need to be addressed are given below.
  1. Performance Testing
  2. Compatibility Testing
  3. Interoperability Testing
  4. Security Testing
  5. Recovery Testing
  6. Usability Testing
  7. Localization Testing
  8. Globalization Testing
  9. Adhoc Testing
Let us first take performance testing. In today's world, internet is everything and it is everywhere. That connects PCs, servers, mobiles and people. Hence it is inseparable from our life. Internet is as important as electricity today. This means, more people use the application. Let us take google, facebook, amazon, youtube, msdn etc. All these sites/portals are used by millions of people. When more users use the system, company gets more visibility and hence more money. But the crowd comes with problem also.

When more people use, the system slows down or crashes. How many people are ready to tolerate the home page loading beyond 5-7 seconds. If your product does not load or start quickly, there are enough competitor products that users can try out. Hence the speed is the single factor that wins the hearts of users, right at the first shot. 

Remember the trinity - Users, Data and Time. If any one of these factors is increased, it uses more system resources such as cpu, memory, disk and network; and that causes slowness. But how will I test my app with 1000s of users, hitting the app at the same time? Can we assemble the real users in beach and give them laptops or tablets and coordinate to test the app? No way. Hence, instead of relying on real users, we go for virtual users. Performance testing is now the key factor for an app to be released. 

Performance testing has different sub-types.
  1. Load testing
  2. Stress testing
  3. Scalability or Capacity testing
  4. Volume Testing
  5. Endurance or Availability testing
To carry out these testing, we need to have proper tools. There are priced tools such as HP Load Runner, IBM Rational Performance Tester, Borland SilkPerformer and there are free open source tools such as Apache JMeter etc. In the coming sections, we will see the concepts of load testing and how to use these tools etc.


For free lessons on automation tools, visit us at http://www.openmentor.net.








 

Tuesday, July 23, 2013

Test Automation - Exception Handling

Test automation is all about a tester generating test scripts, i.e. code. So, all problems of what a developer would face, a tester would also face. Hence test script must also be fully tested by the tester. But, there are 4 major factors that can affect the test script and those 4 are unpredictable. Hence, the test script must gracefully handle those areas. This is called exception handling or known as recovery scenarios.

Hurdle 1 - Unknown pop-ups. When the script executes, step by step, application reacts to those steps, and there is a specific expectation out of each step. For example, if a user enters a valid account number in account number field and press tab, the account name must be auto populated in name field; when script executes, due to a wrong data fed into account number field, if the application shows a pop-up stating "Hey, the account number does not exist; please check the data", that pop-up is a blocker. Without closing that, nothing can be done and script cannot proceed. This is just one example; similarly in many occasions, due to data issues or application functional issues, OS related issues, unwanted popups will crop up. The tester must ensure all such pop-ups are addressed when script runs. Ideal solution is close the pop-up, and continue or go to next test case.

Hurdle 2 - Objects or pages not found or disabled for input. This happens due to a functional bug in the application. Take an example. When user goes to account balance screen, the account number must be enabled for data entry. Occasionally if that field does not appear or disabled, the script will go ahead try to enter the account number and the type event will fail. It is not possible to check the enabled or displayed property for every field to be ON, before every step. A field not found error may happen, if the display of the field, goes outside the display resolution of the monitor. If this kind of errors happen, it is better to relogin to the app and move to the next test case.

Hurdle 3 - Application crashes. This is usually due to some critical bug in the application. The test script will not find the application itself to execute the next step. In this case, it is ideal to restart the app and start the next test case. If we try to start the same test case, it may crash again and it may go in a loop.

Hurdle 4 - Script error. This is due to a wrong logic by the tester in the test script. This may be due to accessing wrong array locations, divide by zero, trying to open a non-existing file etc. If this kind of errors happen, it is better to relogin to the app and move to the next test case.

Tools provide a variety of mechanisms to handle the exceptions, either thru coding or by configurations or by both. Every exception is a learning. It is very difficult to identify all exceptions and handle those before script runs. It  is an evolving process. So, as and when new unforeseen exceptions do happen, add them to the exception handler library.


For free lessons on automation tools, visit us at http://www.openmentor.net.





Monday, July 15, 2013

Test Automation - Scripting Essentials

Record and replay alone cannot solve test automation problems; also record/replay may not be always possible. The test script may need some kind of decision making at run time; script may need some intelligence in handling situations; the test may have to alter its path based on some values coming on screen at run time. The simple solution for all kinds of such issues is - Scripting. Every tool provides some scripting language such as VBScript, Java, JavaScript, C#, Ruby etc. So, if we mix record/replay and scripting, we increase the power of the tool by thousand times.

Rule 1: Never build application logic in the scripting language. Example. You recorded how to book one-way ticket for 1 person; for 2 people, if app needs the price to be multiplied by 2, do not build that multiplication logic in your script. Because, whenever the app logic changes, script needs to be modified and retested. You may make some bugs in coding in the scripting language, while modifying that logic. Always, see what is the input, manually determine what must be the expected output, feed that output as checkpoint values, go on. Your brain is the best tool, better than any automation tool.

Rule 2: Comment your script well. Maintenance of script is very important. Hence make sure another tester can easily understand your script. 

Rule 3: Unit test your test script. Remember, developers make mistakes in their code. When you program, you will also do mistakes in your code. Being a tester, nothing guarantees that your test scripts will work without testing.

Rule 4: Ensure your test functions, work for a variety of parameters. A single function may feed 1000s of data thru data driven test. Hence test your script with multiple data.

Rule 5: Avoid nested if conditions. At the most you can do 2 levels. This itself will consume more time for you to unit test your test scripts.

Rule 6: Avoid nested loops. Nested loops may not be actually required in 95% of the cases. So be judicial when using nested loops.

Rule 7: Have a traceability matrix for your test scripts. You need to have a spreadsheet that documents the input params, output params, file details, function details, caller details for every test script/function. Else, when it grows to 1000 test scripts, changing one script may affect another, if you are not aware of the dependencies.

Rule 8: Always put all test scripts in a batch and run. This will eliminate the base state problems.
 
Rule 9: Always make another tester (other than the author of the test script) to run the test batch. This will eliminate human related issues and documentation issues.


Rule 10: Always run the test batch from another machine (bot used for building the test scripts). This will eliminate system related issues, hardcoding of drive/folder names etc. and documentation issues.


For free lessons on automation tools, visit us at http://www.openmentor.net.