Difference between revisions of "LoadRunner FAQ"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: = LoadRunner FAQ = Also see Load Testing reference... == Transaction Functions == See manual section 'VuGen Function Reference > Utility Functions: C Language (LR) > Transaction Tr...)
 
 
(9 intermediate revisions by the same user not shown)
Line 13: Line 13:


<pre>
<pre>
double time_elapsed, duration, waste;  
  double time_elapsed, duration, waste;  


merc_timer_handle_t timer;  
  merc_timer_handle_t timer;  


      lr_start_transaction("sampleTrans");
  lr_start_transaction("sampleTrans");  
      web_url("index.htm",
              "URL=http://localhost/index.htm",
              "TargetFrame=",
              "Resource=0",
              "RecContentType=text/html",
              "Referer=",
              "Snapshot=t1.inf",
              "Mode=HTML",
              LAST);  


      timer = lr_start_timer();  
  web_url("index.htm",
          "URL=http://localhost/index.htm",
          "TargetFrame=",
          "Resource=0",
          "RecContentType=text/html",
          "Referer=",
          "Snapshot=t1.inf",
          "Mode=HTML",
          LAST);  


/* Do some checks the duration of which
  timer = lr_start_timer();


is not to be included in the transaction. */
  // Do some checks the duration of which is not to be included in the transaction.


      web_image_check("ImgCheck1",  
  web_image_check("ImgCheck1",  
              "src=index_files/image002.jpg",  
          "src=index_files/image002.jpg",  
              LAST);  
          LAST);  


      web_image_check("ImgCheck2",  
  web_image_check("ImgCheck2",  
              "src=index_files/planets.gif",  
          "src=index_files/planets.gif",  
              LAST);  
          LAST);  


// How long did the tests take in seconds.  
  // How long did the tests take in seconds.  


      time_elapsed = lr_end_timer(timer);  
  time_elapsed = lr_end_timer(timer);  


// Convert to millisecond.s  
  // Convert to millisecond.s  


      waste = time_elapsed * 1000;  
  waste = time_elapsed * 1000;  


/* Remove the time the checks took from  
  // Remove the time the checks took from the transaction.


      the transaction. */
  lr_wasted_time(waste);


      lr_wasted_time(waste);  
  lr_end_transaction("sampleTrans", LR_AUTO);
</pre>
 
=Programmatically Controlling Logging=
 
Use something like...
 
<pre>
  int log_profile = LR_MSG_CLASS_EXTENDED_LOG
                        |
                    LR_MSG_CLASS_FULL_TRACE
                        |
                    LR_MSG_CLASS_RESULT_DATA
                        |
                    LR_MSG_CLASS_PARAMETERS;
 
  ...
 
  lr_set_debug_message(log_profile, LR_SWITCH_ON);
 
  ... Code you want extended logging for ...
 
  lr_set_debug_message(log_profile, LR_SWITCH_OFF);  


        lr_end_transaction("sampleTrans", LR_AUTO);
  ...
</pre>
</pre>
=Capturing a Downloaded File=
* Set up a parameter to capure the entire page returned.
* Determine its length.
* Create a function to write this buffer to a file.
e.g.
<pre>
//---------------------------------------------------------------------------------
int WriteDataToFile(char *szFileName, const char *szBuf, int len)
{
    int hFile;
   
    hFile = fopen(szFileName,"wb");
    if (hFile == NULL)
    {
        lr_error_message("Could't create or open the file: %s", szFileName);
        return LR_FAIL;
    }
    fwrite(szBuf, len, 1, hFile);
    fclose(hFile);
    return LR_PASS;
}
//---------------------------------------------------------------------------------
Action()
{
    char *szBuf;
    unsigned long nLength;
    // Function web_set_max_html_param_len sets maximum length of any HTML string,
    // that can be retrieved and saved as a parameter
    // So, make sure new value is greater than a size of string (in our case - file) to be captured
    web_set_max_html_param_len("100000");
    web_reg_save_param("prmLogoImage", "LB=\r\n\r\n", "RB=", LAST);
    web_url("logo.gif",
        "URL=http://www.google.com/intl/en_ALL/images/logo.gif",
        "Resource=1",
        "RecContentType=image/gif",
        "Snapshot=t1.inf",
        LAST);
    lr_eval_string_ext ("{prmLogoImage}", strlen("{prmLogoImage}") /* = 14*/, &szBuf, &nLength, 0, 0,-1);
    lr_output_message("Parmeter length = %d",nLength);
    WriteDataToFile("C:\\LogoImage.gif", szBuf, nLength);
    return 0;
}
//---------------------------------------------------------------------------------
</pre>
See http://motevich.blogspot.com/2007/10/loadrunner-save-download-file-server.html
=What is the Difference Between HTML and URL Based Recording?=
==HTML based recording:==
HTML based recording is context sensitive.  In this mode the LoadRunner engine captures the context of the HTML interaction and attempts to automatically correlate with the last page received to reduce the amount of customized programming required in the script.
==URL based recording:==
Expresses the interaction as a sequence of URL calls.  URL based scripts need to incorporate explicit logic to maintain state where required by the application - examples of this would be embedded page serial numbers or other form data expected by the application at the next (POST) operation.
==Discussion==
See http://www.allinterview.com/showanswers/28156.html
[[Category:LoadRunner]]

Latest revision as of 13:23, 15 July 2008

LoadRunner FAQ

Also see Load Testing reference...


Transaction Functions

See manual section 'VuGen Function Reference > Utility Functions: C Language (LR) > Transaction Transaction Functions'.

Wasting Time

In the following segment, lr_start_timer and lr_end_timer are used to calculate the time spent on checks. This is then subtracted from the time spent on transaction "sampleTrans" with lr_wasted_time.

   double time_elapsed, duration, waste; 

   merc_timer_handle_t timer; 

   lr_start_transaction("sampleTrans"); 

   web_url("index.htm", 
           "URL=http://localhost/index.htm", 
           "TargetFrame=", 
           "Resource=0", 
           "RecContentType=text/html", 
           "Referer=", 
           "Snapshot=t1.inf", 
           "Mode=HTML", 
           LAST); 

   timer = lr_start_timer(); 

   // Do some checks the duration of which is not to be included in the transaction.

   web_image_check("ImgCheck1", 
           "src=index_files/image002.jpg", 
           LAST); 

   web_image_check("ImgCheck2", 
           "src=index_files/planets.gif", 
           LAST); 

   // How long did the tests take in seconds. 

   time_elapsed = lr_end_timer(timer); 

   // Convert to millisecond.s 

   waste = time_elapsed * 1000; 

   // Remove the time the checks took from the transaction.

   lr_wasted_time(waste); 

   lr_end_transaction("sampleTrans", LR_AUTO); 

Programmatically Controlling Logging

Use something like...

   int log_profile = LR_MSG_CLASS_EXTENDED_LOG
                        |
                     LR_MSG_CLASS_FULL_TRACE
                        |
                     LR_MSG_CLASS_RESULT_DATA
                        |
                     LR_MSG_CLASS_PARAMETERS;

   ...

   lr_set_debug_message(log_profile, LR_SWITCH_ON); 

   ... Code you want extended logging for ...

   lr_set_debug_message(log_profile, LR_SWITCH_OFF); 

   ...

Capturing a Downloaded File

  • Set up a parameter to capure the entire page returned.
  • Determine its length.
  • Create a function to write this buffer to a file.

e.g.

//---------------------------------------------------------------------------------

int WriteDataToFile(char *szFileName, const char *szBuf, int len)
{
    int hFile;
    
    hFile = fopen(szFileName,"wb");

    if (hFile == NULL)
    {
        lr_error_message("Could't create or open the file: %s", szFileName);
        return LR_FAIL;
    }

    fwrite(szBuf, len, 1, hFile);
    fclose(hFile);
 
    return LR_PASS;
}

//---------------------------------------------------------------------------------

Action()
{
    char *szBuf;
    unsigned long nLength;
 
    // Function web_set_max_html_param_len sets maximum length of any HTML string,
    // that can be retrieved and saved as a parameter
    // So, make sure new value is greater than a size of string (in our case - file) to be captured
    web_set_max_html_param_len("100000");


    web_reg_save_param("prmLogoImage", "LB=\r\n\r\n", "RB=", LAST);


    web_url("logo.gif",
        "URL=http://www.google.com/intl/en_ALL/images/logo.gif",
        "Resource=1",
        "RecContentType=image/gif",
        "Snapshot=t1.inf",
        LAST);
 
    lr_eval_string_ext ("{prmLogoImage}", strlen("{prmLogoImage}") /* = 14*/, &szBuf, &nLength, 0, 0,-1);
    lr_output_message("Parmeter length = %d",nLength);
 
    WriteDataToFile("C:\\LogoImage.gif", szBuf, nLength);
 
    return 0;
}

//---------------------------------------------------------------------------------

See http://motevich.blogspot.com/2007/10/loadrunner-save-download-file-server.html

What is the Difference Between HTML and URL Based Recording?

HTML based recording:

HTML based recording is context sensitive. In this mode the LoadRunner engine captures the context of the HTML interaction and attempts to automatically correlate with the last page received to reduce the amount of customized programming required in the script.

URL based recording:

Expresses the interaction as a sequence of URL calls. URL based scripts need to incorporate explicit logic to maintain state where required by the application - examples of this would be embedded page serial numbers or other form data expected by the application at the next (POST) operation.

Discussion

See http://www.allinterview.com/showanswers/28156.html