Apa itu Korelasi?
Korelasi, seperti namanya, adalah mekanisme untuk mendefinisikan hubungan antara dua variabel atau entitas. Sebuah Dictionary mendefinisikannya sebagai “hubungan statistik antara dua atau lebih variabel sedemikian rupa sehingga perubahan sistematis pada variabel lainnya menyertai perubahan sistematis dalam nilai satu variabel”.
Dalam tutorial ini, kita akan belajar tentang
- Mengapa kita membutuhkan Korelasi?
- Korelasi otomatis
- Korelasi manual
- Memahami fungsi Web_reg_save_param
Mengapa kita membutuhkan Korelasi?
Mari kita pahami hubungan bersama dengan skenario berikut.
Pertimbangkan Anda merekam skrip menggunakan LoadRunner.
Komunikasi Server-Klien
- Selama Record, klien mengirimkan permintaan ke server untuk memulai sesi
- Server menerima permintaan dan mengalokasikan sesi baru ID ABC
- Klien menyimpan ID sesi ABC dalam skrip.
- Klien memulai sesi dengan ID ABC dan mengirim permintaan ke server untuk mengizinkannya merekam
- Server mengenali ID ABC dan mengizinkan klien untuk merekam skrip
- Sekarang, mari kita pelajari komunikasi klien-server selama pemutaran ulang
- Selama Pemutaran Ulang, klien mengirimkan permintaan ke server untuk memulai sesi
- Server menerima permintaan dan mengalokasikan ID sesi baru XYZ
- Klien memulai sesi dengan sesi ID ABC yang direkam sebelumnya dan mengirim permintaan ke server untuk mengizinkannya merekam
- Server tidak dapat mengidentifikasi ID ABC karena ia mengharapkan ID XYZ yang telah dialokasikan dan sesi gagal.
Kami membutuhkan solusi, yang menangkap parse nilai dinamis yang dikirim pada saat run-time dan mengembalikan nilai ini kembali ke server. Berikut adalah tampilan komunikasi klien-server dengan solusi ini
- Selama Pemutaran Ulang, klien mengirimkan permintaan ke server untuk memulai sesi
- Sebuah Server menerima permintaan tersebut, dan mengalokasikan ID sesi baru ZZZ
- Klien mengurai id sesi baru ZZZ ini dari permintaan.
- Klien mengirimkan permintaan untuk memulai sesi dengan id ZZZ
- Server mengenali ID ZZZ dan mengizinkan klien memutar ulang skrip
Ini tidak lain adalah korelasi .
Klik di sini jika video tidak dapat diakses
Dalam kasus VUGen, korelasi adalah hubungan yang mengikat antara respons dan permintaan sebelumnya.
Ada berbagai situasi ketika permintaan didasarkan pada respons yang diterima sebelumnya dari server, seperti, ID Sesi, tanggal / waktu server yang diambil dari server. Nilai-nilai ini berbeda setiap kali Anda menjalankan aplikasi atau merekam skrip. Jelas, jika eksekusi skrip bergantung pada nilai yang dikembalikan oleh server, itu berarti Anda perlu menemukan mekanisme di mana Anda dapat "menangkap" respons server dan melampirkan ke permintaan yang diharapkan server. Ini biasanya disebut Korelasi di LoadRunner.
Dengan kata sederhana, solusi dengan menggunakan Korelasi adalah:
- Tangkap nilai keluaran dari sebuah langkah
- Gunakan nilai yang ditangkap di atas untuk dijadikan masukan bagi semua langkah selanjutnya
Korelasi diklasifikasikan menjadi 2 kategori di VUGen / LoadRunner:
- Korelasi otomatis
- Korelasi manual
Korelasi Otomatis
LoadRunner provides a mechanism to easily perform correlation in automatic fashion.
VUGen will require you to run a recorded script at least two times so it can internally compare the varying values in the server response.
Automatic correlation can be classified into 3 categories:
- Auto-Detect Correlation
- Rule-Based Correlation
- Correlating All Statements
Rule Name | When to Use |
Auto-detect Correlation | Detect and correlate dynamic data for application servers supported by HP LoadRunner |
Rule-Based | Used when working with a non-supported application server for which the context is known. |
Correlate All | Helps correlate all dynamic data in blind fashion. |
Though Automatic Correlation seems simpler, it can be error-prone and works in not more than 5% of the cases. It is always advisable to use manual correlation.
To configure automatic correlation at the time of recording, perform below configuration in Record Time Setting after a script has been recorded.
Click on Record =>Recording Options (or click Ctrl +F7),
>
Below window will open:
Click on Correlation =>Configuration - below window will open.
Here, you need to mark as checked against all applications (ASPNET) etc., which are used in your subject application. On the right-hand side, you can see the rules which will detect possible candidates for correlation e.g. _VIEWSTATE. You can also add more applications or custom rules by clicking on New Rule button.
You can also click on RULES, you will see as below:
In order for Automatic Correlation to work, you need to ensure Rules Scan is marked as checked. If you click on automatically correlate values found, VUGen will not prompt you with the choice once a correlation candidate is found, instead, it will just correlate them.
We will understand API used for correlation later. However, it is advisable to use HTML comparison instead of text comparison.
Once you’ve selected any rules, click on OK button to close the windows.
Click on from menu and VUGen will regenerate script (without having to record) with new configurations. VUGen will automatically add a required piece of code to handle correlation. We will look at the sample in more detail in Manual Correlation.
Please note, if you perform correlation manually or use automatic correlation, the piece of code will contain exactly same syntax and function.
Steps to auto-correlate a script:
- Record a script
- Replay script
- Identify the values to be correlated
- Select the values and click the auto-correlate button
- Verify the script by running again. A successful run means successful correlation.
Tip:
- Correlation helps run your script with different values
- Correlation also reduces the size of your script
Manual Correlation
Manual correlation is about writing code directly into your script to cater for ever-changing values. We can split it into below steps:
- Determine the value to capture
- Find the right and left text boundaries of the value to capture (WEB)
- Find which occurrence of the text boundaries should be used
- Add a web_reg_save_param function to the script, above the piece of code which requests the page with the value to capture
- Add a parameter name, left boundary, the right boundary, and occurrence to the function
- Parameterize the dynamic value in the script every time it occurs
- Verify correct execution
web_reg_save_param (" OracleAppJSESSIONID3","LB/IC=JSESSIONID=","RB/IC=;","Ord=l","Search=headers","RelFrameId=l",LAST);web_reg_save_param("Siebel_Analytic_ViewState2","LB/IC=ViewState\" value=\"","RB/IC=\"","Ord=1","Search=Body","RelFrameId=l",LAST);
Manual correlation can be done by VUser Comparison. Steps in VUser Comparison method of Correlation can be split as below:
- Identify Dynamic values that need to be correlated
- Find Servers response containing the Dynamic value
- Capture the Dynamic value in a parameter
- Replace every occurrence of the Dynamic value with the parameter
- Verify Changes
Understanding Web_reg_save_param function
VUGen provides multiple functions or APIs to correlate candidates, including:
- web_reg_save_param
- web_reg_save_param_ex
- web_reg_save_param_regexp
- web_reg_save_param_xpath
While a brief introduction is being provided here, for a detailed understanding of functions and their parameters, open VUGen, write function (or use Steps Toolbox), move a cursor on the function and click F1 - get yourself acquainted with VUGen help and make a habit. You will have to deal with it a lot when working in the industry.
Here we go with the function details:
web_reg_save_param(Parameter Name , Left Boundary , Right Boundary )
List of Attributes
Convert: The possible values are:
HTML_TO_URL: convert HTML-encoded data to a URL-encoded data format
HTML_TO_TEXT: convert HTML-encoded data to plain text format; this attribute is optional.
Ignore Redirections: If "Ignore Redirections=Yes" is specified and the server response is redirection information (HTTP status code 300-303, 307), the response is not searched. Instead, after receiving a redirection response, the GET request is sent to the redirected location, and the search is performed on the response from that location.
This attribute is optional. The default is "Ignore Redirections=No".
LB: The left boundary of the parameter or the dynamic data. If you do not specify an LB value, it uses all of the characters from the beginning of the data as a boundary. Boundary parameters are case-sensitive. To further customize the search text, use one or more text flags. This attribute is required. See the Boundary Arguments section.
NOTFOUND: The handling option when a boundary is not found, and an empty string is generated.
"Not found=error", the default value, causes an error to be raised when a boundary is not found.
"Not found=warning" ("Not found=empty" in earlier versions), does not issue an error. If the boundary is not found, it sets the parameter count to 0 and continues executing the script. The "warning" option is ideal if you want to see if the string was found, but you do not want the script to fail.
Note: If Continue on Error is enabled for the script, then even when NOTFOUND is set to "error", the script continues when the boundary is not found, but an error message is written to the extended log file.
This attribute is optional as well.
ORD: Indicates the ordinal position or instance of the match. The default instance is 1. If you specify "All," it saves the parameter values in an array. This attribute is optional.
Note: The use of Instance instead of ORD is supported for backward compatibility, but deprecated.
RB: The right boundary of the parameter or the dynamic data. If you do not specify an RB value, it uses all of the characters until the end of the data as a boundary. Boundary parameters are case-sensitive. To further customize the search text, use one or more text flags. This attribute is required. See the Boundary Arguments section.
RelFrameID: The hierarchy level of the HTML page relative to the requested URL. The possible values are ALL or a number. Click RelFrameID Attribute for a detailed description. This attribute is optional.
Note: RelFrameID is not supported in GUI level scripts.
SaveLen : Panjang sub-string dari nilai yang ditemukan, dari offset yang ditentukan, untuk disimpan ke parameter. Atribut ini opsional. Standarnya -1, menunjukkan untuk menyimpan ke akhir string.
SaveOffset : Offset dari sub-string dari nilai yang ditemukan, untuk disimpan ke parameter. Nilai offset tidak boleh negatif. Standarnya adalah 0. Atribut ini opsional.
Pencarian: Ruang lingkup pencarian-tempat untuk mencari data yang dibatasi. Nilai yang mungkin adalah Headers (Search only the headers), Body (search only body data, not headers), No resource (search only the HTML body, mengecualikan semua header dan resource), atau ALL (search body, headers, dan resource) . Nilai defaultnya adalah ALL. Atribut ini opsional tetapi umumnya lebih disukai.