Labels

Friday, August 21, 2015

Loadrunner- Selecting random value through c code, Encoding

int AcctsCount, iStart, secAcct;
int ThinkTime =5;
int AccountCount,AccountCheck, IterationCount, Rand1, Rand2;
char FromAccount[20];
char ToAccount[20];
char RandomIndex[30];



correlation
---------
web_reg_save_param("Accounts",
 "LB=\"accountVal\":\"",
 "RB=\"",
 "Ord=All",
 "NotFound=warning",
 LAST);

 web_custom_request("ExecGetAccountDetailsAjax.do",
 "URL=http://{p_BaseUrl}/URI/ExecGetAccountDetailsAjax.do?action=INIT&transferType=INT",
 "Method=POST",
 "Resource=0",
 "RecContentType=text/xml",
 "Referer= http://{p_BaseUrl}/URIreferer.do",
 //"Snapshot=t209.inf",
 "Mode=HTML",
 "Body=",
 LAST);





AcctsCount = atoi( lr_eval_string("{Accounts_count}") );
 AccountCount=atoi( lr_eval_string("{Accounts_count}") );
   
 if (  AccountCount <= 4)  {
 lr_exit( LR_EXIT_ITERATION_AND_CONTINUE,
  LR_FAIL );
 }
 else
 {
  Rand1 = (rand() % ((AccountCount/2) -2 )) + 2;
 rand(  );
 rand(  );
 rand(  );
 rand(  );
  Rand2 = (rand() % ((AccountCount/2) -2 )) + 2;       
 rand(  );
 rand(  );
 rand(  );
 rand(  );
  AccountCheck=0;
  IterationCount=0;
  while (AccountCheck == 0) {
   IterationCount = IterationCount + 1;
   if (Rand1 == Rand2) {
    Rand2 = (rand() % ((AccountCount/2) -1 )) + 2;
 rand(  );
 rand(  );
 rand(  );
 rand(  );
   }
   else{
    AccountCheck = 1;
   }
   if (IterationCount == 10) {
    AccountCheck = 1;
 lr_exit( LR_EXIT_ITERATION_AND_CONTINUE,
  LR_FAIL );
   }
  }



/* sprintf( RandomIndex,"{Accounts_%d}",2 ); //3
 lr_save_string( lr_eval_string(RandomIndex),"FromAccount" );
 sprintf( RandomIndex,"{DisplayVal_%d}", 2 );//3
 lr_save_string( lr_eval_string(RandomIndex),"FromAccountDisplay" );
 sprintf( RandomIndex,"{TRANSFER_%d}", 2 );//3
 lr_save_string( lr_eval_string(RandomIndex),"TransferType" );
 sprintf( RandomIndex,"{Accounts_%d}",4 );
 lr_save_string( lr_eval_string(RandomIndex),"ToAccount" );
 sprintf( RandomIndex,"{DisplayVal_%d}",4 );
 lr_save_string( lr_eval_string(RandomIndex),"ToAccountDisplay" );
*/

 for(iStart=2;iStart<=AcctsCount;iStart++)
 {
  //sprintf(DisplayName, "DisplayVal_%d", iStart);
  //lr_paramarr_idx("DisplayVal", iStart);
  if((char *)strcmp(lr_eval_string(lr_paramarr_idx("Accounts", iStart)), "")!=0)
  {
   lr_save_string(lr_paramarr_idx("Accounts", iStart), "FromAccount");
   lr_save_string(lr_paramarr_idx("DisplayVal", iStart), "FromAccountDisplay");
   lr_save_string(lr_paramarr_idx("TRANSFER", iStart), "TransferType");
   secAcct=iStart+1;
   break;
  }
 }
 for(iStart=secAcct;iStart<=AcctsCount;iStart++)
 {
  //sprintf(DisplayName, "DisplayVal_%d", iStart);
  //lr_paramarr_idx("DisplayVal", iStart);
  if((char *)strcmp(lr_eval_string(lr_paramarr_idx("Accounts", iStart)), "")!=0)
  {
   lr_save_string(lr_paramarr_idx("Accounts", iStart), "ToAccount");
   lr_save_string(lr_paramarr_idx("DisplayVal", iStart), "ToAccountDisplay");
   //lr_save_string(lr_paramarr_idx("TRANSFER", iStart), "TransferType");
   //secAcct=iStart+1;
   break;
  }
 }




//Converting into Base-64 encoding
char *convert( char *src)
{
 int dest_size; 
    char *deststr;   
 
    // Allocate dest buffer 
     dest_size = 1 + ((strlen(src)+2)/3*4); 
     deststr = (char *)malloc(dest_size); 
     memset(deststr,0,dest_size); 
    base64encode(src, deststr, dest_size); 
     return deststr; 
}
void base64encode(char *src, char *dest, int len) 
// Encodes a buffer to base64 
 { 
 char base64encode_lut[] = { 
 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q', 
 'R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h', 
 'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', 
 'z','0','1','2','3','4','5','6','7','8','9','+','/','='}; 

   int i=0, slen=strlen(src); 
   for(i=0;i   { // Enc next 4 characters 
     *(dest++)=base64encode_lut[(*src&0xFC)>>0x2]; 
     *(dest++)=base64encode_lut[(*src&0x3)<<0x4 amp="" src="" xf0="">>0x4]; 
     *(dest++)=((i+1)>0x6]:'='; 
     *(dest++)=((i+2)   } 
   *dest='\0'; // Append terminator

}





//Preparing the query string & passing to base-64 encoding
char *getParam(char *str,
      char *param1,
      char *param2,
      char *param3,
      char *param4,
      char *param5,
      char *param6,
      char *param7,
      char *param8,
      char *param9,
      char *param10,
      char *param11,
      char *param12,
      char *param13,
      char *param14,
      char *param15,
      char *param16
      //char *param17,
      //char *param18,
       //char *param19,
       //char *param20
      //char *param16)

{
 char *temp;
 char *src, *target;
 char param[4000];
 temp="";
 src="";
 target="";
 temp=str;
 strcpy(param,"");
 strcat(param,temp);
 strcat(param,param1);
 strcat(param,param2);
 strcat(param,param3);
 strcat(param,param4);
 strcat(param,param5);
 strcat(param,param6);
 strcat(param,param7);
 strcat(param,param8);
 strcat(param,param9);
 strcat(param,param10);

 //strcat(param, "&fromAccount=");
 strcat(param,param11);

 //strcat(param, "&toAccount=");
 strcat(param,param12);
 //strcat(param, "&paymentamount=");
 strcat(param,param13);
    //strcat(param, "&initiationDate=");
 strcat(param,param14);
 //strcat(param, "&estArrivalDate=");
 strcat(param,param15);
 //strcat(param, "&businessDate=");
 strcat(param,param16);
  //strcat(param,param17);
  //strcat(param,param18);
  //strcat(param,param19);
  //strcat(param,param20);

     src=(char *) param;
 //lr_output_message(" Created param value %s",param);
    target=convert(src);
 return target;
}

QC and Load Runner Integratio​n


Got below response from one of the HP support personnel
You have to consider also the versions. LR 11 can only work with QC 10. Check the Controller and Vugen guide for more details.

If you are customer you can try posting on our internal forums for more personalized support.

LoadRunner:
http://h30499.www3.hp.com/t5/LoadRunner-Support-Customer/bd-p/loadrunner-support-customer-forum

Performance Center:
http://h30499.www3.hp.com/t5/Performance-Center-Support/bd-p/performance-center-support-customer

How to:
http://www.youtube.com/watch?v=4ChlysWupWM

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution

Tuesday, July 7, 2015

LR Helps

Transactions pass/fail
========================
 //checking a transaction pass or fail based on text check
 web_reg_find("Text=Trainer Regions List", "SaveCount=Text_Count",
  LAST);
 if(atoi(lr_eval_string("{Text_Count}"))>0){
  lr_end_transaction("3DR_SXX_T0X_LaunchPage",LR_PASS);
 }
 else
 {
  lr_end_transaction("3DR_SXX_T0X_LaunchPage",LR_FAIL);
 }

===========================================================================================================
Removing char from string
========================
#include
 void remchar(char *s, char chr){
  int i, j = 0;   for ( i = 0; s[i] != '\0'; i++ ) /* 'i' moves through all of original 's' */  
{     
     if ( s[i] != chr )     
 {
         s[j++] = s[i]; /* 'j' only moves after we write a non-'chr' */
       }
   }

   s[j] = '\0'; /* re-null-terminate */
}
 int main(){ 
 char text[] = "The quick brown fox jumps over the lazy dog.";
   printf("before : %s\n", text);
   remchar(text, 'o');
   printf("after  : %s\n", text);
   return 0;
}
/* my output
 before : The quick brown fox jumps over the lazy dog.
after  : The quick brwn fx jumps ver the lazy dg.*/
===========================================================================================================
PuTTY
=====
First, let's clarify the terminology for you.
1) putty is not a command, it is a standalone terminal client.
2) putty does not have commands. The 'commands' depend on what server you are connected to is using as a shell. In this case, it SOUNDS like you are connecting to BASH. A quick google of 'Bash commands' will tell you what commands are available. Putty can also connect to winblows servers or servers that run entirely different command sets, and even old school dialup BBS systems.
3) Downloading files in a BASH session will NOT store them on your computer but on the server you are connected to - there really is no practical way to move files from a remote bash session to your local system unless your local system is set up as an FTP server. You want to grab files from your remote system, that's what FTP is for. If your FTP login doesn't have access to the same directories as BASH or whatever shell you are logged into, copy the file to a directory you DO have FTP access to.
4) This has nothing to do with programming
===========================================================================================================
Do-while
========
web_save_timestamp_param("p_Starttime",LAST);
 web_save_timestamp_param("p_tStamp",LAST);
 lr_output_message("StartTime= %s ",lr_eval_string("{p_Starttime}"));
 //---------------------------------------------------------------------------
 do
 {

 web_submit_data("checkDeploymentStatus.jsp",
  "Action=http://{p_URL}/URIxxx/checkDeploymentStatus.jsp?dummy={p_tStamp}",
  "Method=POST",
  "RecContentType=text/html",
  "Referer=http://{p_URL/URIxxx/ShowDeployedFiles.jsp",
  "Mode=HTML",
  ITEMDATA,
  "Name=jobID", "Value={c_JobID}", ENDITEM,
  LAST);
    lr_output_message("Iteration No:%i",i);
    i=i+1;


 }while(i<=55);
 web_save_timestamp_param("p_Endtime",LAST);
 lr_output_message("End Time= %s ",lr_eval_string("{p_Endtime}"));

 //-----------------------------------------------------------------------------
===========================================================================================================
global section
---------------
const int tt=5;
int n=1;
char OfficeList[100], FAList[100];
int g1;
char strOfficeFAXml[9999];
--------------
Action
----------------
  web_reg_save_param("OfficeList",  "LB=\\u003cFa\\u003e",  "RB=\\u003c/Fa",  "Ord=All",  "NotFound=Warning",   LAST);
  web_reg_save_param("FAList",  "LB=\\u003cFa\\u003e",  "RB=\\u003c/Fa",  "Ord=All",  "NotFound=Warning",   LAST);
  strcpy(strOfficeFAXml, "");


  for (g1=1; g1<=atoi(lr_eval_string("{OfficeList_count}")); g1++)
  {
  strcat(strOfficeFAXml, "");
  strcat(strOfficeFAXml, lr_paramarr_idx("OfficeList", g1));
  strcat(strOfficeFAXml, "
");
  strcat(strOfficeFAXml, lr_paramarr_idx("FAList", g1));
  strcat(strOfficeFAXml, "
");
  }

  lr_save_string(strOfficeFAXml, "OfficeFAListXml");
  lr_message("OfficeFAListXml :%s", lr_eval_string("{OfficeFAListXml}"));

===========================================================================================================
set this function in inint  web_set_sockets_option("SSL_VERSION","TLS");
 Enable Integrated Authetication to yesfrom preferences.
Set proxy to enable firewall unblocking

When loadrunner is unable to record in that case add hosts entry in host file under below path to make loadrunner record events
Go to C:\WINDOWS\system32\drivers\etc\hosts file
or type drivers in run dialog box

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1       localhost
IP benefitaccess-qa.morganstanley.com
#xx.xx.xxx.xxx domainname upto .com


=============================================================================
Why ping throws request timed out message.
A ping is an ICMP packet. For comparison, web traffic or HTTP, is generally a TCP packet on port 80. A given server may be providing responses for the purpose of web traffic, but block ICMP (or be behind a firewall that blocks ICMP) and therefore you can:
  • Resolve the URL to its IP address
  • Connect and view the web content
But you cannot ping the IP address. The response "request timed out" is because your client sends the initial packet, waits for a reply (which will never come), and gives up at a preset timeout

Wednesday, March 18, 2015

Floor Function In Loadrunner

My collegue came across a situtation where he needed to convert a correlated value to floor. Any value with fractional part greater than .5 should be converted to next nearest integer. However, the valueswith fractional part less than .5 were normally getting converted to nearest lower interger.
e.g.
4.2=4
4.6=5
We came up to a solution that works in this case

double inputval =  4.454567878E8;
> double result = floor(inputval + 0.5);