Open topic with navigation
int web_js_run("Code=<JS code>" | "File=<file_name>",["Domain=domain",] ["ResultParam=parameter name",] [SOURCES,["File=file_name" | "Code=code", ENDITEM,]+ ] LAST)
|Example: web_js_run and web_js_reset||Miscellaneous Functions|
A delimiter that separates one set of values from the next, where a set of values defines one compound argument. Sometimes a set contains a single value. Do not pass ENDITEM except to separate definitions.
|LAST||Required marker for the end of the argument list.|
One of either the main Code argument or the main File argument is required. Do not pass both.
Files referenced with File arguments must be present in the VUser directory. If the files are in a subdirectory, pass the relative path. For example, "
js_scripts/code.js", where js_scripts is a subdirectory of the VUser directory.
In the SOURCES section, place any items that have to be evaluated before the main Code or File is evaluated. Arguments in the SOURCES section are evaluated in the order in which they appear. The entire SOURCES section is evaluated before the main File or Code argument.
://". The base URL in the Domain argument must include the protocol, for example,
Example of use of the Domain argument:
web_js_run(“Code=” “var request = new XMLHTTPRequest();” “request.open(‘GET’, ‘page.html’, false);” // Relative URL // more code… , “Domain=http://www.mysite.com/abc”, // Base URL LAST);
This request resolves to
web_js_run cannot run script directly from a URL, for example:
"URL=http://www.domain.com/file.js". If you need to run code from a web server, download the page with web_url, save the response to a parameter, and use the parameter in the web_js_run call.
When the code called in a web_js_run step returns, the context is not discarded. Therefore, functions, objects, and variables remain in context and can be used in subsequent steps of web_js_run.
For example, if a function is defined in one web_js_run step, it can be used in a subsequent step without redefining it. In addition, if the function in a web_js_run step defines, calculates, or fetches some data, that data can be used again in a subsequent web_js_run step.
If the runtime setting
Simulate a new user on each iteration is set, web_js_reset is called automatically at the start of each iteration. If
Simulate a new user on each iteration is not set, avoid excessive memory consumption by inserting web_js_reset calls in your script at points where you no longer need the saved context.
Several TruClient functions can be used in the code of a web_js_run call. These functions are documented under Documentation Library > VuGen > Protocols > Ajax TruClient Protocol > TruClient Functions. These functions have equivalent utility functions, as shown in the following table:
|TruClient Function||Equivalent VuGen Utility Function|
This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.