Functions:-
1,
In the following
example, lr_error_message sends a message to the LoadRunner output window or
Application Management agent log file if the login fails. lr_abort is
then invoked to abort the script.
2.
The following
example uses abs to convert the integers 23 and -11 to their absolute
values:
3
In the following
example, the web_add_cookie function adds a cookie with the name
"client_id" to the list of cookies available to the script.
web_add_cookie
("client_id=China127B; path=/; expires=Wednesday, 09–Nov–2001 23:12:40
GMT; domain=www.cnn.com");
4
The following example gets the time as a time_t
structure and converts it to a tm structure, gmt, in
Coordinated Universal Time. asctime then takes gmt and converts
it to a string.
5
The following
example converts the initial portion of the string, s, to a float.
double atof (const char *string); /* Explicit declaration */
vuser_init() {
float x;
char *s = "7.2339 by these hilts or I am a villain else";
x = atof(s);
/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
return 0;
}
vuser_init() {
float x;
char *s = "7.2339 by these hilts or I am a villain else";
x = atof(s);
/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
return 0;
}
6
The following
example converts the initial portion of the string, s, to an integer.
7
Prints time information to a
structure.
|
|
8.
In the following
example, lr_error_message sends a message to the LoadRunner output
window or Application Management agent log file if login fails:
int status = web_url("Login",
"URL=https://secure.computing.com//login.asp?user={username}&session={ssid}",
"RecContentType=text/html", LAST);
if (status == LR_FAIL) {
lr_error_message("Error: %s", "Unable to login to secure computing");
return -1;
}
"URL=https://secure.computing.com//login.asp?user={username}&session={ssid}",
"RecContentType=text/html", LAST);
if (status == LR_FAIL) {
lr_error_message("Error: %s", "Unable to login to secure computing");
return -1;
}
9
The lr_eval_string function returns the
input string after evaluating any embedded parameters. If string argument
contains only a parameter, the function returns the current value of the
parameter.
10.
In the following
example, lr.eval_int returns the value of parameter ID_num.
Example 2 -
Parameterization
In the following example, lr.eval_int substitutes
the parameter string STID with appropriate values for each iteration.
11.
lr.EXIT_VUSER
|
||
lr.EXIT_ACTION_
AND_CONTINUE |
||
lr.EXIT_MAIN_
ITERATION_ AND_CONTINUE |
||
lr.EXIT_ITERATION_
AND_CONTINUE |
||
lr.EXIT_VUSER_
AFTER_ITERATION |
||
lr.EXIT_VUSER_
AFTER_ACTION |
Run until the end of the current action and then exit.
|
12.
13
Example: feof
The following example, for Windows platforms, opens a file and reads it
into a buffer until feof returns true, indicating the end of the file.
To run the example, copy the file readme.txt from the
installation's dat directory to the c drive, or copy another file and
change the value of filename.
14.
The following
example, for Windows platforms, opens a file and reads it into a buffer. ferror
checks for errors on the read file stream.
15
The following
example, for Windows platforms, opens a file using fopen, reads it into
a buffer, and then closes it.
To run the example, copy the file readme.txt from the
installation's dat directory to the c drive, or copy another file and
change the value of filename.
Output:
Action.c(19): 1000 bytes read
Action.c(19): 1000 bytes read
...
Action.c(19): 1000 bytes read
Action.c(20): 977 read
Action.c(34): Total number of bytes read = 69977
Action.c(19): 1000 bytes read
Action.c(19): 1000 bytes read
...
Action.c(19): 1000 bytes read
Action.c(20): 977 read
Action.c(34): Total number of bytes read = 69977
16.
The following
example opens a log file and writes the id number and group name of the Virtual
User to it using fprintf.
17.
The following
example uses free to de-allocate a buffer of length 1024.
18.
The following
example, for Windows platforms, opens a file and reads it into a buffer. If
file errors occur during the process, goto is used to escape the
enclosing loop to code which prints an error message and exits the function.
int count, total =
0;
19.
In the following
example, lr_log_message sends a message to the log file if the
connection to the server fails.
20.
In the following
example, lr_message sends a message if the connection to the server
fails.
21,
In the following
example, ID is a parameter defined in the Parameter list. The lr_next_row
function advances to the next row in the ID.dat file.
22.
In this example,
an Iteration Number type parameter called "iteration" was defined in VuGen. The lr_output_message
function sends a message to the Load Runner Controller or the Application Mangement
Admin Center
indicating the current iteration number.
23.
In the following
example, the lr_rendezvous function sets the Meeting rendezvous point.
When all users that belong to the Meeting rendezvous arrive at the rendezvous
point, they perform do_transaction simultaneously.
24. In the following example, lr.save_data assigns a series of
values to the ID parameter. This parameter is then used in an
output message.
25
In the following
example, lr_load_dll
is used so that a standard Windows message box can be displayed during script
replay:
26.
In the following
example, lr_log_message sends a message to the log file if the
connection to the server fails.
char*
abort="aborting...";
...
if (init() < 0)
{
lr_log_message ("login failed: %s", abort);}
return(0);
}
In the next example, an Iteration Number type
parameter called "iteration" was defined
in VuGen. The lr_log_message function sends a message to the LoadRunner
Controller or Application
Management Admin
Center indicating the
current iteration number.
27.
In the following
example, lr_message sends a message if the connection to the server
fails.
char*
abort="aborting...";
...
if (init() < 0)
{
lr_message ("login failed: %s", abort);}
return(0);
}
28.
In this example,
an Iteration Number type parameter called "iteration" was defined in VuGen. The lr_output_message
function sends a message to the Load Runner Controller or the Application Mangement
Admin Center
indicating the current iteration number.
lr_output_message
( "We are on iteration #%s", lr_eval_string ( "{iteration}"
) );
29.
In the following
example, lr_save_datetime is used to retrieve tomorrow's date.
30.
In the following
example, lr_save_int assigns the string representation of the value of
variable num times 2 to parameter param1.
31.
In this example,
the lr_set_debug_message function enables the full trace option just
before a call to lrd_fetch, which the user needs to debug because it has been
giving unexpected results.
The second invocation of lr_set_debug_message resets the debug level
to what it was formerly, by turning off (LR_SWITCH_OFF) the Extended message
level.
32.
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.
In the following
segment, lr_think_time instructs the script to pause for 10 seconds
after accessing a link and submitting a form.
In the following
example, a user data point is defined that checks the CPU every second and
records the result.
30
The following
segment demonstrates the use of timers to collect wasted time, and the use of lr_wasted_time
to remove that wasted time from the transactions. The output log segments below
show that the effects are not reported in the Vuser log, but are reported in
the Analysis session.
31.
In the following
example, lr_whoami retrieves information about a Vuser and places it
into a message string. The message string contains Vuser login information that
is used to connect with a server.
32.RTE functions
TE_connect
|
Connects the terminal emulator to the specified host.
|
TE_find_text
|
|
TE_get_line_attribute
|
Returns information about text formatting.
|
TE_get_text_line
|
Reads text from a designated line on the screen.
|
In these examples,
web_save_param_length creates three new parameters, Param7_Length,
Param10_Length,and Param16_Length, and stores the length of each respective
source parameter as a hexidecimal number.
The following
examples are presented for web_reg_save_param.
- Example
1: Saving simple text strings
- Example
2: Saving a text by using binary boundaries
- Example
3: Saving a text specified with an offset and length
- Example
4: Boundaries containing special characters
Example 1:
Saving simple text strings
In this example, web_reg_save_param is used to save a value from the
response to a web_submit_form call. The value saved is used in a subsequent
web_submit_form call.
In the Mercury Tours sample program, the server response to the web_submit_form
call below contains the following radio button options:
<tr bgcolor=#66CCff><td align=center><input type = radio
name=outboundFlight value=230;378;11/20/2003 checked >Blue Sky Air
230<td align=center>8am<td align=center>$ 378
<tr bgcolor=#eeeeee><td align=center><input type = radio
name=outboundFlight value=231;337;11/20/2003>Blue Sky Air 231<td
align=center>1pm<td align=center>$ 337
To submit a reservation, the outboundFlight value is required. web_reg_save_param
is used to save the outboundFlight value.
Case of saving a single string
To reserve the default flight, save the "checked" value, and pass
it to web_submit_form. The html segment for the default value is:
Case requiring handling arrays
If you want to test the last option returned by the web_submit_form call,
save all the matches and then handle the array.
This example shows the use of web_reg_save_param with "ORD=ALL"
to get an array of parameters. The last item in the array is then used to
correlate a web_submit_form call.
This web_reg_save_param call applies to the following action function,
web_submit_form. Because of the "ORD=ALL" argument, it saves all the
values that have the given left and right boundaries to an array of parameters.
The SaveLen argument is used to restrict the length to 18 characters
because the default value is "230;378;11/20/2003 checked >". We
restrict the length so as not to capture the " checked ".
The next problem is to get the highest array element, identified with the
parameter outFlightVal_count. This parameter is automatically created by
the script recorder. You do not have to enter anything in the script.
Note that the brackets in the second argument to sprintf are not
indicating a script parameter to sprintf. They are string literals that
will be part of outFlightParam after the call.
Example 2:
Saving a text by using binary boundaries
The following example uses BIN type boundaries. The left boundary is
composed of 3F and DD. The right boundary is composed of CC
and b.
Example 3:
Saving a text specified with an offset and length
The following example specifies an offset and length. The boundaries for
the HTML string "Astra on TESTSERVER", are "Astra " (note
the space which follows the word) and "TestServer". This
should return "on" but since the offset is 1 (i.e. start at the
second character) and the length of data to save is 1, then the string saved to
TestParam is "n".
Example 4:
Boundaries containing special characters
The following example shows the use of escaping in the C language when the
boundaries contain special characters.
The following HTML segment contains new line characters (paragraph markers)
after each "<strong>" and quote marks around each class name.
We want to save "Georgiana Darcy" to parameter "UserName".
The segment containing the new line and quotes has to be included in the left
boundary because "Name:", which precedes the segment, is required for
the occurrence to be unique. The ORD attribute cannot be used in this case
because the length of the list preceding the relevant element varies.
In the following example, web_reg_find searches for the text string
"Welcome". If the string is not found, it fails and the script
execution stops.
-------
In the following
example, the web_find function searches for the name "John" in
the employees.html page.
web_find("Employee
Check",
"expect=notfound",
"matchcase=yes",
"onfailure=abort",
"report=failure",
"repeat=no",
"what=John",
LAST);
"expect=notfound",
"matchcase=yes",
"onfailure=abort",
"report=failure",
"repeat=no",
"what=John",
LAST);
Example 2
In the following example, the web_find function searches for the
text "Home" which is between "Go to" and "Page".
2 comments:
usable information, my side one small suggestion, if it possible create one full video and send the link.
Excellent info. Many thanks for sharing
Post a Comment