Korrelation i LoadRunner med web_reg_save_param Exempel
โก Smart sammanfattning
Correlation in LoadRunner captures a dynamic server value, such as a session ID, and feeds it back into later requests so a recorded VuGen script replays successfully instead of failing on stale data.
Vad รคr korrelation?
Correlation, as the name suggests, is a mechanism of defining a relationship between two variables or entities. A dictionary defines it as โstatistical relation between two or more variables such that systematic changes in the other accompany systematic changes in the value of one variableโ.
Varumรคrkesanmรคrkning: this tool shipped as HP and then Micro Focus LoadRunneroch รคr nu OpenText Professionell prestandateknik. Every correlation function below is unchanged, and the vendor spells the script generator VuGen.
Varfรถr behรถver vi korrelation?
Letโs understand correlation with the following scenario.
Consider you are recording a script using LoadRunner.
Client-Server Communication during recording runs as follows, and the diagram summarises it:
- During Record, the client sends a request to the server to start a session
- En server tar emot begรคran och tilldelar ett nytt sessions-ID ABC
- Klienten lagrar sessions-id ABC i skriptet.
- Client starts the session with ID ABC and sends a request to a server to allow it to record
- Servern kรคnner igen ID ABC och lรฅter klienten spela in skriptet
Now, letโs study the client-server communication during replay, shown after these steps:
- Under Replay skickar en klient en begรคran till servern om att starta en session
- En server tar emot begรคran och tilldelar ett nytt sessions-ID XYZ
- A Client starts the session with the previously recorded session ID ABC and sends a request to the server to allow it to record
- En server kan inte identifiera ID ABC eftersom den fรถrvรคntade sig ID XYZ som den har allokerat och sessionen misslyckas.
We need a solution which can capture and parse the dynamic value sent at run-time and return this value back to the server. Here is how the client-server communication will look with this solution, as the diagram below shows:
- Under Replay skickar en klient en begรคran till servern om att starta en session
- En server tar emot begรคran och tilldelar ett nytt sessions-ID ZZZ
- En klient analyserar detta nya sessions-id ZZZ frรฅn begรคran.
- En klient skickar en begรคran om att starta sessionen med id ZZZ
- En server kรคnner igen ID:t ZZZ och lรฅter klienten spela upp skriptet igen
Detta รคr inget annat รคn korrelation.
The short video below walks through the same record-and-replay problem.
Klicka hรคr. om videon inte รคr tillgรคnglig
In case of VuGen, correlation is a binding relationship between a response and any preceding request.
There are various situations when a request is based on a previously received response from the server, such as a Session ID, or a server date and time which is fetched from the server. These values are different every time you run an application or record a script. Obviously, if the execution of the script depends upon a value returned by the server, it means you need to find a mechanism where you can โcatchโ the server response and attach it to those requests which the server expects. This is typically called Correlation in LoadRunner.
Med enkla ord รคr lรถsningen genom att anvรคnda korrelation:
- Fรฅnga utdatavรคrde frรฅn ett steg
- Anvรคnd ovan fรฅngade vรคrde fรถr att fungera som input till alla efterfรถljande steg
Correlation is classified into 2 categories in VuGen/LoadRunner:
- Automatisk korrelation
- Manuell korrelation
Automatisk korrelation
LoadRunner tillhandahรฅller en mekanism fรถr att enkelt utfรถra korrelation pรฅ automatiskt sรคtt.
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.
Automatisk korrelation kan delas in i tre kategorier:
- Autoupptรคck korrelation
- Regelbaserad korrelation
- Korrelera alla uttalanden
| Regelnamn | Nรคr ska du anvรคnda |
| Autoupptรคck korrelation | Detect and correlate dynamic data for application servers supported by LoadRunner |
| Regelbaserad | Anvรคnds nรคr du arbetar med en applikationsserver som inte stรถds fรถr vilken sammanhanget รคr kรคnt. |
| Korrelera alla | Hjรคlper till att korrelera all dynamisk data pรฅ ett blind sรคtt. |
รven om automatisk korrelation verkar enklare, kan den vara felbenรคgen och fungerar i hรถgst 5 % av fallen. Det รคr alltid lรคmpligt att anvรคnda manuell korrelation.
Fรถr att konfigurera automatisk korrelation vid inspelningstillfรคllet, utfรถr nedanstรฅende konfiguration i Record Time Setting efter att ett skript har spelats in.
Click on Record =>Recording Options (or click Ctrl +F7), shown in the menu below,
Nedanstรฅende fรถnster รถppnas:
Klicka pรฅ Korrelation =>Konfiguration โ nedanstรฅende fรถnster รถppnas.
Hรคr behรถver du markera som kontrollerat mot alla ansรถkningar (ASPNET) mm, som anvรคnds i din รคmnesansรถkan. Pรฅ hรถger sida kan du se reglerna som kommer att upptรคcka mรถjliga kandidater fรถr korrelation, t.ex. _VIEWSTATE. Du kan ocksรฅ lรคgga till fler applikationer eller anpassade regler genom att klicka pรฅ knappen Ny regel.
Du kan ocksรฅ klicka pรฅ REGLER, du kommer att se nedan:
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.
Vi kommer att fรถrstรฅ API som anvรคnds fรถr korrelation senare. Det รคr dock lรคmpligt att anvรคnda HTML-jรคmfรถrelse istรคllet fรถr textjรคmfรถrelse.
Nรคr du har valt nรฅgra regler, klicka pรฅ OK-knappen fรถr att stรคnga fรถnstren.
Click on the toolbar button shown here from the 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.
Observera att om du utfรถr korrelation manuellt eller anvรคnder automatisk korrelation, kommer kodbiten att innehรฅlla exakt samma syntax och funktion.
Steg fรถr att autokorrelera ett skript:
- Spela in ett manus
- Spela om manus
- Identifiera de vรคrden som ska korreleras
- Vรคlj vรคrdena och klicka pรฅ knappen autokorrelera
- Verifiera skriptet genom att kรถra igen. En framgรฅngsrik kรถrning betyder framgรฅngsrik korrelation.
Dricks:
- Korrelation hjรคlper till att kรถra ditt skript med olika vรคrden
- Korrelation minskar ocksรฅ storleken pรฅ ditt skript
Manuell korrelation
Manuell korrelation handlar om att skriva kod direkt i ditt skript fรถr att tillgodose stรคndigt fรถrรคnderliga vรคrden. Vi kan dela upp det i fรถljande steg:
- Bestรคm vรคrdet som ska fรฅngas
- Hitta hรถger och vรคnster textgrรคns fรถr vรคrdet som ska fรฅngas (WEB)
- Ta reda pรฅ vilken fรถrekomst av textgrรคnserna som ska anvรคndas
- Lรคgg till en web_reg_save_param-funktion till skriptet, ovanfรถr kodbiten som begรคr att sidan med vรคrdet ska fรฅngas
- Lรคgg till ett parameternamn, vรคnster grรคns, hรถger grรคns och fรถrekomst till funktionen
- Parametrisera det dynamiska vรคrdet i skriptet varje gรฅng det intrรคffar
- Verifiera korrekt utfรถrande
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);
Code anteckningar: both snippets appear exactly as published. Watch the ordinals: Ord=l och RelFrameId=l use a lower-case L, and VuGen expects the digit 1.
Manuell korrelation kan gรถras av VUser Comparison. Stegen i VUser Comparison-metoden fรถr korrelation kan delas upp enligt nedan:
- Identifiera dynamiska vรคrden som behรถver korreleras
- Find the server response containing the Dynamic value
- Fรฅnga det dynamiska vรคrdet i en parameter
- Ersรคtt varje fรถrekomst av det dynamiska vรคrdet med parametern
- Verifiera รคndringar
Understanding the 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
Versionsnotering: current VuGen releases treat web_reg_save_param_ex as the successor to the original function, and web_reg_save_param_regexp as the choice when the boundaries themselves change. The original example still runs.
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.
Hรคr gรฅr vi med funktionsdetaljerna:
web_reg_save_param(Parameternamn , Vรคnster grรคns , Hรถger grรคns )
Lista รถver attribut
The table below collects every attribute the function accepts, whether it is mandatory, and what it controls.
| Attribut | Nรถdvรคndig? | Vad den gรถr |
| Konvertera | Frivillig | HTML_TO_URL converts HTML-encoded data to a URL-encoded data format. HTML_TO_TEXT converts HTML-encoded data to plain text format. |
| Ignorera omdirigeringar | Optional, default โIgnore Redirections=Noโ | When set to Yes and the server response is redirection information (HTTP status code 300-303, 307), that response is not searched. The GET request goes to the redirected location and the search runs on the response from there. |
| LB | Krรคvs | 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. |
| HITTADES INTE | Optional, default โerrorโ | Handling when a boundary is not found and an empty string is generated. โNot found=errorโ raises an error. โNot found=warningโ (โNot found=emptyโ in earlier versions) instead sets the parameter count to 0 and continues, which is ideal when you want to see whether the string was found without failing the script. With Continue on Error enabled the script continues even under โerrorโ, but the extended log records it. |
| ORD | Optional, default 1 | Indicates the ordinal position or instance of the match. If you specify โAll,โ it saves the parameter values in an array. The use of Instance instead of ORD is supported for backward compatibility, but deprecated. |
| RB | Krรคvs | 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. |
| RelFrameID | Frivillig | The hierarchy level of the HTML page relative to the requested URL. The possible values are ALL or a number. RelFrameID is not supported in GUI level scripts. |
| SparaLen | Optional, default -1 | The length of a sub-string of the found value, from the specified offset, to save to the parameter. The default saves to the end of the string. |
| SparaOffset | Optional, default 0 | The offset of a sub-string of the found value, to save to the parameter. The offset value must be non-negative. |
| Sรถk | Optional, default ALL | The scope of the search โ where to search for the delimited data. The possible values are Headers (search only the headers), Body (search only body data, not headers), No resource (search only the HTML body, excluding all headers and resources), or ALL (search body, headers, and resources). |
Once the script replays cleanly, add parametrisering, transaktioner och kรถrtidsinstรคllningar, run it from the Regulator, and read the result in Analys as part of wider Prestandatester och Lasttestning.







