Tuesday, October 15, 2013

LoadRunner Script formatter

This formats the following in the recorded loadrunner script
  1. Timestamps
  2. comments out the Extrares
  3. deletes unwanted server calls (need to specify)
this is a swing program and this can be exported as a jar file and can be used.

import java.io.*;
import javax.swing.*;
//deletes the unwanted lines
import java.awt.GridLayout;
public class LrScriptFormatter1 {
 public static void main(String[] args) {
   
  JPanel panel = new JPanel(new GridLayout(2, 0, 0, 0));
  JTextField field1 = new JTextField("C:\\LRScriptFormater\\Raw.txt");
  JTextField field2 = new JTextField("C:\\LRScriptFormater\\Out.txt");
  panel.add(new JLabel("Raw File:"));
  panel.add(field1);
  panel.add(new JLabel("Output File:"));
  panel.add(field2);
  
  String inFile = field1.getText();
  String outFile = field2.getText();
  int option = JOptionPane.showConfirmDialog(null, panel,
    "LoadRunner Script Formatter - by TLQE", JOptionPane.OK_CANCEL_OPTION,
    JOptionPane.PLAIN_MESSAGE);
  if (option == JOptionPane.OK_OPTION) {
   inFile = field1.getText();
   outFile = field2.getText();
   JPanel panelOK = new JPanel(new GridLayout(1, 0));
   JOptionPane.showMessageDialog(panelOK, "Processing \n1: Web_add_cookies \n2: Timestamps", "TLQE", JOptionPane.INFORMATION_MESSAGE);
  }else if (option == JOptionPane.CANCEL_OPTION) {
   JPanel panelCancel = new JPanel(new GridLayout(1, 0));
   JOptionPane.showMessageDialog(panelCancel, "Bye Bye", "TLQE", JOptionPane.INFORMATION_MESSAGE); 
   return;
  }
    
  
  File fileTemp = new File(outFile);
  if (fileTemp.exists()) {
   fileTemp.delete();
  }
   
  try {
   String fileName = inFile + "";
   FileInputStream fstream = new FileInputStream(fileName);
   DataInputStream in = new DataInputStream(fstream);
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
   FileWriter fOutstream = new FileWriter(outFile, true);
   BufferedWriter out = new BufferedWriter(fOutstream);
   String newString = null;
   String strLine;
   while ((strLine = br.readLine()) != null){
    try {
     if (strLine.contains("web_add_cookie")) {
     } else if (strLine
       .contains("\"Name=_lastSubmitTimestamp\", \"Value=")) {
      if (strLine.matches(".*[0-9].*")) {
       newString = strLine
         .replaceAll(strLine,
           "\t\t\"Name=_lastSubmitTimestamp\", \"Value={tStamp}\", ENDITEM,");
       out.write(newString);
      } else
       out.write(strLine);
     } else if (strLine
       .contains("\"Name=postTimestamp\", \"Value=")) {
      if (strLine.matches(".*[0-9].*")) {
       newString = strLine
         .replaceAll(strLine,
           "\t\t\"Name=postTimestamp\", \"Value={tStamp}\", ENDITEM,");
       out.write(newString);
      } else
       out.write(strLine);
     }else if (strLine.contains("web_submit_data")) {
      out.write("\tweb_save_timestamp_param(\"tStamp\", LAST );");
      out.newLine();
      out.newLine();
      out.write(strLine);
     }else if (strLine.contains("web_custom_request(\"TealeafTarget.jsp")) {
      out.newLine();
      while ((strLine = br.readLine()) != null){
       out.newLine();
       if (strLine.contains("LAST")) {
        break;
       }
     }
     }else if (strLine.contains("web_url(\"SFXClientLogging")) {
      while ((strLine = br.readLine()) != null){
       if (strLine.contains("LAST")) {
        break;
       }
     }
     }else if (strLine.contains("EXTRARES")) {
      out.write(strLine);
      out.newLine();
      while ((strLine = br.readLine()) != null){
       if (strLine.contains("LAST")) {
        out.write(strLine);
        out.newLine();
        break;
       }else{
        out.write("//" +strLine);
        out.newLine();
       }
     }
     }
     else
      out.write(strLine);
     out.newLine();
    } catch (Exception e) {
     System.err.println("Error: " + e.getMessage());
    }
   }
   in.close();
   out.close();
  }catch (Exception e) {
   System.err.println("Error: " + e.getMessage());
  }
 }
}
 

Wednesday, October 9, 2013

Validating a transaction by using the web_reg_find

web_reg_find("Text=Thank You",
       "SaveCount=ThankYouPageCount",
  LAST);

    nFound = atoi( lr_eval_string("{ThankYouPageCount}") );
    if (nFound == 0){
    lr_end_transaction("Scn03_Screen72_ThankYou", LR_FAIL);
    }
    else{
    lr_end_transaction("Scn03_Screen72_ThankYou", LR_PASS);
    }

Monday, October 7, 2013

Required Transactions Per Second Calculator

Think time Value No of Think Times in Script Total Think time in script Approx Run Time of script Total Run Time of script - SEC no of Iterations in 1 Hr Total No of Users Total Iters in 1 Hr (by All users) Total Iters in 2 hrs
Scenario 2 9 18 20 38 94.74 38 3600 7200
         
                   
Total Iter 3600 7200
TPS 1 1


Expected TPS 0.76 0.25 0.18 2
No of Iter in 2 hrs 5472 1800 1296 14400
No of Iter in 1 hr       7200

Tuesday, October 1, 2013

Random String Generator with no consecutive duplicate characters

this function generates a random string of required length with no consecutive duplicate characters. This can be used for generating passwords (with no duplicate consecutive characters like zzztest)

random_Generator(char* paramname, int length) {
char buffer[32] = "";
int r,i;
char c;
srand((unsigned int)time(0));
for (i = 0; i < length; i++) {
r = rand() % 25 + 65;
c = (char)r;
buffer[i] = c;
if (buffer[i] == buffer[i-1])
{
r = rand() % 25 + 65;
c = (char)r;
buffer[i] = c;
}
}
lr_save_string(buffer, paramname);
return 0;
}

Action()
{
random_Generator( "Random_LastName",
10 );
    lr_output_message("LastName  = %s", lr_eval_string("{Random_LastName}"));
return 0;
}

Monday, September 23, 2013

download a file and save it to local disk

 download a file and save it to local disk
 
 
long fp;
 char *data;
 long prmLen;
 char fileName[50];
 int pdf_size;
-------
 web_set_max_html_param_len("2000000");
 
 web_reg_save_param_ex(
  "ParamName=sPrintPDF",
  "LB=",
  "RB=",
  LAST);
-----------------
   
sprintf(fileName, "C:\\Junk\\file_%s.pdf", lr_eval_string("{iterNo}"));
   fp = fopen(lr_eval_string(fileName), "wb");

 pdf_size = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );
 fwrite(lr_eval_string("{sPrintPDF}"),pdf_size,1,fp);
 fclose(fp);