Subscribe to SoftLogica
Newsletter to get 10% discount on newly
released products!
Parameter Value Dynamic Calculation
Parameter Value Dynamic Calculation
Testing of dynamic web sites and applications often requires the usage of dynamic values of request parameters.
If you don't change the recorded user profiles, WAPT Pro simply repeats all requests that
you made during recording, so all virtual users of the same profile send identical requests to the server.
However, you can add more reality to your tests by using parameter values generated dynamically at run-time.
WAPT Pro can simulate this with the help of various functions.
The program provides you with a number of functions for dynamic calculation of request parameters
and URL paths at run-time.
Functions can be divided into several groups:
random values (numeric or alphanumeric),
values from list (random or ordered),
values from actual server response (hidden form values and others),
and other functions.
The results of several functions can be also concatenated to form more
complicated values. WAPT Pro can also upload files to web server using the POST method
with multipart content.
There are two methods to use functions in WAPT Pro:
Request parameter value can be calculated using the combination of functions directly, or
You can define a variable (using functions or other variables) and set a request parameter to use the value.
Note that functions like Parameter from URL or Hidden
which obtain values from the actual server response
are calculated using the following as an input:
HTML code of the PREVIOUS page when the function is used for calculation of request PARAMETER value, or
HTML code of the CURRENT page when the function is used for defining a VARIABLE.
How to define a formula for calculation of parameter value
The list of request parameters is displayed in request properties (URL Parameters or
POST Parameters tab).
To define a parameter, you can use functions that parse actual HTML code of response at run-time.
Add..: Opens the Edit Parameter dialog where you can
create a new parameter and select a function for its calculation.
Remove: Removes selected parameter from the list.
Edit..: Opens the Edit Parameter dialog
where you can change parameter name and a function for its calculation.
Name: Here you can change parameter name. Type: You can select either "Formula", or "File".
Formula: Select this option if you wish to define a formula for calculation of parameter value.
File: Select this option if you need to upload some file (for example, an image file) to the tested server.
For details, see the description of $File function.
The following is related to the option Formula.
Formula: Here you can view a defined formula for calculation of parameter.
This field is accessible only for viewing. Functions: The list of functions for calculation of the current parameter is displayed in this field.
You can define several functions for the same parameter.
Results of those functions will be concatenated to form more complicated values.
Add..: Opens the Edit Function dialog where you can select a function
for calculation of parameter value.
Remove: Removes selected function from the list. (That function will be deleted only from the list
of functions for calculation of the current parameter.)
Edit..: Opens the Edit Function dialog
where you can edit the selected function or choose another function.
Move Up: Moves selected function one step up in the list (if you defined several functions for the same parameter).
Move Down: Moves selected function one step down in the list.
Below is the detailed description of functions which
can be used to imitate users' actions on a web page.
Static text
Returns a specified string. A parameter defined as "static text" is always the same and it does not depend on
requests. During the recording process, parameters get their initial values. After that you can change initial values
on any other values.
Example:
Variable - $Var
Returns the value of specified variable.
Variables will help you handle different user-dependent parameters like
session IDs or view states. Variables can be defined using any function and redefined later if necessary.
Note that functions which obtain values from the actual server response (hidden form values and others) use the
HTML code of the CURRENT page as an input when they are used for defining a variable.
Syntax: $Var({name})
Example:
Type the name of variable in the Name field. While you are typing,
you will see a prompt
with the list of existing variables if WAPT Pro finds the similar name in that list.
You can select the necessary variable there.
Or you can click the Select... button and you will see the list of existing
variables. The list includes variables created on one of the previous pages.
WAPT Pro has also a built-in variable
Session_number. It is the number of session of current profile beginning from 0.
When you add the $Var function for some request inside a loop
(Loop operator),
you will see one more variable in the list - the number of loop iteration. If, for example, you name a loop as
Main Loop, variable's name will be Main Loop_iteration. It also starts from 0.
Select a desired variable in the list and click OK.
Ordered list - $LOrder
Returns the 1-st string from a specified list for the 1-st user/session of current profile, the 2-nd
string - for the 2-nd user/session of current profile and so on. When
you add this function for some request inside a loop (Loop operator),
you will see three available modes: users, sessions and loop iterations. If you choose the loop iteration
mode, this function will return
the 1-st string from a specified list for the 1-st iteration of the loop, the 2-nd
string - for the 2-nd iteration and so on.
Choose a desired mode in the combo-box (Different values for different
users/sessions/loop_name iterations). Then
specify the list of strings: type one string
per line in the text field. Or you can load strings from a file: check the Load strings from a file
option and specify the name of a file containing the list.
The list is cycled so that
if the number of users/sessions/loop iterations is more than the list length, then the 1-st string
will be used after the last one.
For example, this function can be used to provide each virtual user with the individual user name and password.
Syntax: $LOrder(1|2,{file_name}|value1[,{value2},…])
for users and sessions
Here 1 stands for users and 2 - for sessions.
$LOrder(0,Loop_name,{file_name}|value1[,{value2},…])
for loop iterations
If you add this function for requests from embedded loops, use different loop names.
Example:
$LOrder(1,John,Mike,Bob)
It results in sending the following HTTP requests:
First virtual user: POST /login.do username=John&...
Second virtual user: POST /login.do username=Mike&...
Third virtual user: POST /login.do username=Bob&...
Random from list - $LRand
Returns a random string from a specified list.
Specify the list of strings: type one string per line in the text field. Or you can load strings from a file: check the
Load strings from a file option and specify the name of a file containing the list.
Numeric random - $NRand
Returns the concatenation of prefix string and evenly distributed random
number in the specified range.
Syntax: $NRand({prefix},{from},{to})
In other words, it returns a random integer located in the [from,to] range
preceded by a {prefix}
(if one specified). An integer number will be greater than or equal to the value specified in the "From"
field and less than or equal to the value specified in the "To" field.
Example:
$NRand(ID,1,20)
Below are sample HTTP requests that could be sent to the server:
Alphanumeric random - $ARand
Returns a random alphanumeric string with the length from a specified
range.
Syntax: $ARand({from},{to})
In other words, this function returns a random alphanumeric string with the length
located in the [from,to] range
(the length will be greater than or equal to the value specified in the "From"
field and less than or equal to the value specified in the "To" field.)
User number - $UserID
Returns the concatenation of 3 parameters: a prefix string, the number of virtual user of the current profile
(starts from 0) and postfix string.
For example, this function can be used to provide each virtual user with the individual user name and password.
Syntax: $UserID({prefix},{postfix})
Example:
$UserID(name,)
It results in sending the following HTTP requests:
First virtual user: POST /login.do
username=name0&...
Second virtual user: POST /login.do username=name1&...
Third virtual user: POST /login.do username=name2&...
Sequence - $Seq
Returns the sequence of strings that are
the concatenation of the prefix string and an integer number with some leading zeros (leading zeros appear if the length
of the integer number is less than the value specified in the "Width" field).
The integer number is calculated according to formula:
Start + RN + Shift*UN,
where RN is the number of current request execution within the whole test, and UN is the number of current user.
Syntax: $Seq({prefix},{start},{shift},{width})
Example:
$Seq(thread,2,5,2)
The 1-st virtual user will send these HTTP requests to the server:
JavaScript - $JavaScript WAPT Pro allows the execution of JavaScript within virtual user profiles.
You can use JavaScript functions when you define request parameters or variables.
Note that if you use JavaScript function, you should first define it in one of files of JavaScript library
(JavaScript tab of program settings).
If you wish to define some variable or request parameter as a result of JavaScript function, you should
select "JavaScript" as function type and specify function name and function parameters.
Example:
Suppose you define a variable which is calculated as a result of function "summ" - the sum of 2
variables.
Type: Select "JavaScript" as function type.
Function name: Type the name of some function
defined in WAPT Pro JavaScript library.
Function parameters: Here you can specify function parameters.
Each parameter can be calculated as a result of some function.
Click the Add... button and you will see the same Edit Function dialog
where you can define a new parameter and a function for its calculation.
JavaScript Library:
Click this button and you will see the list of files included in the library.
If you select some file in the list, its JavaScript code will be displayed in a new window.
You can add new files to the library. Click JavaScript Library -> Add JavaScript File... button
and you will switch to the
JavaScript tab of program settings
where you can add new files.
When you finish editing the function, click OK to save changes. In the Edit Variable
(or Edit Parameter) dialog you will see the formula for calculation of
variable (parameter).
So in this example, the variable SessionID will be calculated as:
SessionID=$ARand(1,20)+$NRand(ID,1,20)
Search parameter - $Search
This function searches the HTML code of the CURRENT page for dynamic values located between 2 specified strings.
The $Search function is very useful when you know that some dynamic value is always
surrounded by the certain strings on the left
and on the right. You can specify those strings and organize the search.
Index defines which occurrence of the current parameter to use in case WAPT Pro
finds several dynamic values in the HTML code between the specified boundaries.
For example, you specified "ItemID=" as the left boundary and "&" as the right boundary and
WAPT Pro found the following strings in the HTML code:
ItemID=11111111111& and
ItemID=222222222&. So 2 dynamic values
11111111111 and 222222222 were found.
If the index is equal to 1, the program will use the 1-st occurrence;
if the index is equal to 2, then - the 2-nd occurrence and so on.
0 stands for random occurrence.
Example:
Suppose the HTML code on some web page contains the following text:
<A HREF="/scdp/page;jsessionid=u8kzzgzsr2">Preparing a test scenario</A>
You can create a variable JSesID which is calculated using
the $Search function that searches for dynamic values between the following strings: /scdp/page;jsessionid= (left boundary) and ">
(right boundary).
After that you will be able to change the recorded URL path into this one:
and you will obtain the actual URL with a new value of jsessionid.
In this example, the variable JSesID will get the value
u8kzzgzsr2.
You can set the URL in the subsequent request to use the value of JSesID variable.
Session variable is a part of URL path
The functions URL from link and URL from Form cannot be used
to define the URL path directly. You should create a variable
based on one of these functions and then use that variable in the subsequent request to define the URL.
URL from link - $HRef
This function searches for a link with a specified text in the HTML code of the CURRENT page and returns the
URL path from that link.
In other words, it searches for a string like <A HREF=URL path>Text</A> containing the specified
Text and returns the URL.
Note: If the link uses a relative path, WAPT Pro automatically transforms it
to an absolute path.
Syntax: VarName=$HRef({text},{index})
Index defines which occurrence of URL to use in case
WAPT Pro finds several links with such text.
For example, if the index is equal to 1, the program will use the 1-st occurrence;
if the index is equal to 2, then - the 2-nd occurrence and so on.
0 stands for random occurrence.
Example:
Suppose the HTML code of server response contains the following link:
<A HREF="/scdp/page;jsessionid=u8kzzgzsr2">Preparing a
test scenario</A>
If you create a variable JSesID equal to $href(Preparing a test scenario,1),
you will obtain the actual URL with a new value of
jsessionid.
In this example, the variable JSesID will get the following value:
/scdp/page;jsessionid=u8kzzgzsr2
and you can set the URL in the subsequent request to use the value of JSesID variable.
URL from Form - $Action
Searches the HTML code of the CURRENT page for a form and returns the value of its action attribute.
Note: If the link uses a relative path, WAPT Pro
automatically transforms it to an absolute path.
Syntax: VarName=$Action({index})
Index defines which occurrence of the form to use in case of multiple forms on the page.
For example, if the index is equal to 1, the program will use the 1-st occurrence;
if the index is equal to 2, then - the 2-nd occurrence and so on.
0 stands for random occurrence.
Example:
Suppose the HTML code of the current page contains the following form:
If you create a variable URL_session equal to $Action(1),
you will obtain the actual URL from that form with an actual value of
SessionID. In this example, the URL_session variable will get the following value:
and you can set the URL path in the subsequent request to use the value of URL_session variable.
Session variable is a request parameter
Functions $UrlParam and $Hidden can be used directly or using variables. Examples below
show the direct usage of these functions.
Parameter from URL - $UrlParam
Searches the HTML code of the CURRENT page for a request that contains the specified parameter name and returns
parameter value.
Syntax: ParamName=$UrlParam({name},{index})
Index defines which occurrence of the current parameter to use in case
WAPT Pro finds that parameter several times.
For example, if the index is equal to 1, the program will use the 1-st occurrence;
if the index is equal to 2, then - the 2-nd occurrence and so on.
0 stands for random occurrence.
Example 1:
Suppose the HTML code of response contains such link:
The usage of Myparam=$UrlParam(SessionID,0) in the next request
will result in the actual value of Myparam=FCHHAB02DF.
This function is very important when you need to use parameter values generated
by the server on-the-fly.
Example 2:
Suppose you need to automate a simple scenario of navigating through a certain
site using respective HTTP requests:
1. User registration:
http://myserver/register?User=Alex&Pass=qwerty
(a POST request)
2. After registration, the user is redirected to the
main category which displays links to all resources of the site.
At this stage, the SessionID
session variable is generated. The user selects the Main category
by clicking the respective link:
During recording, WAPT Pro records this sequence of HTTP requests, but the
static value of SessionID would not be used to play this sequence back
during test run. After sending the second request an error will occur. The
reason is that we try to use the old value of SessionID.
You should define the SessionID parameter as $UrlParam(SessionID,0)
and thus solve the problems related to SessionID.
Hidden - $Hidden
Searches the HTML code of the CURRENT page for a form containing the specified name of hidden parameter and
returns parameter value.
Syntax: ParamName=$Hidden({name},{index})
Index defines which occurrence of the current parameter to use in case
WAPT Pro finds that parameter several times
(it is the case of multiple forms with the same parameter).
For example, if the index is equal to 1, the program will use the 1-st occurrence;
if the index is equal to 2, then - the 2-nd occurrence and so on.
0 stands for random occurrence.
This function searches for an element containing <....
name="{name}" value="{value}"> using the specified {name}.
The result of the search will be the found {value}. Such syntax is typically used to define input
elements in HTML forms. The advantage of this function is that it allows
working with hidden form elements and dynamically generated values
(for example, session variables).
Example:
Suppose the HTML code of the current page contains a form with the set of
hidden elements:
To obtain the UserSession value presented as a hidden input, you should define the
UserSession variable as $Hidden(UserSession,0).
File - $File
Returns a file with the specified mime type and name. File content and other request parameters will be sent as the
POST data with the "multipart/form-data" content type.
Syntax: ParamName=$File({mimetype},{name})
Example:
Suppose you need to upload the JPEG image image001.jpg located
in the C:\Users\Public\Pictures\ folder to the tested server. You
should define the following function: