Latest Entries »


Use the below functions in Vugen to overcome this error.

 

web_set_sockets_option(“MAX_CONNECTIONS_PER_HOST”,”10″);
web_set_sockets_option(“MAX_TOTAL_CONNECTIONS”,”10″);

 

Advertisements

Use the below functions in Vugen script to overcome this error.

web_set_sockets_option (“CLOSE_KEEPALIVE_CONNECTIONS”, “1”);
web_set_sockets_option(“MAX_CONNECTIONS_PER_HOST”,”1″);
web_set_sockets_option(“OVERLAPPED_SEND”, “0”);
web_set_sockets_option(“IGNORE_PREMATURE_SHUTDOWN”, “1”);
web_enable_keep_alive();


char *date=”27 mar 2010″;
char *position;
int offset;
char *search_str[20] = {“jan”,”feb”,”mar”,”apr”,”may”,”jun”};
char *search_strvalue[20] = {“01″,”02″,”03″,”04″,”05″,”06″};
char * tokens;
char reqValue[100];
int i,j;

vuser_init()
{
lr_save_string(lr_eval_string(date),”date_new”);
lr_output_message(“%s”,lr_eval_string(“New date is {date_new}”));

j=0;
do
{
position = (char *)strstr(date, search_str[j]);
offset = (int)(position – date + 1);
j++;
} while (offset != 4);

tokens=(char *)strtok(lr_eval_string(“{date_new}”),” “);
i=0;
while (tokens!=NULL)
{
if(strcmp(tokens,search_str[j-1])==0)
{
strcat(reqValue, ” “);
strcat(reqValue, search_strvalue[j-1]);
strcat(reqValue, ” “);
}
else
{
strcat(reqValue,tokens);
}
tokens = (char *)strtok(NULL,” “);
}
lr_save_string(lr_eval_string(reqValue), “NewFormatDate”);

return 0;
}


C:\Program Files\HP\LoadRunner\bin>mmdrv.exe -usr DateFormatChange\DateFormatChange.usr

scripts should be placed inside the bin folder..


Put this code inside the action:-

char filename[1024], command[1024];
char new_dir[] = “C:\\Sample”;

/* Create a directory under root called xyz and make it the current dir */
if (mkdir(new_dir))
lr_output_message(“Create directory %s failed”, new_dir);
else
lr_output_message(“Created new directory %s”, new_dir);

sprintf (filename, “%s\\%s”, new_dir, “SIVA.txt”);

/* Execute a dir /b command and direct it to a new file */
sprintf (command, “dir /b c:\\ > %s /w”, filename );
system(command);
lr_output_message(“Created new file %s”, filename);

return 0;


typeperf -c “\Process(*)\% Processor Time” -si 00:01 -sc 50 -f CSV -o output.csv
typeperf -q -o output1.txt


Below is the snippet to be used for performance testing the SMTP server with bulk email messages or per your project needs,

 

Action()
{
// connect to smtp mail server
smtp_logon(“Logon”,
“URL=smtp://{P_userID}@mail.o365am.xxx.com:xxxx”,
“CommonName=SMTP {P_userID}”,
“LogonUser={P_LoginEmailID}”,
lr_decrypt(“5d564d6e185f6c5457b32fc024bc4a91aaacc3c”),
“STARTTLS=STARTTLS”,
LAST );

// send email
smtp_send_mail(“SendMail”,
“To={P_RecepientEmail}”,
“Cc={P_RecepientEmail}”,
“Bcc={P_RecepientEmail}”,
“From={P_LoginEmailID}”,
“Subject=Testing SMTP message from Load Runner”,
“ContentType=text/plain;”,
“charset=UTF-8”,
//     MAILOPTIONS,
//     “X-Priority: 3”,
//     “X-MSMail-Priority: Normal”,
//     “X-Mailer: Microsoft Outlook Express 5.00.2919.6700”,
//     “X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700”,
MAILDATA,
“MessageText=This is a simple mail from LR\r\n”,
LAST );

// wait time
lr_think_time(2);

// disconnect from server
smtp_logout();

return 0;
}


By using the below command, we can remote login to machine even though a session is already opened.

mstsc /v:{server name} /admin


As OAuth Token is currently used in most of the REST services for authentication purpose, it is little tricky to have LR VUGEN HTTP Script ready with the test data. So we can go for JAVA protocol and use the below codes. Discuss with the development team and get algorithms which are getting used and change the below code accordingly

 

/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/

//Set ClassPath for below jar file in RunTime Settings
//javax-crypto.jar
//xml-security-impl-1.0.jar
//spring-web-3.1.0.RELEASE.jar

import lrapi.lr;
import lrapi.web;

import javax.crypto.Mac;
import java.util.UUID;
import javax.crypto.spec.SecretKeySpec;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.net.URLEncoder;

public class Actions
{
private static final String HMAC_SHA256_ALGORITHM=”HmacSHA256″;
private static final String AUTHENTICATION = “Authentication”;
private static final String AUTHORIZATION = “Authorization”;
private static final String API_KEY = “X-ABCD-API-KEY”;
private static final String GRANT_TYPE = “grant_type”;
private static final String SCOPE = “scope”;
private static final String HEADER_ACCOUNT_NO = “account_no”;
private static final String DOCUMENT_BODY = “document_body”;
private static final String DOCUMENT_NAME = “document_name”;
private static final String DOCUMENT_TYPE = “document_type”;
private static final String DOCUMENT_FORMAT = “document_format”;
private static final String DOCUMENT_M5_CHECKSUM = “document_md5_checksum”;
private static final String DOCUMENT_DATE = “document_date”;
private static final String DOCUMENT_KEY = “documentKey”;
private static final String DOCUMENT_FILE_NAME = “document_file_name”;

public int init() throws Throwable
{
return 0;
}//end of init
public int action() throws Throwable
{

String client_id = “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx”; //lr.eval_string(“{P_ClientID}”);
String client_secret = “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx”; //lr.eval_string(“{P_ClientSecret}”);
String grant_type = “client_credentials”;
String macToken=””;
String access_token=””;
String authorization_header = null;
String strAccountNumber=null;
String fileName=null;
String date1=null;
String serviceStatusCode = null;

macToken = generateMacToken(client_id,client_secret,grant_type);

web.set_sockets_option(“SSL_VERSION”,”TLS”);
web.add_auto_header(“Content-Type”,”application/x-www-form-urlencoded”);
//web.add_auto_header(“Authentication”,”MAC id=\”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx\”,ts=\”1458797751846\”,nonce=\”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx:ABCD\”,mac=\”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=\””);
web.add_auto_header(“Authentication”, macToken.toString());
web.add_auto_header(“X-ABCD-API-KEY”,”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx”);

web.reg_save_param(“C_AccessToken”,new String[]{“LB=\”access_token\”:\””,”RB=\”,\n”,”LAST”});
web.reg_save_param(“C_MacKey”,new String[]{“LB=\”mac_key\”:\””,”RB=\”,\n”,”LAST”});

web.custom_request(“web.custom_request”,
“Method=POST”,
new String[]{“URL=https://test.environment.com/ssssssssss/v2/oauth/token/mac”,
“TargetFrame=”,
“Resource=0”,
“Referer=”,
“Body=grant_type=client_credentials&scope=”,
“LAST”});

macToken = lr.eval_string(“{C_MacKey}”);
access_token = lr.eval_string(“{C_AccessToken}”);
String service_uri = “/xxxxxxxxxxxxxx/xx/xxxxxxxxxxxxxxx/xxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
String host_name = “test.environment.com”;
authorization_header = generateMacAuthToken(client_id,macToken,access_token,service_uri,host_name,”443″,”POST”);

web.set_sockets_option(“SSL_VERSION”,”TLS”);
web.add_auto_header(“Content-Type”,”multipart/form-data”);
//web.add_auto_header(“Authorization”,”MAC id=\”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx\”,ts=\”1458797868653\”,nonce=\”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx:ABCD\”,mac=\”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx””);
web.add_auto_header(“Authorization”,authorization_header.toString());
web.add_auto_header(“account_no”,”xxxxxxxxxxxxx”);
web.add_auto_header(“X-ABCD-API-KEY”,”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx”);

web.custom_request(“web.custom_request”,
“Method=POST”,
new String[]{
“URL=https://test.environment.com/ssssssssssssssss/v1/dddddddddd/eeeeeeeee/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“TargetFrame=”,
“Resource=0”,
“Referer=”,
“Body=document_body=B@1b15887&document_name=DocumentName&document_file_name=fileName.pdf&document_type=cc&document_format=PDF&document_md5_checksum=ddddddddddddddddddddddddddddddd&document_date=1457931150709”,
“LAST”});

return 0;
}//end of action

public static final String generateMacToken(String client_id,String client_secret,String granttype) throws Exception{
//java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE());
String uuid= UUID.randomUUID().toString();
////System.out.println(“uudi – >” + uuid);
String nonce = uuid+”:ABCD”;
////System.out.println(“nonce – >” + nonce);
String ts = String.valueOf(((long)System.currentTimeMillis()));
////System.out.println(“ts – >” + ts);
String tsn = ts + “\n”;
String noncen = nonce + “\n”;
//base string
String baseString = client_id+”\n”+tsn+noncen+granttype+”\n”;
////System.out.println(“baseString – >” + baseString);
//Generate signature using client secret
SecretKeySpec signingKey = new SecretKeySpec(client_secret.getBytes(“UTF-8”), HMAC_SHA256_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
mac.init(signingKey);
byte[] signatureBytes = mac.doFinal(baseString.getBytes(“UTF-8”));
String signatureStr=Base64.encode(signatureBytes);
////System.out.println(“signatureStr – >” + signatureStr);
String mac_authentication_header = “MAC id=\””+client_id+”\”,ts=\””+ts+”\”,nonce=\””+nonce+”\”,mac=\””+signatureStr+”\””;
System.out.println(“The value of mac_authentication_header –>” + mac_authentication_header);
return mac_authentication_header;
}

public static final String generateMacAuthToken(String client_id,String mac_key,String access_token,String resourcePath,String host,String port,String httpMethod ) throws Exception{
String uuid= UUID.randomUUID().toString();
String nonce = uuid+”:AAAA”;
String ts = String.valueOf(((long)System.currentTimeMillis()));
String tsn = ts + “\n”;
String noncen = nonce + “\n”;
String hostn = host+”\n”;
String portn = port+”\n”;
String resourcePathn = URLEncoder.encode(resourcePath)+”\n”;
String httpMethodn = httpMethod+”\n”;
//base string
String baseString = tsn+noncen+httpMethodn+resourcePathn+hostn+portn+”\n”;
//Generate signature using client secret
SecretKeySpec signingKey = new SecretKeySpec(mac_key.getBytes(“UTF-8”), HMAC_SHA256_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
mac.init(signingKey);
byte[] signatureBytes = mac.doFinal(baseString.getBytes(“UTF-8”));
String signatureStr=Base64.encode(signatureBytes);
String mac_authorization_header = “MAC id=\””+access_token+”\”,ts=\””+ts+”\”,nonce=\””+nonce+”\”,mac=\””+signatureStr+”\””;
return mac_authorization_header;
}
public int end() throws Throwable
{
return 0;
}//end of end
}


Sometimes there might be a requirement to keep some files in the LG machine for temporary use. Have the file included in the script which needs to be copied to LG machine. Use the below mentioned commands to create a temporary folder inside c:\temp folder and copy the file from script folder to newly created folder in LG machine. Once the use of file is completed, use the last command to delete the newly created folder. Char command1[]=”mkdir \”c:\\temp\\\ext_jar”;

Char command2[]=”xcopy /Y filename.pdf \”c:\\temp\\\ext_jar\””;

Char command3[]=”RD /S /Q \”c:\\temp\\\ext_jar\””;

System(command1);

System(command2);

Lr_think_time(5);

System(command3);