visiblebody如何获取body帐号申请

Enter your search terms
Submit search form
The Trouble with AJAX and LoadRunner
Many tool vendors (including Microsoft and HP LoadRunner)
have not responded quickly enough with tools for AJAX because of how quickly
AJAX has been adopted.
One reason for the rapid adoption of AJAX is that no additional software
is needed since AJAX make use of what the clever designers of
have already built into internet browsers.
When the term AJAX was coined by Jesse James Garrett in ,
many in the industry were still struggling to achieve
common behavior among browsers and using
to build RIA (Rich Internet Applications).
After Gmail, Outlook WebMail offered
selective update of a web page
rather than refreshing the entire page with each user action
and enabled users to drag items,
other developers were inspired to develop websites with
the same interactive look and feel of a desktop app and
brave souls came forward with libraries (toolkits) to simplify use of JavaScript.
LoadRunner's HTML protocol (functions web_form_submit and
web_form_data) are based on a sychronous
exchange between client and server.
LoadRunner waits for a response after each request is sent,
and issued a time-out if one is not received.
The &A& in AJAX stands for Asychronous&, which means that
LoadRunner should not wait for a response from one request before
moving on.
The one command LoadRunner that seems to behave in this way works on
requests for resources of a single HTML request, not on multiple
requests. Its use with AJAX resulted in errors.
So LoadRunner scripters were forced to spend many hours essentially using
synchronous tools to solve asynchronous problems --
meticulously analyzing requests and responses
to figure out how to duplicate what went on inside the browser.
Such an approach requires a level of experience with web development that
most LoadRunner scripters lack.
Acknowledgement of how inefficient these efforts were came when
&reduces scripting time up to 80 percent&
are achieved by using
the entirely new set of
HP invented to work with AJAX.
The Annoyances with LoadRunner Click and Script
Scripting AJAX using LoadRunner is still
not as easy as HP salesmen may make it out to be.
Alas, lack of documentation, training events, and buggy implementations
resulted in LoadRunner users needing to fall back on time-consuming
Here are the annoyances with using LoadRunner on AJAX apps:
LoadRunner supports only a few of the
LoadRunner's User Guide contain only two pages to explain the new
Googling for posts about AJAX recording by LoadRunner
and interview question pages such as
yield few useful solutions or insights.
Script created by AJAX Click and Script recording
sometimes fail to recognize JavaScript calls
(elements within an in-line iframe that is within a frame).
Special functions for frameworks such as &Atlas&
(for Microsoft's ASP.NET AJAX) are released too late by HP
for obsolete versions xxx
that are no longer compatible with new (current) versions in use.
LoadRunner fails to execute some JavaScript code.
LoadRunner's Run-time Viewer does not completely repeat what
actually appears on the end user's browser.
Playback may not truly emulate behavior of a browser.
LoadRunner's C-based player can only handle one thread of execution
at a time.
Error messages issued by LoadRunner, the browser, or server
are often in-comprehensible.
To make matters worse, as LoadRunner's support for AJAX frameworks
failed to keep up with rapid changes
(and new libraries popping up all the time),
the belleaguered HP Support organization became defensive about defects.
Rumors are that this is due to organizational turmoil and apparent
infrequent communication with developers of LoadRunner in Isreal.
My observation is that technologies are progressing
so quickly that it's difficult for
traditionally organized organizations and programmers to keep up.
Alternatives to LoadRunner
Most workers are not in a position
to select what tool they get paid to use.
We just have to make it work.
Even if you have the political power to make good on an
emotionally satisfying statement like &to hell
with LoadRunner, I'm going to use Selenium&,
(or other product),
you may find that
there can be as much difficulty creating scripts
with other tools as with LoadRunner.
Each tool has its own strengths and weaknesses.
A tool that is quick to record scripts may require more manual effort
during runs and analysis.
What you may gain within another tool in one area (such as scripting)
you may lose in ease-of-use in another area (such as metrics collection
or analysis).
So my advice is to be tenacious (despite foot-dragging
by LoadRunner support),
insist on making use of the money your company pays
each year for LoadRunner maintenance,
and be fearless about diving into the innards
of not just LoadRunner but the application under test.
Refuse to close an issue and demand escalation when necessary.
The complexity of AJAX requires HP engineers to develop a
way to recognize tricky coding, which takes time.
This means that LoadRunner users have to wait for the next
release or beg HP Support for a patch.
I (Wilson Mar) also offer a service where I analyze your
script during a WebEx session or on-site.
Email me at WilsonMar
or call 310.320-7878.
Reverse Psychology
Testers dig into the system from the end-user
back through the system API down into application code.
This is quite a different process than what developers usually look at
(and relate to).
Developers struggle to understand the API so
conjure up code which make the system
behave the way they want.
On the other hand, LoadRunner C script creators struggle to
understand the actual implementation so
they can invoke behaviors
making requests of the system under test.
For example, when ASP.NET AJAX developers make use of the
LoadRunner scripters
do not see &SciptManager& anywhere when
looking at browser source code. But they know that its impact from the
because (unlike standard web pages),
JavaScript files are not explictly defined for retrieval in the HTML
source sent to client browsers.
Performance testers do not need to duplicate every behavoir of the
client application, only those behaviors that cause requests
to be made of the server.
X-Ray Eyes
The &XML& refers to the XMLHttpRequest (XHR)
method Javascript uses to make requests to the server
behind the scenes
rather than the GET and PUT methods which
refreshes the entire page with every interaction with the server.
JavaScript code then updates the HTML in the browser's DOM
(Document Object Model) containing all elements of the browser session.
This means that
what is happening inside the browser.
A Valuable Service to Developers
By diving into what makes AJAX work at the browser and server,
we can provide support to developers
working at the other end of the deployment chain.
Many LoadRunner testers (to their detriment) see their role as
scripting for simulation of load rather than also
providing actionable feedback to developers.
This works to the detriment of both parties
because it engenders an invisible wall between testers and developers.
Many developers, in order to save time (and code more productively)
make use of API libraries
so that they don't need to mess with how their coding
is actually resolved into JavaScript on client machines,
a process that can be quite convoluted.
Within Visual Studio a developer
can add to existing ASP.NET apps
AJAX partial rendering and error
template by dragging the UpdatePanel
and ScriptManager from the Toolbox of
controls to the design surface, add a visible field,
and set the Trigger property for the update event.
But problems in recording scripts
are usually reported from the point of view
of the end-user, at the other end of the convolutions.
This means that the developer then has to
trace the complex sequence of events backward from how
he or she usually needs to think in order to create source code.
For example, in the source code obtained from the browser,
a text box can have a name of "ctl100_SampleContent_MessageTextBox",
which would have no meaning to a developer if that name is
auto-generated by the API and not the developer.
This is where performance testers can uniquely provide value.
If someone can communicate difficulties with
how a page works not just from the end-user perspective,
but also in language that developers can understand,
then a valuable service is provided.
But this can happen only if that person takes
the time to first dive deep into how JavaScript works internally,
helped by learning some tools to analyze what is going on internally.
In organizations which accustomed to a wall,
it may also involve a cultural shift.
To achieve this, performance testers first must be able to open both
defects (reporting a violation of requirements), and
enhancement requests such as &add a UpdateProgress control to keep
users informed of remaining time to complete a long-running action&.
Perhaps management will add tested performance test scripts to the list of
work items which need to be produced before a module is considered
JavaScript Libraries LoadRunner Advertised to Support
HP has stated that they support these frameworks for AJAX functions:
Atlas 1.0.10920.0/ASP.NET AJAX (All controls)
(developed using Visual Studio 2005).
LoadRunner 9.10 supported the Atlas 2.0 version in Visual Studio 2005.
This is one generation behind the ASP.NET 3.5 AJAX AjaxControlToolkit
shown on the .
However, I have been able to use LoadRunner 9.51 to work with
many MS AJAX 3.5 controls even though some
controls are not being created during recording.
1.8 — Autocomplete, Reorder List, and Slider
HP advertises that VuGen supports these frameworks at the &engine level&,
implying that VuGen will create
Prototype 1.6
Google Web Toolkit (GWT) 1.4
I've heard that additional licensing is needed for
LoadRunner to support the
Infragistics library.
What is the HP product code for this, if it exists???
JavaScript Libraries LoadRunner Does Not Officially Support
At version 9.52, HP has stated that LoadRunner does not
support recognition nor replay of these AJAX libraries:
Microsoft's DataGrid nor recognition of HTC (HTML Compiled) sites.
(first released in 2006 by John Resig)
has been called intuitive, powerful, elegant, secure, and complete
because its common-send API
focuses on a flexible and rich way to work with the DOM .
such as Amazon, Google, Dell, IBM, Slashdot.
In late 2008 Microsoft announced it would be integrating jQuery into Visual Studio,
distributing jQuery version 1.3.2 with its ASP.NET MVC framework,
a constituant part of ASP.NET 4.0 and Visual Studio 2010.
Microsoft makes its AJAX library available on
of servers around the world by using this code:
<script src="/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
The &min& signifies the minified version (with white space removed).
reduces library file size up to 40%
by removing &white space& (tabs, line breakes, comments, etc.)
which are not needed to work but included for better readability.
Visual Studio 2008 Web Developer SP1 users can enable IntelliSense support
for jQuery by
and perhaps
to use a file name ending with -vsdoc to describe jQuery's
functionality to Visual Studio.
Using jQuery in VS 2008 .
jQuery is one of the 3 libraries
(ExtJs) AJAX Library (version 1.0 on April 1, 2007)
is vernerable for its compactness and speed. .
which is built on top of , is used by Ruby Rails
EXT 3.0 (announced August 2009) supports development of
(pronounced &gwit&),
which turns Java code (written using Eclipse IDE)
into JavaScript so that screen size and browser differences are
automatically addressed.
Its community of developers make for innovations such as enabling
Not mentioned by HP are these other JavaScript libraries:
, JavaScript library which powers Gmail and other Google web apps with
reusable UI widgets and controls,
utilities for DOM manipulation,
classes for server communication,
animation utilities,
data structure implementations,
a unit testing system,
rich-text editing, etc. using
from TIBCO. [ |
is not as well known, but it has enterprise cred.
It was the first to draw graphics using Microsoft
Internet Explorer's native VML (Vector Markup Language).
It also integrates with reverse AJAX library
(Direct Web Remoting) that pushs Javascript to AJAX clients
from back-end Java servers.
It also has a development environment and
functional Test Automation Kit (GITAK) with extensions to Selenium.
Its v3.5 adds a run-time code profiler and
Javascript performance-boosting obfuscator that works around regular expressions.
is popular open-source library that sits on top of
in front to
ICEfaces also supports server push.
is known for its cross-browser compatibility and ease-of-use.
For $1950, Isomorphic Software provides unlimited support to build list-and-drill-down type apps such as
. However, its library is rather bloated and slow.
(MIT Open Source from Python developer Bob Ippolito)
is a darling for its avowed focus on
&making Javascript suck less&.
(in Germany)
offers the basics of what all AJAX libraries need
within Microsoft.NET Framework 2.0 and 1.1. Good for simple projects
or as the basis for learning the internals of AJAX.
claims to be the &most widely used AJAX Framework with the richest library of AJAX components.&
LoadRunner Click and Script 16 Functions
AJAX function Emulates a user ...
web_browser
entering a URL Address.
web_button
clicking on a button.
web_check_box
selecting or clearing a check box.
web_edit_field
entering input fields with text and password.
web_element
clicking on an element defined with any HTML tag.
entering a path for file input elements.
web_image_link
clicking on an image that is a hypertext link.
web_image_submit
clicking on an image that fires a submit request.
selecting an item from a list control.
web_map_area
activating an area within a client side map.
web_radio_group
selecting one button from a radio button group.
web_reg_dialog
registering user response for the subsequent call to a
JavaScript function (modal dialog).
web_static_image
clicking on a static image.
acting on a table.
web_text_area
entering text in an input text area.
web_text_link
clicking on a hypertext link.
AJAX specific LoadRunner functions and other libraries
LR commands names beginning with &ajax_&
are relevant only to 1) the Microsoft Visual Studio 2005
&Atlas& AJAX framework library which Microsoft put on its
open-source website
and 2) scripts recorded and run using LoadRunner's AJAX protocol.
This table provides links to compare LR and demos of jQuery widgets:
LoadRunner Function
Emulates ... jQuery
ajax_accordion
a user extending or collapsing a menu.
ajax_autocomplete
selection of an item from a list based on text entered in a field.
ajax_collapsiblepanel
a user collapsing or expanding sections on a web page.
ajax_rating
a user setting a value of a rating control.
ajax_reorderlist
a user reordering elements in a list.
ajax_slider
setting a value using a slider control.
use of folder-style tabs in Atlas applications.
Some now consider Microsoft's AJAX library as rather basic because it doesn't
natively provide widgets which the
is enhanced by the open-source
, which displays more variations
This table also identifies where the jQuery depends on others'
add-ins, plug-ins, and extensions to fill out its widget capabilities:
Also, the jQuery UI library provides these interactions
and listed here:
http://ecn./o9/mix/10/mp4/EX22.mp4
Video: Six Things Every jQuery Developer Must Know by Elijah Manor
http://ecn./o9/mix/10/mp4/EX36.mp4
EX36 How jQuery Makes Hard Things Simple
John Resig
http://ecn./o9/mix/10/mp4/FT50.mp4
http://ecn./o9/mix/10/pptx/FT50.pptx
FT50 Advanced Web Debugging with Fiddler
Eric Lawrence
LoadRunner's Trouble with Recording
LoadRunner 9.51 has trouble recognizing elements within
an in-line iframe that is within a frame.
LoadRunner has trouble recognizing JavaScript within
.htc (HTML Component) files proprietary to Microsoft browsers
used by Microsoft DataGrid controls.
However, I have found a way to make LoadRunner work with it.
LoadRunner 9.51 does not process JavaScript DEFER tags the
same way as browsers render them. I have attempted to file a defect on this with HP.
This jQuery JavaScript code manipulates the DOM after its elements have been loaded:
$(document).ready(function() {
$("<p>dynamic text</p>").appendTo("body");
This jQuery code binds JavaScript to process a user button click:
<input id="cmdTest" type="button" ...
$("#cmdTest").bind('click', hellojQuery());''
Files To Consider
To resolve problems, I've found the need to analyze many files.
The above diagram illustrates the components that can be
considered when recording AJAX web apps.
Tools To Expose Behavior
This tutorial makes heavy use of tools that analyzes
each Asynchronous JSON request to and response
from ASP.NET app servers and displays
IE8 comes with Developer Tools in
its Tools menu or by pressing F12.
Its Profiler provides a count of how many times
each JavaScript function was invoked and how long they took.
Other add-ons appear in the Explorer Bars
The Firebug plug-in for Firefox does not handle IE.
HTTP Watch
provides a graphical analysis of resource download times.
It uniquely saves what it shows in a (*.hwl) file.
Being a commercial product ($300) enables it to offer more refined
presentation and user experience.
is a free tool which captures requests and responses
after attaching itself as a proxy of the HTTP communication service.
So anything that goes in and out of the browser is detected.
This means it can be run while VuGen executes.
NOTE: On Vista, set its options to disable IPV6 support.
is unique in providing an ASP.NET-specific
ViewState parser and
Debug/Trace feedback.
It also captures a page into a graphic file.
In addition to being a JavaScript console (immediate window),
DOM inspector, HTTP tracing tool, script profiler diagnostics,
However, because it is an IE6+ browser extension,
it is session-based and oblivious to what VuGen does since
VuGen emulates other browsers.
Microsoft Internet Explorer 7 has a built-in Script Debugger.
Although ,
this works after IE Tools > Internet Options > Advanced Tab
&Display a notification about every script error&.
is checked. Restart IE for the changed settings to take effect.
Many prefer the Microsoft Script Editor installed with
Microsoft Office XP/2003.
article note that
if Options do not have "Disable Script Debugger" checked, go to
View > Script Debugger > Open. Select
View > Script Debugger > Break at next statement.
A JavaScript debugger comes with a Microsoft Visual Studio edition
called Visual Web Developer (VWD) 2008 Express Edition.
To use it, create a new project of type Web Site.
Click the play button, and Visual Studio will launch IE 7.
It might ask you if you want to enable debugging.
At the empty project, type any address in the address bar for the debugger to work on.
Strategy for Recording Using LoadRunner
In following , run through the business process
to write down the manual activities you will
perform and the verification necessary.
Due to the complexity of AJAX,
I also recommend saving a graphic file (visual snapshot)
for each before/after condition
along with the HTML that created each.
After recording, additional script coding is usually needed
to be added to reveal internal conditions.
Invoke VuGen
(from Start > LoadRunner > Applications > Virtual User Generator),
click &New User Script& to create a new Multi-protocol script of
&Web (Click and Script)& (available in LoadRunner v8.1 FP4 and later).
Click the right arrow to move it over to the Selected Protocol,
then click OK.
This activates technology from the HP QuickTestPro (QTP) product
which recognizes and replays Javascript just as the browser would.
I usually get rid of the Tasks pane and click the Script icon.
In VuGen menu Tools > Recording Options,
by pulling down the Tools menu. In Advanced,
check &Record rendering-related property values&
&Enable generation of out-of-context steps&.
In Web Event Configuration,
move slider up to High.
Adjust this back down to Medium on less
difficult apps.
Rather than recording into the default vuser_init or Action section,
I prefer to make a habit of recording into a separate new
&Recording& VuGen action file (then copying and pasting generated code).
This is because I at times wiped out my edited Action code.
Click Start Record.
Select &Internet Application& and type in the URL of the AJAX-enabled page you want to script.
For this tutorial, we use the
at . Microsoft updates this page to the
latest release. Known releases are the September 2009 Release Version 3.0.30930 and
Version 3.0.30512 based on .NET Framework 3.5 developed using Visual Studio 2008.
There is an earlier version on .NET Framework 2.0 developed using Visual Studio 2005.
If you get a &Data Protection Exception&,
from the start menu, select "All Programs", then "Accessories"
and right-click on the "Command Prompt" shortcut and choose "Run As Administrator".
Click Continue to confirm.
Disable Data Execution Prevention (DEP) with this following command:
bcdedit.exe /set {current} nx AlwaysOff
After your run, turn it back on again:
bcdedit.exe /set {current} nx AlwaysOn
The expected response from the computer is:
The operation completed successfully.
If you are running with IE7, you may get
. If so, click Yes, then open up IE again
and paste the app URL in the IE Address bar.
You should now see the count of events increment.
Before performing each activity on the page being recorded,
I add a comment
so I can remember the text I clicked on and why I did it.
Copy and paste the text from your list of actions planned.
If you didn't plan, open a Notepad and add to the list as your record.
Stop the recording. VuGen then generates LoadRunner script code.
ASP.NET/AJAX/Samples
(such as fade, fold, pulsate, puff, bounce, and explode)
are purely &eye candy& on the client screen
and do not trigger communication with the server (and thus impact load).
However, such actions may nevertheless need to be recorded if they
change a variable value sent to the server in subsequent actions.
At the time I accessed the example site,
there were 32 items on the left panel of controls,
starting from &Accordion&.
The people who created this page were nice enough to be consistent about
every control, so I can code just one function to invoke each of them each from a list.
This means I could verify whether the correct page was retrieved by looking for
the control's name before the word " Demonstration".
The function I code for each control then would contain code only applicable
to that control.
Notice that JavaScript files downloaded to a client from an
ASP.NET AJAX web app are not specified in a <script src ...
HTML tags. This is because the AJAX ScriptManager
manages downloading of its Scripts collection.
The ScriptManager names have a strange set of unique characters.
web_reg_cross_step_download
Previously to AJAX, it was assumed that each web page receives
a response before going to the next step.
But AJAX code can fire and move on.
To accomodate Asynchronous AJAX,
a LoadRunner service function can be addeded manually to the script.
web_reg_cross_step_download("URL/RE=start_a\.htm$",LAST);
The \. and dollar sign ($) are regular expression markers.
Working with JavaScript Variables
To obtain a value and display it by issuin a pop-up alert,
remember to escape quotes around values:
web_browser("keyId_Get",
"EvalJavaScript=document.getElementById(\"keyId\");",
"EvalJavaScriptResultParam=rKeyId",
web_browser("Send_Alert",
"EvalJavaScript=alert(\"rKeyId=\"+\" {rKeyId}\");",
The double underlines in the JavaScript function
__doPostBack(eventTarget, eventArgument)
invoked to trigger postback indicate that it belongs to (generated by)
the underlying ASP.NET engine and not custom application code.
It has two parameters:
__EVENTTARGET containing the control name and __EVENTARGUMENT stored in hidden
form INPUT fields.
"EvalJavaScript=alert(\"EVENTTARGET=\"+Request.Params.Get(\"__EVENTTARGET\"));",
To change a value within the JavaScript DOM, use the .Value method:
web_browser("keyId_Set",
"EvalJavaScript=document.getElementById(\"keyid\").Value=\"123ABC\"";",
To use JavaScript to submit against <form id="myform" action="...
web_browser("keyId_Set",
"EvalJavaScript=document.myform.submit();",
Recording Sensitivity
By default, LoadRunner generates onFocus statements.
They are not neededd (and can be deleted)
unless there is an onFocus event specified in javascript.
So disable it in Options > Recording > Custom.
Modal Dialogs
With AJAX, user actions are emulated using the new
web_reg_dialog LoadRunner service function
which references code in an action automatically created by LoadRunner
during recording.
web_reg_dialog(
DESCRIPTION,
"Type=Confirm",
"Message=Click OK to continue",
"Click=OK" ,
To enter text in a pop-up edit box after the next AJAX command is invoked:
web_reg_dialog(
DESCRIPTION,
"Type=Prompt",
"Message=Where is Walt Whitman buried?",
"SetText=Camden, N.J." ,
To close a modal dialog window:
self.close();
window.close();
Find the Value
There are two values that LoadRunner needs:
the ID of the element and the value.
Fortunately, when the wrong value is provided to a function,
VuGen displays a list of possible valid values.
Some web pages block all keys and programmatically recognize
only specific keycodes.
This is done to disable right-clicking by website users.
To obtain the value for the ID of a form INPUT field:
web_edit_field("1_1",
"Snapshot=t21115.inf",
DESCRIPTION,
"Type=password",
"name=PinCode",
"WindowType=Modal",
"EvalJavaScript=document.getElementById(\"ct100_CardNum\").value=\"1\"",
Try this equivalent EvalJavaScript:
"EvalJavaScript=$get(\"ct100_CardNum\").value=\"1\"",
If you find that LoadRunner parameters in EvalJavaScript values are not being recognized, use sprintf to define a C string and expand the LoadRunner parameter into that. then use the resulting string in place of the EvalJavaScript attribute.
Try this equivalent EvalJavaScript:
sprintf(buffer1,"EvalJavaScript=%s",lr_eval_string("{myvar1}"));
Replay Problems
"JavaScript Failed to compile" errors may be caused by the
JavaScript engine not having time to update.
Try adding before the request:
sleep(1000);
"Failed to execute JavaScript code" may be avoided by invoking the submit directly:
"EvalJavaScript=this.Form1.Submit();",
Getting Information by Recording in Web HTML Mode
In the past, to obtain information not displayed during AJAX protocol recording,
I performed a recording in HTML protocol.
However, I prefer to use developer tools instead.
In looking at output from the Log Viewer, I can make a
Before Replay
In Tools > General Options > Display tab >
check "Show browser during replay".
Then click the replay button.
Before changing the generated script,
play the script back, save it with an appropriate name,
exit the script file, and zip it up.
In the script generated, comment out lr_think_time lines,
delete web_add_cookie_ex code and these lines automatically added:
web_browser("Please enter the initial URL here",
DESCRIPTION,
"Navigate=Please enter the initial URL here",
In the Run-Time Viewer, I review each activity I performed
to verify whether the Run-Time Viewer captured the displays.
For example, I found that the pop-up for control "AlwaysVisibleControl"
does not appear in the Run-Time Viewer.
Wait for what you typed in to appear to the right of "Text in the AJAX Response:".
If you had recorded with option ___ set at __,
when VuGen encounters a page with no title,
it erroneousy generates this line:
web_reg_find("Text=Untitled",
To avoid a playback error, comment it out (with //).
Press F4 to set Runtime Settings Log to display everything all the time:
Advanced and all boxes checked.
In Runtime Settings Internet Protocol Advanced Options
Step Download Timeout
and set its value to 9999 (rather than the default 120).
In Tools > General, set Display
Replay the recording.
Save the script using a file name that distinguishes it among all your other recordings.
Date (e.g., "")
Environment (DEV, PRD, etc.)
The condition of the script (works, FrameErr, etc.)
Zip up the script folder immediately after a recording.
This preserves the Generation Log.
Analyze. Click the &Generation Log& tab for the detailed sequence of (header and body) requests and responses.
Unlike static HTML web pages, one cannot &View Source& at the client browser to look for text to correlate.
With AJAX sites, one must look at the dynamic exchange of data
VuGen captures in its Generation Log and
in VuGen's new Tree view.
VuGen captures the traffic between client and server much like HTTP Proxy client utilities such as
In the Generation Log, the first GET request is for the URL specified to obtain the response.
"HTTP/1.1 200 OK" is the normal expected valid response, as agreed in the .
In the Response Header, notice the
Set-Cookie: JSESSIONID=89BA28F07F366FD57F4A; Path=/a4j-simpleRepeator
The first Response Body for that Request Header in the Generation Log is below, indented with line breaks:
<HTML>
<HEAD>
<TITLE>ajax4jsf. Simple Repeator Demo</TITLE>
<script type="text/javascript" src="/a4j-simpleRepeator/org.ajax4jsf.resource/org.ajax4jsf.framework.ajax.AjaxScript">
</HEAD>
<BODY>
<form id="_id0" method="post" action="/a4j-simpleRepeator/demo.jsf" enctype="application/x-www-form-urlencoded">
<table><tbody>
<td> Type the Text:</td><td><input type="text" name="_id0:_id3" value="" onkeyup="A4J.AJAX.Submit('_viewRoot','/a4j-simpleRepeator/demo.jsf',this,{'parameters':{'_id0:_id4':'_id0:_id4'}})" size="50"></td>
</tr><tr>
<td>Text in the AJAX Response:</td>
<td><span id="_id0:repeater"></span></td>
</tbody></table>
<input type="hidden" name="_id0" value="_id0">
</form>
</BODY>
</HTML>
The remaining HTML is not shown here.
The first "Add Event" is the LoadRunner script generated from the first GET request.
Scroll down through the second set of requests for the "AjaxScript" file requested in the <script tag:
If the script was recorded with "Recording Options" set to "HTML", then the script would not have a separate request for the AjaxScript
because the &mode=HTML& in the VuGen script tells LoadRunner to automatically retrieve resources (such as script, css, img, and other files) mentioned in the HTML.
The &jsessionid=& appended to the end of the URL to retrieve the AjaxScript
means that the file will be downloaded again at the start of every session, which
developers want if the file changes dynamically.
If the script file is not expected to change, users would not need to wait for the file to be downloaded
if there was not a &jsessionid=& in the URL, since
the browser will automatically reuse what remains in the cache.
That is unless the browser has been set by the user to "refresh with every page" or the expiration date on the file has passed.
When normally static file changes, developers rename the file name to ensure that all active clients
get the new file rather than reusing the old file in their cache.
The AjaxScript file can be examined at the location where browsers download resources (cookies, CSS files, etc.).
On IE browsers, pull down "Tools", "Internet Options", click "Settings" within the "Temporary Internet files" section, then "View Files...".
This opens up a Windows Explorer.
Scroll right or expand the width of the window to click "Last Accessed" once or twice to sort the list.
Save the file by right clicking on it, select "Copy", then paste it into another Windows Explorer window.
At that new location, right click on it, select "Properties" to note its size (e.g., 50,798 bytes).
Use Wordpad to edit the file because it contains UNIX style line breaks which Notepad ignores.
For faster download, "production" websites would have the content of static compressed (stripped of whitespace such as blank spaces and tabs).
If that is the case, for human readability we would need to
reverse the compression by saving the code in a file and sending it through a code formatter utility to indent the statements.
The SlickEdit editor can reformat code.
BTW, at the top of the file, notice the comment "
is an ECMAScript library acting as a cross-browser wrapper for native XML APIs."
Scroll down to see that this particular library uses logging functions extensively.
Change the Recording Mode to "URL" and re-record the script again.
Notice that &RecContentType=text/javascript& appears even when the file name is suffixed with ".AjaxScript" rather than ".js". "AjaxScript" is really JavaScript.
The next request is a "POST" which was triggered by onkeyup=, that browsers recognize as
an event that should fire when certain keys are pressed and released.
As of Internet Explorer 5, the event also fires for the following keys:
* Editing: BACKSPACE
* Navigation: PAGE UP, PAGE DOWN
* System: SHIFT+TAB
Other websites code the onKeyPress= event instead because it represents the entire keystroke and can be canceled.
The event specified to fire is the A4J.AJAX.Submit function defined in a JavaScript/AjaxScript library on the client.
Other libraries may use another function name.
Unlike other attributes, "onkeyup=" does not require the user to click on another area of the screen before it gets to work.
Search for this in the ActionScript file.
We see that it accepts 3 parameters (separated by commas within the parentheses):
A4J.AJAX.Submit =
function( containerId, form, obj , options ) {
This function in turn calls A4J.AJAX.SubmitRequest (which has the same parameters)
at last invokes form.onsubmit that sends a request out to the server
&/a4j-simpleRepeator/demo.jsf&,
Java Server Faces file. specified &<form action=& HTML.
The request body shown in the Generation Log, such as:
AJAXREQUEST=_viewRoot&_id0%3A_id3=x&_id0=_id0&_id0%3A_id4=_id0%3A_id4&
are formatted in the "Add Event" script presented under "ITEMDATA" in VuGen scripts, presented in this table with a
correspondence to the source of parameters in HTML code through AjaxScript functions:
onkeyup= A4J.AJAX.Submit parameter
parameter in Javascript function
VuGen script generated within web_submit_data
<form action=...
'/a4j-simpleRepeator/demo.jsf'
"Action=/a4j-simpleRepeator/demo.jsessionid={JSESSIONID2}",
'_viewRoot'
containerId
"Name=AJAXREQUEST", "Value=_viewRoot",
<input type="text" name="_id0:_id3"
"Name=_id0:_id3", "Value=x",
{'parameters':{'_id0:_id4':'_id0:_id4'}}
"Name=_id0:_id4", "Value=_id0:_id4",
<input type="hidden" name="_id0" value="_id0">
"Name=_id0", "Value=_id0",
<form ... enctype="application/x-www-form-urlencoded"
"RecContentType=text/xml"
Within Javascript, &this& refers to the text object itself,
which in the example contains a text value &x&.
The enctype="application/x-www-form-urlencoded" in the HTML form requests the browser to send (asynchronously) what the HTTP spec calls an XMLHttpRequest by specifying Content-Type: application/x-www-form-charset=UTF-8 in the Request Header.
&RecContentType=text/xml& appears with the web_submit_data instead of
&RecContentType=text/html& for regular HTML requests.
Internally, this results in VuGen sending out a "HTTPXMLrequest".
Going back to the Generation Log,
notice that the second and subsequent Request Header do not contain a &Set-Cookie& as in the first Request.
The second and subsequent Response Header do not contain a &Cookie: JSESSIONID=&
that browers and LoadRunner automatically resend back to the server to help maintain the same session.
To see what comes back from a request, scroll down to the "Response Body For Transaction" under the request above.
Note that the response body begins with <?xml version="1.0" encoding="iso-8859-1"?>, which IE does not display.
During playback, the Run-Time Viewer would display an error for pages beginning with this
(if in "Tools", "General Options", "Display" tab, "Show browser during replay" is checked).
A JavaScript listener function in the AjaxScript reads the rest of the response body. For example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>ajax4jsf. Simple Repeator Demo</title>
</head>
<body><hr />
<span id="_id0:repeater">x</span>
<span id="ajax-update-ids" style="display: none" title="_id0:repeater">
<input type="hidden" name="jsf_sequence" value="1" />
</span>
<div style="font-size:9height:150width:800
border: 1padding: 5px 5px 5px 5 overflow:"
id="logConsole">
</body></html>
Notice that this response does not contain some of the HTML of the first Response Body
(why AJAX is preferred over traditional whole-page exchangees).
from the server to the request sent to the server is received by the AjaxScript.
We trace through the AjaxScript code to learn that in the incoming XML:
<span id="ajax-update-ids" style="display: none" title="_id0:repeater">
id="ajax-update-ids" triggers an update of the innerHTML text in the object named in
title="_id0:repeater", which is defined in the
by <span id="_id0:repeater">.
An AjaxScript "callback" function update displays the text "x" between <span id="_id0:repeater"> and </span>.
So to verify the response, add to the VuGenscript a LoadRunner web_reg_save_param()
call to capture the text between those two markers.
web_reg_save_param("pRetText","Search=Body", "ORD=ALL",
"LB=<span id=\"_id0:repeater\">",
"RB=</span>", "Notfound=warning",
Note that back slashes are added to quote characters being searched.
The first parameter in the &web_submit_data(& displayed in Add Events and in the VuGen script generated for the "POST"
is often edited by performance engineers to avoid confusion because the session code there is what was captured during recorded
and will change with every session.
Click on the VuGen script window.
Add logic to perform the VuGen script command to capture the JSESSIONID value AGAIN if cookies are cleared or if the application user logs off.
Add logic to NOT perform the VuGen script command to capture the JSESSIONID value during the same continuous session.
This can be done by declaring an integer (binary) flag in the vuser_init section:
int intHaveJSessionID = 0; // 0 = NO.
The Action section would have:
if( intHaveJSessionID == 0 ){
web_reg_save_param("JSESSIONID2",
"LB/IC=jsessionid=",
"RB/IC=\"",
"Search=header",
"RelFrameId=1",
intHaveJSessionID = 1; // 1 = YES
web_cleanup_cookies();
intHaveJSessionID = 0;
Simply adding &Notfound=warning&, to the generated web_reg_save_param command does not work because
that would cause the JESSIONID2 parameter to be unusable when the value is not there to find.
Because the Response Header is usually smaller than the Response Body, you can save a little script execution time by changing
&Search=body& to
&Search=header&
Pull down the "Tools" menu for Recording Options. Mouse over to the "GUI-based script" and note that the description reads:
&Generate a step for each user action, for a concise, intuitive script. JavaScript is evaluated during replay.&
During VuGen script development, you may also want to set Run-Time Settings to ignore think times.
Record another sample URL: .
Instead of a traditional web_submit_data command,
VuGen may records this out-going XML requests as web_custom_request() commands containing
a Body such as:
"Body=AJAXREQUEST=_viewRoot&_id1%3AtextArea=This%20text%20area%20should%20not%20be%20updated&_id1%3A_id18=any&_id1%3A_id21=yellow&_id1%3A_id24=any&_id1=_id1&_id1%3A_id22=_id1%3A_id22&",
, require hidden type fields such as com.sun.faces.VIEW to be captured within VuGen scripts.
A very popular Ajax library is Yahoo's BSD-Licensed . Record the
functional example. An analysis of the files downloaded:
Requested by/as
File Downloadload
.../reset.css
.../yahoo.js
global object used by YUI Library.
.../event.js
.../dom.js
.../calendar.js
.../calendar.css
...bc_1.7.3.js
EXTRAREScalendar.css
...callt.gif
...calrt.gif
YAHOO.namespace("example.calendar"); invokes a function in the yahoo.js library which
invokes the function YAHOO.widget.Calendar.
function init()" in the calendar.js library knows to replace
<div id="cal1Container"></div> with HTML code that it generates based on the current date.
Such generated HTML can only be seen if "Full Source" or a special Microsoft DLL is installed.
In that generated HTML, each clickable field is defined with a class and an id that are also generated internally by JavaScript.
YAHOO.util.Event.addListener(window, "load", init);
establishes a listener for responses from the server.
JSON Coming Back
The following response from the server is a
JSON (JavaScript Object Notation) data payload format.
Its use of braces and indentation instead of tags in XML makes it more &lightweight& and easier to read.
{"addressbook": {"name": "Mary Lebow",
"address": {
"street": "5 Main Street"
"city": "San Diego, CA",
"zip": 91912,
"phoneNumbers": [
"619 332-3452",
"664 223-4667"
Within browser Javascirpt, this is read by code such as:
var myObj = eval( '(' + JSON_response + ')' );
JSON is also favored because its use of server callback functions
gets around browsers preventing files being loaded across domains
lists links, such as
Resources:
by Siva Darivemula, Director of Product Marketing HP Software
Portions &Copyright
Wilson Mar. All rights reserved. |

我要回帖

更多关于 如何获取body 的文章

 

随机推荐