Friday, 4 September 2015

SSL Certificate Conversion - Java Keystore(.jks) into .p12 format

Below Keytool command can be used to convert .jks certificate format into .pem format. Where myapp.jks is your source file & myapp.p12 is your destination file.

keytool -importkeystore -srckeystore myapp.jks -destkeystore myapp.p12 -srcalias myapp-dev -srcstoretype jks -deststoretype pkcs12

If your certificate is password protected you can use below command for conversion:

keytool -importkeystore -srckeystore myapp.jks -destkeystore myapp.p12 -srcalias myapp-dev -srcstoretype jks -deststoretype pkcs12 -srcstorepass pass123 -deststorepass pass123

How to Configure SSL Certificate in LoadRunner?

Configuring SSL Certificate in LoadRunner:

Right click at Action panel & choose “Add files to script” option & select SSL certificate and add it in script. Then use web_set_certificate_ex function to set the certificate.
Example:
web_set_certificate_ex(
"CertFilePath=certificate.pem",
"CertFormat=PEM",
"KeyFilePath=certificate.pem",
"KeyFormat=PEM",
"Password=Password",
LAST );



Creating Web Services Script in LoadRunner using WebService/Web(http/html) Protocol

Some Important Definitions:

Web Services:
It is a web application components which can be published & used on web.
Web services do not require the use of browsers or HTML.
In Web Service XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available.

XML: EXtensive Markup Language
XML is designed to describe the data & act as a tool for carrying information.

SOAP: Simple Object Access Protocol
It is a protocol for accessing web services.
Soap is a format for sending messages & used for communication between applications.

WSDL: Web Services description Language
It is an XML document which is used to describe & locate web services.
It specifies the location of the service and the operations (or methods).


Data requirements:

  • Sample Request & Response XML.
  • End Point URL(Host) where request xml to be posted. E.ghttp://webservice.nam.nsroot.net/
  • WSDLfile to get the information & soap action for all the existing operations/methods.
  • Operation details which needs to be invoked like “GetLoadDetails”.
  • SSL Certificate(also known as a Web Server Certificate, Secure Server Certificate, and Digital Certificate) & password if the host is SSL secured.
Two different ways of creating Web Services Script:

We can do web services scripting in two ways:
  • By using Web Services Protocol.
  • By using Web(HTTP/HTML) Protocol.
Steps for writing script:

  • Open the Vugen and select Web Services protocol.
  • Click on Import SOAP on top navigation bar and select request xml file.
  • Click LOAD and provide End Point URL(Host) & Soap action then press OK.
  • Soap request will be created with the step name “SOAP Request”.
Error Handling & Validation:
lr_xml_find and lr_xml_get_valuesfunctions can be used to validate the page. If-Else statement can be used to validate the resposne.
Example:
lr_xml_find("XML={response}",
"Query=//SOAP-ENV:Body/*/LoanAmount",
"Value=2000",
LAST );
lr_xml_get_values("Xml={response}",
"Query=//SOAP-ENV:Header/*/UUID",
"ValueParam=UUID",
LAST);
Error Handling:
if (strcmp(lr_eval_string("{Response}"), "0") != 0 )
{lr_end_transaction (“Submit_Request", LR_FAIL);
LR_EXIT_ITERATION_AND_CONTINUE;
lr_error_message(“Invalid Response"));
return 0;
}
else
{lr_end_transaction ("Submit_Request ", LR_PASS);
}


Writing Script in Web(http/html) protocol:
We need to create Custom request using Web protocol & keep the xml request in the web request body.
Example:
web_custom_request("Weather SOAP Request",
"URL=http://www.webservice.nam.nsroot.net/GetLoanDetails",
"Method=POST",
"TargetFrame=",
"Resource=0",
"RecContentType=text/xml",
"Referer=",
"Mode=HTML",
"EncType=text/xml;charset=utf-8",
"Body=<<Your Complete XML Request>>"LAST);

We can capture complete response or any particular value using web_reg_save_paramfunction.
Check point can also be added using web_reg_findfunction.
If-Else statement can be used for error handling check.

Examples:
web_reg_find("Text/IC=ResponseCode>0<",LAST);

web_reg_save_param(“Complete_Response",
"LB=",
"RB=",
"NOTFOUND=warning",
"SEARCH=ALL",
"ORD=1",
LAST );



Virtual Table Server(VTS) Enhancements in LoadRunner 12.00

In LoadRunner 12.00, the VTS enhancements include multi-instance support, TruClient native support, sample data, etc. Another small handy feature is supporting database APIs in different protocols, which can be used as an alternative to VTS.

Multi-instance Support
The old 2.x version of VTS is a Windows application, and users can run multiple instances on a single machine. Each process will listen to a TCP port, and each will serve one data table. The VTS in LoadRunner 11.52 is web-based and run as a Windows service, however it can only serve one table per machine. We added this feature to the new VTS in LR 12.00 in response to customers' requests.

There are two ways to launch multiple instances of the VTS on the same machine - from the command line, and from the web UI.

For the VTS instances that are running on one machine, there are two types, which have some slight differences between them:
  • Main Instance: This is the instance that always run when the VTS service starts. It behaves the same as the VTS in LR 11.52. There can be only one main instance per machine, and user can create additional named instances from main instance UI.
  • Named Instance: There can be multiple named instances, as long as they have different names and ports, both of which should be unique across all instances.
The differences are:
  1. A named instance will only use one port, and the port is for both API access and Admin UI display.
  2. You cannot create other named instances on this Admin UI.
  3. The title of the Admin UI changed to ‘VTS - <Instance Name>’, so that the user can easily identify the instance from the tab, as follows:
p1.png

Here are some short descriptions on the two ways to manage instances.

1. Command-Line Mode
The command tool (vtscmd.js) is a JavaScript file that runs with node.exe, which can be found in the same folder. The following is the screen of the command mode.
p2.png


In the new version we will allow users to run the following commands:

  • node vtscmd /start /port 4001 /name <InstanceName>
  • node vtscmd /import file1.csv /port 4001 /delimiter \t

The first line starts a new instance and the second line imports the data file into the VTS table that listens on the same port. "/delimiter" is optional and by default uses ",".  The VTS Windows service should already be started when you run commands, and the command tool should be used on the same machine that runs the VTS service. All of the commands will communicate with the VTS service, so after launching the instances, they can survive the user logging out and machine restarts.

There are demo .bat files in the VTS installation folder, to show how to launch new instances of VTS and how to stop them. You can find them under folder "\Program Files\HP\VTS\web\samples". One limitation of this release is that when you try to stop the VTS instances, the process may still be running until you stop the VTS service. If instances are still running, it will block you from creating another instance with the same name or port. To make the ‘stop’ action take effect, you can restart the Windows service, with the command “net stop vtsservice” followed by “net start vtsservice”.

2. UI Mode
The user can also manage VTS instances from the main instance’s UI, with the File menu Options -> Other Instances. There are two dialogs, one to start new instances and the other to stop instances.
p3.png

Now one machine may run multiple instances of VTS, including one main instance and multiple named instances. In 12.00, API access of all instances will be enabled or disabled together, and only from the main instance UI. The following UI has been updated to reflect the change. Notice the tooltip indicates that "Enable/Disable API Access" action will affect all running instances:
p4.png

One more tip - the VTS runs on the node.js engine, and is written in JavaScript. Therefore, if you feel curious, you can open Task Manager to check how many node.exe processes running, to find out how many VTSs are running.
  
VTS Support in TruClient
In LR 11.52, the user needs to write VTS API calls in a C function, and then use it in TruClient scripts, which is not very convenient. As of 12.00, VTS JavaScript APIs are available in TruClient which can be used directly in TruClient steps. You can add "Evaluate JavaScript" step in the TruClient Sidebar, and add some code similar to the following:
TC.vtcConnect("localhost",8080,"myVTSAlias");
…
TC.vtcGetCell("columnName1",1, "myVTSAlias");
TC.vtcAddCell("columnName2", 1, "myVTSAlias");

Some Other Improvements
Sample data
Sample data has been added to VTS, for example, Customers and Employees, so that users can create sample scripts with data out-of-the-box. Just click the menu Options -> Import Samples to import the sample data table. If you have your own csv files and want to access them often, you can also put them under the samples folder, and the files will also displays on the menu.

Installation
The installation package contains both 32-bit version and 64-bit versions. If you have 64-bit windows, it will install the 64-bit version automatically, otherwise it will install the 32-bit version. The 64-bit version is expected to be more scalable because it uses 64-bit node.js. If you want to install VTS silently, you can run a command like "SetupVTS.exe /s /a /s". There’re actually 2 operations here – extraction files and then installation. Hence the “/s” appears twice, one for each stage.

Step Toolbox
The VTS API can be found in the VuGen Toolbox, so if you don't want to remember the long API names, you can drag and drop from the toolbox to use them.

Database API Support
Although database APIs have nothing to do with VTS, they can be used to make calls to databases in your script, allowing you to use databases as the shared parameter server. Before LR 12.00, there were several database APIs in the Web Service protocol:
  • lr_db_connect
  • lr_db_disconnect
  • lr_db_executeSQLStatement
  • lr_db_dataset_action
  • lr_checkpoint
  • lr_db_getvalue
But they can only be used when web service protocol is used. As of LR 12.00, we migrated them to all of the other C language protocols, e.g. Web HTTP/HTML, Flex, etc. You will notice that they appear on the Step Toolbox of VuGen, so you can design the database steps just as you did in the Web Service protocol.

Some More Information
There are some trouble-shooting tips, not necessarily related to LR 12.00 but worth mentioning here.
  • Some scripts use "lrvtc_update_message_ifequals" heavily and users have noticed that the API becomes slow when there is a lot of data. The cause is there is no index on the column. Just like databases, when there is no index on the column, checking uniqueness of a value will scan all the data. The solution is to add an index to this column. This can be achieved by either the Admin UI or lrvtc_ensure_index API in the script. Note that deleting the entire column will also delete the index, so the next time you create a column of the same name, you need to build index again.
  • If you wants to trouble shoot issues with VTS, you can check the log files. To troubleshoot remotely, you can also read the log file from the web URL http://<server>:4000/data/diag/log. Accessing the log remotely is by default turned off, but you can turn it on by changing the setting "enableDiag" to true in the configure.json file and restarting the service.
  • One common misunderstanding is the return value of the lrvtc_connect API. Unlike another similar API vtc_connect, which returns a handle, lrvtc_connect return the status code of connection. So vtc_connect returns non-zero when connecting successfully, while lrvtc_connect returns zero upon success. 

Virtual Table Server(VTS) in LoadRunner 11.52

With the release of 11.52, HP has released a whole new VTS, with some enhanced features in LR 12.00. The new VTS APIs is backward compatible and can be used in all protocols that uses C language as well as TruClient. You can see the new console UI in the below screen:

VTS2.png

Installation:
The new VTS consists of two parts, the vuser side is tightly integrated with the LoadRunner, and is installed with 11.52. The VTS server side needs separate download and install.

If you want to use the new VTS, you can take the following steps to install the new VTS and experience it:
  • Install 11.52 on all load testing machines, particularly, the VuGen and LG machines.
  • Install VTS server on a server machine, it can be a separate machine, or any of existing load testing machine, depends on how much load VTS service will have. You can either install 32 bits version or 64 bits version, depends on your OS type. After installation, the service will start automatically and you can browse to the VTS console UI. The default port is 4000, therefore the URL is something like http://localhost:4000. You can specify a different port during the install or afterwards.
  • On the console UI, you can import data by uploading a CSV file, or typing in a connection string to import from database directly. The following screen shows the UI of importing data&colon;VTS3.png
  • Create a C language script, like Web Http/Html script. Add VTS API in vuser_init method to connect to the server, like the following:
int   rc = 0;
char  *VtsServer = "192.168.0.100";
int   nPort = 8888; 

PVCI2 pvci = 0;
vuser_init()
{
    pvci = lrvtc_connect(VtsServer,nPort,VTOPT_KEEP_ALIVE);
    lr_log_message("pvci=%d\n", pvci); 
    return 0;
}
  • In Action.c, add some code to retrieve one column from the server and remove from the server at the same time. You can run the action multiple iterations, and it will retrieve one:
char * cname; //column name
int ret;

RetrieveMessage()
{
    lr_start_transaction("retrieve_column");
    rc =  lrvtc_retrieve_messages1("cname",";");
    lr_log_message("lrvtc_retrieve_messages1 rc=%d\n", rc);
    lr_log_message("cname is %s", lr_eval_string("{cname}"));
    lr_end_transaction("retrieve_column", LR_AUTO);
}

Action()
{
    RetrieveMessage();
    return 0;
}

  • In vuser_end.c, add API call to close the VTS handle:
vuser_end()
{
    lrvtc_disconnect();   
    return 0;
}

  • You can test it in VuGen and run it in Controller. Don’t forget to turn on the API access port before you run the script. Like old VTS, the new one use 8888 as the port for API to access. It is turned off by default, so you need to browse to the administrative UI to enable it.