Package com.facilita.fc.web
- handling cookies
- HTTP caching and authentication
- HTML parsing
- HTML form handling
Creating scripts
When eggPlant Performance runs a test containing Web Java Virtual Users, aWebBrowserVirtualUser
object is created by the eggPlant Performance engine for every Virtual User
in the test. These WebBrowserVirtualUser
objects runs
scripts/workflows by creating instances of script classes (which are
subclasses of the WebBrowserScript
class) and
calling the script()
method on them.
Create scripts through eggPlant Performance Studio by right-clicking the Scripts folder in a workspace, and either recording a web trace or creating a blank script. A template is used to fill in the basic structure of the script:
e.g.
package com.testplant.testing;
public class MyNewWebJavaScript extends com.facilita.fc.web.WebBrowserScript
{
public void pre() throws Exception
{
super.pre();
// Put any code that needs to execute at the start of the test here
}
public void script() throws Exception
{
// Place your iterated script code here.
}
}
The name you give your script in eggPlant Performance Studio will be used as
the name of the class in the script file, and the class will be a subclass of
WebBrowserScript
.
In eggPlant Performance Studio you can define a test which includes a Virtual
User Group running your Web Java Virtual User script (or a workflow
containing your script). When the test is run in Test Controller, then code
written in the script()
method will execute. The script()
method will be called a number of times, relating to the number of iterations
that the VU Group is set to perform. This may be a fixed number per test, or
a VU Group can be set to run continuously for a certain period of time.
Sending web requests
ARequest
object is
created by calling
WebBrowser.createRequest(HttpMethod, Url)
. The
Request
object can be modified by adding HTTP request headers, or
setting POST data. The request can then be sent to the web server using the
Request.send()
or
Request.sendTopLevel()
methods.
e.g.
Request request = getWebBrowser().createRequest(HttpMethod.GET, new Url("http://www.testplant.com/"), 1);
Response response = request.send();
Handling HTTP responses
The return value ofRequest.send()
is a
Response
object. The
Response
object contains information about the
response from the web server, such as the HTTP status code, the HTTP response
headers, and the actual content of the response. Methods such as
Response.verifyContains(String)
,
Response.verifyTitle(String)
and
Response.extract(ExtractionCursor, String, String)
can be used to check that the response from the web server is correct.
The response may also contain sub-responses, such as images, CSS files, or
javascript. These can be accessed using the
Response.getSubResponses()
method.
Using HTML forms
Usually, aForm
object
is obtained by extracting it from a Response
,
using the Response.extractForm(int)
method.
Each element in the form is represented by an
HtmlElement
object. You can access the elements
in the form by using the various "get" methods (e.g.
Form.getHtmlElement(String)
,
Form.getInputElement(String, String)
). The
HtmlElement
objects can be modified to change the data that will be
sent back to the server. More elements can be added to the form using
Form.addElement(HtmlElement)
, and removed using
Form.removeElement(String, String)
.
e.g.
Response response = request.send();
Form form = response.extractForm(0);
The form is then usually modified by changing the HtmlElement
objects
it contains, and sent back to the server on a later request. This could be
either as query data on a GET request:
// Create a Url with the form data as a query string
Url url1 = new Url("http://localhost/");
url1 = url1.withQuery(form);
// Create a GET request based on the url and send it to the web server.
Request request1 = getWebBrowser().createRequest(HttpMethod.GET, url1, 1);
// Send the request to the web server
Response response1 = request1.send();
Or, as the message body on a POST request:
// Create a Url
Url url2 = new Url("http://localhost/");
// Create a POST request and set the form data as the message body
Request request2 = getWebBrowser().createRequest(HttpMethod.POST, url2, 2);
request2.setMessageBody(form);
// Send the the request to the web server
Response response2 = request2.send();
Customising Virtual Users
When developing Web scripts, it is recommended to customise the Web Java Virtual User type by performing the following actions in eggPlant Performance Studio:- Under Workspace/Virtual Users, right-click Web Java Virtual User, and then click New VU Type
- Type a name (which will be used as the class name) and a description
- Expand the newly-created custom Virtual User type, and the Source folder
- Edit the VU source file (the class which extends
WebBrowserVirtualUser
) by adding methods that can be called from any script which is based on your custom Virtual User, and/or overriding the methods inWebBrowserVirtualUser
.
WebBrowserScript
and will be the base class of
any script files you create with the custom Virtual User type.-
Interface Summary Interface Description WebSocketClosedCallback An interface defining the method that is called when aWebSocket
is closed.WebSocketErrorCallback An interface defining the method that is called when an error occurs on aWebSocket
.WebSocketReceivedMessageCallback An interface defining the method that is called when a message from the server is received on aWebSocket
-
Class Summary Class Description CachedResponse Represents an HTTP response that has been cached by theWebBrowser
.Coder Provides static methods for encoding and decodingString
data.ConcurrentRequestSender Provides methods for sending multipleRequest
objects to the web server concurrently.FileElement Represents anInputElement
which is a file select control.Form Represents an HTML form.HtmlElement Represents an HTML element within an HTML form.HttpStatus Represents an HTTP status code.ImageButtonElement Represents anInputElement
which is an image.InputElement Represents an HTML input element within an HTML form.NameValuePair Represents a name/value pair ofString
objects.OffsetEditSequence Objects of this class contains a sequence of one or more edit instructions.OptionElement Represents an HTML option element within an HTML form.QueryData Represents the query string of aUrl
as a sequence of name/value pairs.Request Describes an HTTP request.Response Describes an HTTP response returned by a web server.SelectElement Represents an HTML select element within an HTML form.TextAreaElement Represents an HTML textarea element within an HTML form.Url Represents a URL, specified by a protocol, optional credentials host, port, path, optional query data, and optional reference.WebBrowser TheWebBrowser
class is the starting point for sending web requests.WebBrowserScript Represents a Web Java Virtual User Script.WebBrowserVirtualUser Represents a Web Java Virtual User.WebSocket Represents a WebSocketWebSocketMessage Represents a message that can be sent or received over aWebSocket
WebSocketMessageQueue Provides a mechanism for waiting forWebSocketMessage
's to arrive from the server. -
Enum Summary Enum Description ConnectionType Represents an HTTP or HTTPS connection handler.HostFilteringMode Describes the modes available for filtering hosts.HttpMethod Describes an HTTP method.HttpStatusCategory Describes the HTTP status category for custom handling of the HTTP status codes.HttpStatusRange Describes the HTTP status ranges.InputElement.InputElementType Enumerates the different types ofInputElement
that are available.Protocol Represents an internet protocol.SearchFlags Used for searching for data with Correlation Rules.