30
Scripting Enhancements

Day2 j meter_training_script_enhancements

Embed Size (px)

Citation preview

Page 1: Day2 j meter_training_script_enhancements

Scripting Enhancements

Page 2: Day2 j meter_training_script_enhancements

Script Enhancements ◦ Recording Scripts

◦ Parameterization

User Parameters

Function Helper Dialog

◦ Correlation

Regular Expression Extractor

◦ Assertions

◦ Listeners

◦ Timers

Confidential 2

Page 3: Day2 j meter_training_script_enhancements

Confidential 3

The Http proxy server is selected

for Configuring the recording

option.

Right Click WorkBench Add Non-Test Elements HTTP Proxy Server

We are using the proxy server to record ,as the Browser is routed to JMeter port to record the

HTTP browser sessions .

Page 4: Day2 j meter_training_script_enhancements

Confidential 4

Port number is

entered

Add patterns to be

included while recording.

E.g. Add “.*\.html”

Select Target Controller settings

Select type of Grouping

Add patterns to be excluded while

recording. E.g. Add “.*\.gif” Start recording

Page 5: Day2 j meter_training_script_enhancements

Enter port number in the place provided as 8090.

Select the target controller – The requests will be targeted or recorded at the option

selected.

Select the grouping type – This option groups the requests according to the type selected.

Enter patterns to be included.

Enter patterns to be included.

Open Browser.

Click Tools -> Internet options -> Connections -> LAN settings.

Change IP of proxy to “localhost” and also the port number as 8090.

Click Start.

Traverse through the pages needed.

Close browser.

Click Stop in JMeter.

Confidential 5

Page 6: Day2 j meter_training_script_enhancements

Confidential 6

Page 7: Day2 j meter_training_script_enhancements

User Parameters

◦ Right Click the Request Add Pre Processors User Parameters

Confidential 7

Page 8: Day2 j meter_training_script_enhancements

User Parameters

◦ The variable is specified by clicking the Add Variable button in the bottom of the panel

and filling in the Variable name in the 'Name:' column.

◦ To add a new value to the series, click the 'Add User' button and fill in the desired value

in the newly added column.

Confidential 8

Similar to Unique each iteration in Load

Runner tool

Page 9: Day2 j meter_training_script_enhancements

Confidential 9

Values can be accessed

in any test component in

the same thread group,

using the syntax:

${SearchString}.

Make the number of

users in Thread

Properties to the number

of users assigned in the

User Parameter.

Page 10: Day2 j meter_training_script_enhancements

Using Function

◦ Create a Txt File with the parameters in any location .

◦ Click Options Function Helper Dialog in JMeter.

◦ Choose the function __StringFromFile.

Confidential 10

Page 11: Day2 j meter_training_script_enhancements

◦ Provide Full path of the location of file.

◦ Provide a Name to the variable

◦ Provide start File sequence Number as needed.

◦ Click generate.

◦ Copy and paste the value generated to the value of the variable which has to be

parameterized in the request.

◦ The data will be taken from the file while execution. This function can be used to provide

only one column of data.

◦ To use multiple columns, __CSVRead function can be used.

Confidential 11

Page 12: Day2 j meter_training_script_enhancements

Confidential

1

2

Page 13: Day2 j meter_training_script_enhancements

Confidential 13

The generated value is

pasted here (exclude

variable name and

sequence number)

Page 14: Day2 j meter_training_script_enhancements

Using Function

◦ Create a CSV File with the parameters in any location .

◦ Click Options Function Helper Dialog in JMeter.

◦ Choose the function __CSVRead.

Confidential 14

Page 15: Day2 j meter_training_script_enhancements

Confidential 15

Page 16: Day2 j meter_training_script_enhancements

Confidential 16

The generated

value is pasted here

with column 0

The generated

value is pasted here

with column 1

Page 17: Day2 j meter_training_script_enhancements

Confidential 17

Page 18: Day2 j meter_training_script_enhancements

Confidential 18

Substituting the correlated values

Page 19: Day2 j meter_training_script_enhancements

Confidential 19

Page 20: Day2 j meter_training_script_enhancements

Using Regular Expression Extractor (Regex)

◦ Allows the user to extract values from a server response using a Perl-type regular

expression

◦ Extracts the requested values, generate the template string, and store the result into the

given variable name.

◦ Equivalent to Correlation.

Confidential

2

0

Right Click the Request Add Post Processors Regular Expression Extractor

Page 21: Day2 j meter_training_script_enhancements

The Regular Expression Extractor needs to be added in the previous request to capture the

dynamically changing data in the current request.

Confidential 21

In the above figure, the SessionId has got recorded in the ‘LoginPageToPlannerPage’ request. To

capture the SessionId, the Regular Expression Extractor named ‘SessionId’ is included in the

previous request ‘HomePageToLoginPage’.

Page 22: Day2 j meter_training_script_enhancements

Reference Name: The name of the variable where the dynamically parameterized value get stored.

Regular Expression: This must contain at least one set of parentheses "()" to capture a portion of the string. And left and right boundary of the parameter to be correlated can also be given. In the given example:

(&BV_SessionID=) Left Boundary of the SessionId within parentheses.

(.*) .* within parentheses signifies that any value between the left and right boundary has to be captured. This .* is one of the patterns of regular expression. Other patterns include \W,\d etc.

(&BV_EngineID=) Right Boundary of the SessionId within parentheses.

Template: The template is used to create a string from the matches found. It can be $0$, $1$, $2$.

From the given example, the parentheses break the expression into three groups: Left Boundary, SessionId Value and Right Boundary. The value $2$ in the Template field signifies that the value in the second group i.e. the SessionId value needs to be captured and assigned to the given variable.

Match No: Indicates which match to use. The regular expression may match multiple times.

Default Value: If no matches are found, then the value given in this field will be substituted. Hence, this value needs to be empty.

Confidential 22

Page 23: Day2 j meter_training_script_enhancements

Confidential 23

• Replace the value of variable which is to be Dynamically Parameterized as ${SessionId}

Page 24: Day2 j meter_training_script_enhancements

Assertions allow you to assert facts about responses received from the server being tested.

You can assert that the response to a query will contain some particular text and check if

the correct response is received from the server.

Confidential 24

Right Click the Request Add Assertions Response Assertion

Page 25: Day2 j meter_training_script_enhancements

Confidential 25

Name for the Assertion

Text to check in the

web page

Page 26: Day2 j meter_training_script_enhancements

To view Assertion Results , add Assertion Listener to the thread group while running the script.

Confidential 26

Page 27: Day2 j meter_training_script_enhancements

Confidential 27

Asserted text found in Page Asserted text not found in page

Page 28: Day2 j meter_training_script_enhancements

JMeter thread sends requests without pausing between each request.

Available Timers can be used to provide delay between the requests so that the server is not

loaded with requests in a short time.

Confidential 28

Page 29: Day2 j meter_training_script_enhancements

Confidential 29

In the above figure, Constant Timers are added between the requests. The delay is given as 3000 milli seconds

i.e. 3 seconds.

Page 30: Day2 j meter_training_script_enhancements

Confidential 30