Load Runner Advanced Scripting Techniques
Load Runner Advanced Scripting Techniques
Introduction
Let's suppose that you have ten scripts to write and each one starts with a complex login screen, for example. The usual approach to this would be to record your scripts one at a time and correlate and parametize each one independently. And if, at a later date, the recorded login functionality changes, each script would then have to be modified accordingly. There is however another approach: Record one script and program the login screen until it works. Then, build a function from this working code and call this function from within each script that needs to login to the application under test. This document shows how this can be achieved quickly and easily with a minimum of coding knowledge. Just follow the example below. Suppose you want to record a web searching script where each different type of user logs into your site and performs a different search depending on their particular business rules. So for each type of user you have a separate script but they all share the same initialization function (init()) where they login.
"Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST); web_concurrent_start(NULL); web_url("y3.gif", "URL=http://us.i1.webwob.com/us.webwob.com/i/ww/beta/y3.gif", "Resource=1", "RecContentType=image/gif", "Referer=http://www.webwob.com/", "Snapshot=t2.inf", LAST); return 0; } Action.c (variable searching activities) Action() { web_add_cookie("D=_ylc=X3IDMwRmcANyL3N4&_ylg=X3oDMTQwczUxMzEy; DOMAIN=www.webwob.com"); lr_think_time(15); web_url("p.gif", "URL=http://www.webwob.com/p.gif?t=1166801046&_ylp=A0LEfYGW.ItFtV8AN131 cSkA&, "Resource=1", "RecContentType=image/gif", "Referer=http://www.webwob.com/", "Snapshot=t31.inf", LAST); web_add_cookie("B=bjh9s8t2jc687&b=3&s=5n; DOMAIN=search.webwob.com"); web_add_cookie("Q=q1=AACAAAAAAAAAfA--&q2=RYtEeg--; DOMAIN=search.webwob.com"); web_add_cookie("SO=v=0.4&t=1166799707; DOMAIN=search.webwob.com"); web_url("search",
"URL=http://www.webwob.com/r/sx/*http://search.webwob.com/search?p=Nikon+F-301+1985&fr=yfp-t501&toggle=1&cop=mss&ei=UTF-8&vc=&fp_ip=UK", "Resource=0", "RecContentType=text/html", "Referer=http://www.webwob.com/", "Snapshot=t32.inf", "Mode=HTTP", LAST); return 0; } globals.h (This is used next. See below.) #ifndef _GLOBALS_H #define _GLOBALS_H //-------------------------------------------------------------------// Include Files #include "lrun.h" #include "web_api.h" #include "lrw_custom_body.h" //-------------------------------------------------------------------// Global Variables #endif // _GLOBALS_H
web_add_cookie("B=bjh9s8t2jc687&b=3&s=5n; DOMAIN=www.webwob.com"); web_add_cookie("Q=q1=AACAAAAAAAAAfA--&q2=RYtEeg--; DOMAIN=www.webwob.com"); web_add_cookie("SO=v=0.4&t=1166799707; DOMAIN=www.webwob.com"); web_url("www.webwob.com", "URL=http://www.webwob.com/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST); web_concurrent_start(NULL); web_url("y3.gif", "URL=http://us.i1.webwob.com/us.webwob.com/i/ww/beta/y3.gif", "Resource=1", "RecContentType=image/gif", "Referer=http://www.webwob.com/", "Snapshot=t2.inf", LAST); return 0; } Save this file somewhere in your file structure. Let's say it is under c:\LRScripts. Next, edit the vuser_init.c file so that it looks like this: vuser_init.c vuser_init() { login(); return 0; } And edit the globals.h file thus: globals.h (Note the additional line.)
#ifndef _GLOBALS_H #define _GLOBALS_H //-------------------------------------------------------------------// Include Files #include "lrun.h" #include "web_api.h" #include "lrw_custom_body.h" #include "c:\\LRScripts\mylogin.h" //-------------------------------------------------------------------// Global Variables #endif // _GLOBALS_H
mylogin.h login(char* username, char* password) { web_add_cookie("FPS=dl; DOMAIN=www.webwob.com"); web_add_cookie("B=bjh9s8t2jc687&b=3&s=5n; DOMAIN=www.webwob.com"); web_add_cookie("Q=q1=AACAAAAAAAAAfA--&q2=RYtEeg--; DOMAIN=www.webwob.com"); web_add_cookie("SO=v=0.4&t=1166799707; DOMAIN=www.webwob.com"); web_url("www.webwob.com", "URL=http://www.webwob.com/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST); web_concurrent_start(NULL); web_url("y3.gif", "URL=http://us.i1.webwob.com/us.webwob.com/i/ww/beta/y3.gif", "Resource=1", "RecContentType=image/gif", "Referer=http://www.webwob.com/", "Snapshot=t2.inf", LAST); return 0; } Inside mylogin() you can refer to username and password just like any other variable and vuser_init() passes the data into the function like this: login("user_id1", "Password1");