Tuesday, November 20, 2012

How to Save the downloaded file to local system

Problem Statement: During some of our non functional testing scenarios, there might be a need to download some files. We are also asked to check the transaction time for that download process, but very rarely there is a need to save the downloaded files to your local system for some verification later. If this is the case then how can we do so...

Solution: There is a solution to do so, all you need to do is get the data from the server response and save it to a file using normal file operations. But you need to know beforehand the type of file you are going to download.

In this sample example let's consider that you are trying to download a .pdf file and want to save it to local system. Here is a sample code snippet to do so:
**************************************************

//declare the variables
int fp;
long i;

//create file for writing.
fp = fopen("c://test_file.pdf","wb");

//Start a transaction to measure the download time.
lr_start_transaction("file_download");

//Set the parameter size large enough to save the data.
web_set_max_html_param_len("100000");

//Use web_reg_save_param with the correct boundary to capture the data returned by the server (for the download)
web_reg_save_param("FILEDATA","LB=","RB=","Search=Body",LAST);

//HTTP call to download the .pdf file
web_url("http://serverURL:port/app/resource/getme.pdf");

//Get the download size.
i = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );

//Write the data saved to an output file.
fwrite(lr_eval_string("{FILEDATA}"),i,1,fp);

//End the transaction
lr_end_transaction("file_download", LR_AUTO);

//Close the file pointer.
fclose(fp);
**************************************************

Hope this helps in your scenario.

Monday, October 8, 2012

Conversion Functions for Hash (SHA1) and Hex

Problem Statement: During a recent project there was a need to encrypt the data to be sent to target application using SHA1 algorithm. There was a need to develop some kind of function which can achieve this objective.

SolutionDuring this process i used Visual Studio 2010 to develop the required functions using c++ code and then export these functions using dll.

This dll can be called in your VUGen script to encode the string using SHA1 algorithm and send it back to you (this generates the code in base-64).

Also this dll has some more basic utility like converting a string to hex and vice-versa. The usage of the functions can be seen in the screenshot below:


Hope this is helpful to you in your projects; if anyone needs any custom functions then i can probably add them later into this dll.

PS: I can't post the dll here in this post due to option restrictions; you can mail me if you need it then i can send you the dll.

Thursday, September 13, 2012

Minimum Permission Level to Install and Run Loadrunner

Problem Statement: What is the minimum access level a user needs to Install and Run Loadrunner and its components ?

Solution: Ideally the user needs to be part of Administrator group on the machines where he wants to install and run loadrunner.

But actually a user needs to be Administrator for installation and power user for running LoadRunner.


It is recommended to be a member of at least power users to run LoadRunner. 
Sometimes, due to security restrictions, this is not possible. In that case, the user must have at least the following rights; these rights needs to be provided appropriately by an Administrator:
1. Full access (read/write permissions) to registry keys as mentioned below:
HKEY_CURRENT_USER\Software\Mercury Interactive
HKEY_LOCAL_MACHINE\Software\Mercury Interactive 
HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\engines\text
HKEY_LOCAL_MACHINE\Software\Microsoft\Tracing
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\WMI
2. Full access (read/write permissions) to the file system (preferably to the local drive where user account is present and other drive if Loadrunner is installed on a secondary drive) to be able to copy files.

If there is any problem either with agent start up or connection from Controller to the agent on a Windows 2K machine with a power user, then ask the system administrator to perform the following:
1. Open the Local Security Settings window through Start -> Programs -> Administrative Tools -> Local Security Policy.
2. Select Security Settings -> Local Policies -> User Rights Assignments.
3. Add the user to the "Create global objects" policy.

Tuesday, September 11, 2012

Is there a way to suppress errors from perfmon counters in controller

Problem Statement: During our day to day life as performance testers / experts, we must have noticed a lot of errors related to counters during a long running scenario. Mostly the errors are like "A counter with a negative denominator value was detected.", "A counter with a negative time base value was detected." or "A counter with a negative value was detected."

All these errors make the online monitoring a lot difficult to filter out the actual errors coming from the application.

Is there a way to mask these errors related to counters?

SolutionThe answer is Yes, it is possible to do so.
For this you need to do the below change in both Controller and Load Generator machine.


  • Go to the Loadrunner (or performance center host) installation dir; then go to folder "dat -> monitors" 
  • under that folder open the file "nt.cfg" in a wordpad; it will be like as shown in the snapshot below:




  • You can see the "general" section in the file, there is an entry called as "FilterErrors" which has the current value as 6.
  • Now to set the proper value for other errors which you want to suppress, get the Hexa value of the error from MSDN website: " http://msdn.microsoft.com/en-us/library/aa373046(v=VS.85).aspx "
  • Look for the hexa code like " 0x800007D6 (PDH_CALC_NEGATIVE_DENOMINATOR) " for the error " A counter with a negative denominator value was detected. "
  • Open Calculator in scientific mode (in case of XP / win 2003 machine) or programmer mode (in case of win 7 or 2008 server) as shown below


  • Move it to Hex mode and make the entry for the Hex code as it appears for the particular error, in this example it will be "800007D6". Once entered, change the calculator to Dec mode and you will get a number like "2147485654" (see the screenshot below):

  • Copy the value from the calculator and put it in the "nt.cfg" file along with the earlier value separated by comma (,) as shown in the screenshot below:

  • Once done you can perform similar steps for other error types you are getting from windows perfmon counters.
  • Save the "nt.cfg" file and restart the loadrunner agent process (or service) on Load generator.



Monday, September 10, 2012

Functions not allowed while running vusers over firewall

Problem Statement: In certain cases your VUGen script has certain functions (may be custom functions in C like malloc, etc) which runs fine during replay on your machine. But the same function gives an error while running the script on a load generator over firewall (i.e. the vuser is running over a firewall). The error given by LR is: "Error: -19886: CCI security error:You are running under secure mode and the function is not allowed in this mode"

Is there a way to allow the function to be run in the load generator?

PS: This error doesn't come while running the script on a normal load generator (not behind the firewall).


Solution: The answer is Yes, it is possible to do so. 
go to the load generator machine where the above mentioned error is coming; go to the installation directory and open the folder called as "merc_asl".

There will be many "*.asl" files, each corresponding to protocols support during running Vusers over firewall. 

Open the .asl file for the protocol in a wordpad for which you are getting the above error, add your function in that file as shown below:
[Function name]= 
below the [Allowed_Functions] tag


Once you have added the custom function in the asl file; restart the agent service (or process) on the load generator and your script should pass now.

Hope this helps in resolving your issues.

How to create web scripts with different recording option without recording

Problem Statement: In certain cases during recording of a web application we notice that certain actions (or request) are not captured by LR script. Then we are advised to try out in different recording mode and see if we are able to capture the request. 

Is there a way to recreate the script with different recording options without re-recording the business flow again?

Solution: The answer is Yes, it is possible to do so. There is feature in VUGen known as "re generate script" which can be leveraged to get the desired script.

Note: This action will reset all customization done on the saved script (like custom formatting, checks, transaction naming etc)

In this solution which i tried out, i had recorded the application (AUT) in web click and script in a multi-protocol mode. Following the below steps, i had converted the "web click and script" to normal web HTML script.
Once the script is generated, you need to save the script locally and then click on Tools Menu on Vugen and select Regenerate script:



Once you click that option, you will notice a small window with warning message, click on the options button:



After clicking the options menu, you will get the recording option window; select the appropriate recording mode / options you want the script to be generated with and click on OK:


Click on OK on the previous window after the recording option window closes and you can see the VUGen code being re-generated:

Save the script once the code generation is complete.

Thursday, August 30, 2012

How to set authentication object for web services

Problem Statement: In certain cases where the application under test (AUT) is a smart client application and the application uses web-services for it's operations. During recording of the application VUGen doesn't record the authentication object and while replaying the script you get the below error for the web services request(s):


An Authentication object was not found in the SecurityContext
The reason for the SOAP fault is: "An Authentication object was not found in the SecurityContext"

Solution: As mentioned above, the application being a smart client is mostly launched via a web-link where the run time jars / dlls are downloaded locally and application is launched. During launching itself the application takes the credentials from local system (your AD account details) and authenticates the user.

In case of replaying this operation in VUGen this authentication information is not available; this can be done by sending the authentication information in the header before the first web-service request as shown below:








Otherwise if your web service method has property for sending authentication object then you can do so in the request itself.

Hope this helps in solving your issue.

Wednesday, August 29, 2012

How to set CITRIX client file security for Load Generator

Problem Statement: During scenario execution, there might be a step where the citrix session will be interacting with local drive for some operations like select a local file to upload. In this case the citrix session on the load generator will be stuck up due to CITRIX client file security dialog. 

Solution: While doing any operations to access local system resources CITRIX gives a pop-up to user to whether to allow the access or not and settings for it (as shown below in the screenshot):


mostly in our session we choose "Full Access / Read Access" and "Never ask me again". So while we replay our scripts on our local machines it runs fine; but this can cause an issue while running a scenario through a load injector (or load generator).

If you are running the scenario through local injector (localhost) then you can manually do the setting while performing the same operation on the application.

If you are running the scenario on a remote injector then you need to login to that injector machine (as admin) and again perform the same operation and provide access to the citrix client (assuming that the injector is running magentproc under your id).

In case of performance center this thing is a bit tricky; in this case what you need to do is to login to the injector machine (as admin) and open the following location:

"(root directory)\Documents and Settings\(username)\Application Data\ICAClient" and open the webica.ini file in a notepad.

by default there will not be any entries in this file, you need to make the following entry after the "[Access]" line:
"GlobalSecurityAccess=405" (this security code is for "Full Access and Never ask me again setting")

Now your webica.ini file should look like this 


please note that you need to make this change for "IUSR_METRO" and "default user" under "Documents and Settings"
Then restart your performance center agent service and run your test; this should enable your transaction to pass on the remote 

Tuesday, August 28, 2012

View Citrix Vuser in LoadGenerator

Problem Statement: During scenario execution, you might be wondering is there a way where I can see why a certain VUser (Citrix protocol) is failing and why; which needs a kind of debug run to find a solution / fix to your code.

Solution: Actually there is a simple solution to the above mentioned problem. You can enable the citrix vuser view in controller command line (or in Performance Center) to view what the user is doing in replay window.

To do so all you need to do is to go to script group details and provide command line as shown in the screenshot below:


If you are using Performance Center, other than normal LR controller then you can use the command line feature in the design mode of the script as shown in the below screenshot:


One done start your scenario and you can see your virtual user replay in the load generator machine.
Please note that if you are running the Injector from PC then you need to stop the performance center agent service and start "magentproc.exe" manually under your user account so that you can view it properly. Otherwise this will be running under the PC user session and you will not be able to view the replay and waiting this thing to happen in your session.

Hope this small article helps you in resolving your issues.

Tuesday, July 3, 2012

Monitor Java app server via JMX and sitescope

Problem Statement: There was a need to monitor the JVM level stats from the application during performance testing other than normal system level stats.

Solution: Our target system was hosted on Tomcat 6.0 on a windows box (64-bit); to enable to monitor the JVM level params you can always enable JMX and monitor via Jconsole or VisualVM.

To enable JMX Settings on your application add the following lines to your startup script (or tomcat6w.exe in this case):

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port="JMX Port"
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

If your server is behind a firewall then you will not be able to access the JMX via JConsole or VisualVM; even though the telnet to JMX port shows that the port is running and accessible.

In that case you need to add another entry in the java params:
-Djava.rmi.server.hostname="IP Address of system"


Restart the tomcat service (or your java app server); now you should be able to access it through Jconsole or VisualVM on remote machines.


If you want to configure this on sitescope then you need to do is add a JMX monitor and provide the JMX URL to connect to that JVM as shown below:


service:jmx:rmi:///jndi/rmi://"Server Name":"JMX Port"/jmxrmi


Once this is done, select the appropriate counters to monitor in sitescope; once configured add it to your controller / PC scenario. This will enable you to store the values into your test results and analyse them later.


Hope this solution works for all.

Monday, January 2, 2012

Analysis Report contains transaction numbers instead of transaction names

Problem statement:
While generating analysis report the transaction summary has numbers instead of transaction names. This issue is seen mostly in case of test being run in performance Center. 
The possible reasons for this behavior are:

  • Version conflict between controller and Load Injector.
  • Map file was missing on one of the load generators.
  • Analysis of the load test run showed that the load test had exceeded its timeslot and ended with the error "Executing run failed to stop in a timely manner". Furthermore no load test results were collated for this load test. As a consequence test result collation was perfomed manually by setting the collator status to "before collating results" and then collating the results.
Solution:
Install correct version of Load generator on all the LG machines.

In order to resolve this problem, where no map file is used and all information is written to the eve file, revert to the old way of writing the results using this steps:
a) Close all the instances of Controller and make sure no test is running.
b) On the Controller machine search and find the file "Wlrun7.ini".
c) Back up the file to save the original version
d) On the file go to [GENERAL] section and add the line: EveVersion=2, close and save the changes.
e) Launch the controller and run the LoadTest. If this is controller machine in Performance Center implementation, perform this operation on every controller machine that is running a load test.
f) Open the results with analysis and all the transactions should be present.

This problem is fully resolved in LoadRunner 11 and Performance Center 11, as information to the MAP file is written during the load test itself and not only at the end of the load tests

Alternate Workaround:

Try the following workaround so that Analysis will display names under transaction names rather than numbers in the Analysis Report.
1. Open a new analysis session and change the option there  in Tools ---> Options ---> Result collection --->Choose "Generate summary data only."
The default is "Display summary while generating complete data."
 
2. Then, go to File ---> Open ----> Change the "Type of File"  to "LoadRunner Results."  The default is "Analysis Session Files."
 Choose the .lrr file and Click on "Open". 
3. The Analysis report will be generated.  Save the .lra file.
Open the .lra file and check the Summary report for transaction names.



Error:Unable to create Java VM" when running / recording a Java Vuser

Problem Statement:
When trying to run (or record with) a Java Virtual User (or java record and replay), the following error message occured:
"Error -22994 : Error:Unable to create Java VM. [MsgId: MERR-22994]


Resolution:
Check the Java add-in and the System variables Path and Classpath
1. This error usually means that the PATH and the CLASSPATH environment variables are not set properly. (Check whether any other tools like QTP or Winrunner is not installed on the system previously, as it sets its own custom variables related to java hook and path)
2. Delete ini file for Vugen:
a. Shutdown Vugen.
b. Go to (Window install directory) and look for vugen.ini. Delete the file. LoadRunner will recreate new configuration file when VuGen is launched.

c. Launch VuGen and run the script again. 

"java.security.AccessControlException..." during replay

Problem Statement:
The (java / java record n replay) script was recorded without any problems. During replay, the user receives the error:


System.out: Exception occured: java.security.AccessControlException: access denied(java.lang.RuntimePermission createClassLoader )
Notify: System.err: java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader )
Error System.err: at java.security.AccessControlContext.checkPermission(AccessControlContext.java:xx)
Error System.err: at java.security.AccessController.checkPermission(AccessController.java:xx)
Error System.err: at java.lang.SecurityManager.checkPermission(SecurityManager.java:xx)
Error System.err: at java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:xx)
Error System.err: at java.lang.ClassLoader.(ClassLoader.java:xx)
Error System.err: at DummyClassLoader.(DummyClassLoader.java:xx)
Error System.err: at DummyClassLoader.setContextClassLoader(DummyClassLoader.java:xx)
Error System.err: at Actions.action(Actions.java:xx)
Error Error occured: java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader )  



Resolution:


Comment out the section for "Installing RMISecurityManager."
Example:
/* if (System.getSecurityManager() == null)
System.setSecurityManager(new java.rmi.RMISecurityManager()); */ 


How to call a custom C# dll in VUGen

It’s not possible to directly call a C#.Net code in LR; for that you need to create a wrapper dll around the original dll. Below is a sample example and ways to do it:


If your core code implementation looks like below:
*********************************************************************
using System;
namespace intmath
{
public class Class1
{
public Class1()
{
}


public static int sum(int a, int b)
{
return (a+b);
}

}

}


*********************************************************************
And this code creates a dll called as “intmath.dll” which is in c# code.

1.Launch Visual Studio .NET and create a new C++ Win32 Project. In the application settings, set the application type to "Dll."
2. Set all required configuration properties required for using managed extensions in the project properties.
a.Go to Configuration Properties -> General.
b.Set the "Use Managed Extensions" option to Yes.
c.Go to the properties of the .cpp file, and under Configuration Properties -> C/C++ -> Pre-Compiled headers, set the "Create/Use Precompiled Header" option to "Not Using Precompiled Headers."

3. Add a reference to the managed code library in this project. //In this case it will be “intmath.dll”


4. In the projects .cpp file, add methods to make calls to the managed code. Add code in the beginning to include the appropriate namespaces.


Below is a code snippet of the cpp file


*************************************************************************
#using

using namespace System;
using namespace intmath; // This is the namespace which is of your original file

#include "stdafx.h"


BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern int Calladd(int, int);


extern "C"
{
__declspec(dllexport) int add(int a, int b)
{
return Calladd(a,b);
}


}


int Calladd(int a, int b){
return Class1::sum(a,b); // call to the original function written in C#
}


***************************************************************************
build this project and generate your dll, in this case it will be known as “mytest.dll” (name of your project)

Then I can use this dll in my VUGen script like shown below:
****************************************************************************


Action()
{

lr_load_dll("mytest.dll"); // Instead of loading the original “intmath.dll”
lr_output_message("add(12, 13) = %d", add(12, 13));
return 0;


}

*******************************************************************************

Hope this will help you in resolving issue with dll loading.