9 Web/HTTP Load Module

This chapter provides a complete listing and reference for the methods in the OpenScript HTTPService Class of HTTP Load Module Application Programming Interface (API).

9.1 HTTPService ENUM Reference

The following section provides an alphabetical listing of the enums in the OpenScript HTTPService API.

9.1.1 Alphabetical Enum Listing

The following table lists the HTTPService Enums in alphabetical order.

Table 9-1 List of HTTPService Enums

Enum Description

EncodeOptions

When solving variables using solve(), specify an additional encoding/decoding transformation to apply the variable's value.

Source

For the find() and solve() functions, specify which part of the browser response in which to look.


9.2 HTTPService API Reference

The following section provides an alphabetical listing of the methods in the OpenScript HTTPService API.

9.2.1 Alphabetical Command Listing

The following table lists the HTTPService API methods in alphabetical order.

Table 9-2 List of HTTPService Methods

Method Description

http.addAuthentication

Add a username and password to use when authenticating a URL that requires NTLM or Basic authentication.

http.addCookie

Adds a cookie to the cookie jar.

http.addGlobalAssertText

Registers a text assertion test to run every time a page is requested.

http.addGlobalVerifyText

Registers a text verification test to run every time a page is requested.

http.addValidator

Adds a class to provide custom validation for all browser responses.

http.assertResponseTime

Tests the server response time for the previous request.

http.assertText

Searches the HTML contents of the specified document XPath for the specified text pattern.

http.assertTitle

Searches the <title> tag in the HTML content for the specified title pattern, reporting a failure if the test fails.

http.assertXPath

Extracts a value from the browser's last retrieved contents using XPath notation.

http.beginConcurrent

Begins a concurrent section used to make multiple HTTP requests at the same time by the same Virtual User using a different HTTP connection.

http.clearCookies

Clears the Cookies during playback.

http.delete

Requests a web page using an HTTP DELETE method.

http.deletedata

Convenience method to return a deletedata ParamCollection.

http.element

Finds the element from the browser's DOM tree using XPath notation.

http.endConcurrent

Ends the specified concurrent section waiting the specified amount of time for requests to finish.

http.form

Finds the form element from the browser's DOM tree using XPath notation.

http.frame

Finds the frame element from the browser's DOM tree using XPath notation.

http.get

Requests a web page using an HTTP GET method.

http.getBrowser

Gets a Thin browser for making HTTP requests.

http.getHtmlContent

Gets the HTML content of a document which is specified by the XPath.

http.getLastBrowserResponse

Gets the last retrieved response from this Virtual User's browser.

http.getLastResponseContents

Returns a String version of a given browser response from the specified source type.

http.getResponseHeaders

Gets the headers of a response and its ancestors that is received by a window specified by the XPath.

http.getSettings

Gets the settings for the HTTP service.

http.getValidatorList

Returns all the validators added by addValidator.

http.header

Convenience method for creating a new Header object.

http.headers

Convenience method to create a new Header array.

http.httpdata

Convenience method to return a httpdata ParamCollection.

http.javaScriptPath

Builds the JavaScript path(s) to use to extract JavaScript strings using http.solveGroupJavaScript.

http.link

Finds the link element from the browser's DOM tree using XPath notation.

http.loadKeystore

Loads the keystore file using the specified password.

http.multipartPost

Requests a web page using a multipart HTTP POST method with querystring, postdata, headers, boundary, URL-encoding, and character sets.

http.navigate

Navigates to a web page using the specified ID, URL, additional headers, redirect, character set, method, and input stream.

http.param

Convenience method to create a new File Parameter object.

http.patch

Requests a web page using an HTTP PATCH method with querystrings, putdata, headers, URL encoding, and character sets..

http.patchdata

Convenience method to return a patchdata ParamCollection object.

http.post

Requests a web page using an HTTP POST method with querystrings, postdata, headers, URL encoding, and character sets.

http.postdata

Convenience method to return a postdata ParamCollection.

http.put

Requests a web page using an HTTP PUT method with querystrings, putdata, headers, URL encoding, and character sets.

http.putdata

Convenience method to return a putdata ParamCollection object.

http.querystring

Convenience method to create a query string ParamCollection object.

http.removeCookie

Removes the cookie named cookieName from the cookie jar.

http.removeGlobalTextValidator

Removes a global text assertion or verification test that was previously added using the http.addGlobalAssertText.

http.removeValidator

Removes a previously added validator.

http.setAcceptLanguage

Specifies the Accept-Language header that the browser should use when sending HTTP requests.

http.setUserAgent

Specifies the User-Agent header that the browser should use when sending HTTP requests.

http.solve

Parses a value from the document found by XPath and stores it as a variable.

http.solveCookieHeader

Extracts the "Set-Cookie" header value which matches the cookie key from the last response header and stores it in the specified script variable.

http.solveGroupJavaScript

Extracts a JavaScript string from a document by XPath using a String and stores it in the script's variables collection.

http.solveHeader

Extracts the specified header value using from the last request's response header acccording to header name.

http.solveRedirectNavs

Parses a value from the re-directed navigation's contents and stores it as a variable.

http.solveRefererHeader

Extracts the "Referer" header value using from the last request's response header using XPath notation.

http.solveXPath

Extracts a value from the specified document contents using XPath notation.

http.text

Convenience method to return a ParamCollection object.

http.urlEncode

URL-encodes a given string using a specific character set excludng the specified character array.

http.validate

Validates the browser result for correctness.

http.verifyResponseTime

Tests the server response time for the previous request without failing.

http.verifyText

Searches the HTML contents in the document specified by XPath notation for the specified text pattern.

http.verifyTitle

Searches the <title> tag in HTML content for the specified title pattern, reporting a warning if the test fails.

http.verifyXPath

Verify the text of a DOM element in the browser's last retrieved contents.

http.window

Finds the window element from browser's DOM tree using the window index.

http.xmlPost

Posts an XML string to a web server using the HTTP POST method.


The following sections provide detailed reference information for each method and enum in the HTTPService Class of HTTP Load Module Application Programming Interface.

http.addAuthentication

Add a username and password to use when authenticating a URL that requires NTLM or Basic authentication.

When the browser requests a URL that returns a 401 or 407 "Unauthorized" HTTP response code, the browser will authenticate using a username and password in its authentication list whose corresponding URL matches the unauthorized URL. All querystring parameters in the URL are ignored. The protocol of the URL is also ignored. The URL is case-sensitive.

If multiple authentication entries are added for similar looking URLs, the URL that matches the most successive characters will be chosen. The order in which authentication entries are added to the list and searched is arbitrary.

Format

The http.addAuthentication method has the following command format(s):

http.addAuthentication(url, username, password);

http.addAuthentication(url, username, password, bNTLMv2);

Command Parameters

url

a String specifying the URL for this authentication information. May contain {{ }} syntax for transforming.

username

a String specifying the username. May contain {{ }} syntax for transforming. Must not be null. For NTLM-based authentication, username may be preceded by a domain and a single backslash. For example, in Java code, type: oracle\\user1. Note that two backslashes are typed because Java requires a backslash to be escaped with a backslash.

password

a String specifying the password. May contain {{ }} syntax for transforming. Must not be null.

bNTLMv2

a Booelan specifying if NTLM v2 is used.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Sets username and encrypted password authentication for myServer.com. See also the decrypt and encrypt methods in the Basic module API.

http.addAuthentication("http://myServer.com", "myUsername", 
 decrypt("38eHEwYhPOOG9ljr70eF6A=="), true);

http.addCookie

Adds a cookie to the cookie jar. The browser will submit this cookie in subsequent HTTP requests.

This method is identical to http.getBrowser().getCookieJar().addCookie(String, String).

This method URL-encodes the value specified in the cookie string using the specified character set. If no URL-encoding is desired, specify a null character set.

The cookieString is formatted like a Set-Cookie header as if it were sent by the server. The name, value, and other optional attributes are extracted from cookieString and set into the Cookie object.

If an empty or null domain is specified in cookieString, this cookie will apply to all domains.

If no path is specified in cookieString then this cookie will apply to all paths.

If a cookie with the specified name/domain/path (case-sensitive) does not yet exist, then it will be added.

If a cookie with the specified name/domain/path (case-sensitive) exists and its value and attributes are also the same, this method does nothing.

If a cookie with the specified name/domain/path (case-sensitive) exists but its value or attributes differ, then the new cookie will replace the old one.

Format

The http.addCookie method has the following command format(s):

http.addCookie(cookieString, charset);

Command Parameters

cookieString

a String specifying the Response cookie header. May contain {{ }} syntax for transforming. Must not be null. The "Set-Cookie:" portion of the header is optional, and so are any additional attributes.

Example 1: Set-Cookie: cookieFavoriteColor=Blue; path=/; expires=Thursday, 11-Dec-2008 11:15:00 GMT; domain=www.oracle.com

Example 2: client_user=user123

charset

a String specifying the Character set to use when URL-encoding the value part of the cookie. May contain {{ }} syntax for transforming. May be null. If null, this method will not URL-encode the value.

Throws

UnsupportedEncodingException

if charset is not a supported character encoding.

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Adds a custom cookie to the cookie jar using the specified character set.

http.addCookie("JSESSIONID=JLCTLkmMxvqfL6J7h", "ASCII");

http.addGlobalAssertText

Registers a text assertion test to run every time a page is requested.

The text assertion test searches the HTML contents of all documents in all browser windows for the specified text pattern.

If the test fails, the script will always fail and stop running, unless the text matching test error recovery setting specifies a different action such as Warn or Ignore.

The assertion is performed for all requests made by this Virtual User, including requests made inside concurrent sections. The assertion is not performed for resources requested by the Download Manager.

This method supports result code verification methods including getLastResult() and getLastError().

To unregister a global text assertion, use http.removeGlobalTextValidator.

Format

The http.addGlobalAssertText method has the following command format(s):

http.addGlobalAssertText(testName, textToAssert, sourceType, textPresence, matchOption);

Command Parameters

testName

a String specifying a descriptive name of the test being applied. This name may be used by a subsequent call to the http.removeGlobalTextValidator. Must not be null.

textToAssert

a String specifying th e text to match on the page, or not match on the page if TextPresence is set to TextPresence.PassIfPresent. Must not be null.

sourceType

a Source enum specifying where to match the text: the HTML contents or HTTP response headers. Must not be null.

textPresence

a TextPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the text to be present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

Example

Adds a Global Text Matching test for Display Content, Response Header, and Source HTML respectively.

globalTextMatchingTest1 passes if the text to match string is present in the Display Content and matches exactly.

globalTextMatchingTest2 passes if the text to match string is present in the Response header and matches the Regular Expression.

globalTextMatchingTest3 fails if the text to match string is present in the Source HTML and matches the Wildcard.

http.addGlobalAssertText("globalTextMatchingTest1", 
 "match this text string", Source.DisplayContent, 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.addGlobalAssertText("globalTextMatchingTest2", 
 "jsessionid=(.+?)(?:\\\"|&)", Source.ResponseHeader, 
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.addGlobalAssertText("globalTextMatchingTest3", 
 "match this *", Source.Html, 
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.addGlobalVerifyText

Registers a text verification test to run every time a page is requested.

The text verification test searches the HTML contents of all documents in all browser windows for the specified text pattern.

If the test fails, a warning is always reported, irrespective of current Error Recovery settings.

The verification is performed for all requests made by this Virtual User, including requests made inside concurrent sections. The verification is not performed for resources requested by the Download Manager.

This method supports result code verification methods including getLastResult() and getLastError().

To unregister a global text verification, use http.removeGlobalTextValidator.

Format

The http.addGlobalVerifyText method has the following command format(s):

http.addGlobalVerifyText(testName, textToAssert, sourceType, textPresence, matchOption);

Command Parameters

testName

a String specifying a descriptive name of the test being applied. This name may be used by a subsequent call to http.removeGlobalTextValidator. Must not be null.

textToAssert

A String specifying the text to match on the page, or not match on the page if TextPresence is set to TextPresence.PassIfPresent. Must not be null.

sourceType

a Source enum specifying where to match the text: the HTML contents or HTTP response headers. Must not be null.

textPresence

a TextPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the text to be present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

Example

Adds a Global Text Matching test for Display Content, Response Header, and Source HTML respectively.

globalTextMatchingTest1 passes if the text to match string is present in the Display Content and matches exactly.

globalTextMatchingTest2 passes if the text to match string is present in the Response header and matches the Regular Expression.

globalTextMatchingTest3 fails if the text to match string is present in the Source HTML and matches the Wildcard.

http.addGlobalVerifyText("globalTextMatchingTest1", 
 "match this text string", Source.DisplayContent, 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.addGlobalVerifyText("globalTextMatchingTest2", 
 "jsessionid=(.+?)(?:\\\"|&)", Source.ResponseHeader, 
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.addGlobalVerifyText("globalTextMatchingTest3", 
 "match this *", Source.Html, 
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.addValidator

Adds a class to provide custom validation for all browser responses.

Custom IValidator instances are invoked after HTTPService performs its own validation.

Format

The http.addValidator method has the following command format(s):

http.addValidator(validator);

Command Parameters

validator

a Custom validator object.

Example

Adds a custom validator to test a response.

import oracle.oats.scripting.modules.basic.api.exceptions
   .AbstractScriptException;
public class script extends IteratingVUserScript {
 @ScriptService oracle.oats.scripting.modules.utilities.api.
   UtilitiesService utilities;
 @ScriptService oracle.oats.scripting.modules.http.api.HTTPService http;
 public void initialize() throws Exception {
 }
 public void run() throws Exception {
 //define databanks and variables
 getDatabank("navigation_info").getNextDatabankRecord();
 String link = eval("{{navigation_info.link}}");
 LinkValidator linkValidator = null;
 //[script navigation code...]
 //add a validator
 http.addValidator(linkValidator = new LinkValidator(link));
 //[additional script navigation code...]
 }
 public void finish() throws Exception {
 }
//define class for custom validator action
 class LinkValidator implements IValidator {
  @ScriptService oracle.oats.scripting.modules.utilities
    .api.UtilitiesService utilities;
  @ScriptService oracle.oats.scripting.modules.http.api.HTTPService http;
 private String link;
 public LinkValidator(String link) {
   this.link = link;
  }
  public void validate(Response response) {
   String contents = response.getContents();
   if (!contents.contains(link))
    try {
     info("Not found link '" + link + "'"); 
    } catch (AbstractScriptException e) {
     e.printStackTrace();
    }
   else
    try {
     info("Found link '" + link + "'"); 
    } catch (AbstractScriptException e) {
     e.printStackTrace();
    }
   }
  }
}

http.assertResponseTime

Tests the server response time for the previous request.

This method does nothing if the Response already has an exception set.

If the test fails, always fail the script unless the server response test error recovery setting specifies a different action such as Warn or Ignore.

Subclasses may override this method if they need to modify how the HTTP Service itself validates server response times.

Format

The http.assertResponseTime method has the following command format(s):

http.assertResponseTime(testName, minTime, maxTime);

Command Parameters

testName

a String specifying a descriptive name describing what request is being tested. The name may appear in results and counter names.

minTime

a double specifying the minimum server response time (inclusive).

maxTime

a double specifying maximum server response time (inclusive).

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

ResponseTimeException

if no previous response to validate, or if the response time does not fall within the given range and stopIterationOnFailure is true.

Example

Adds Server Response test with a minimum of 1 second and a maximum of 15 seconds.

http.assertResponseTime("myServerResponseTest", 1.0, 15.0);

http.assertText

Searches the HTML contents of the specified document XPath for the specified text pattern.

If the test fails, always fail the script unless the text matching test error recovery setting specifies a different action such as Warn or Ignore.

Format

The http.assertText method has the following command format(s):

http.assertText(testName, textToAssert, sourceType, textPresence, matchOption);

http.assertText(testName, documentXPath, textToAssert, sourceType, textPresence, matchOption);

Command Parameters

testName

a String specifying the test name.

textToAssert

a String specifying the text to match on the page, or not match on the page if TextPresence is set to TextPresence.PassIfPresent.

sourceType

a Source enum specifying where to match the text: the HTML contents or HTTP response headers.

textPresence

a TestPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the test to pass or fail if the text to match is present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

documentXPath

a String specifying the XPath to the document that contains the contents.

Throws

MatchException

if the assertion fails. AbstractScriptException on any other failure when attempting to assert the text.

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Exception

if the assertion fails.

Example

Adds Text Matching tests in the specified document for Display Content, Response Header and Source HTML respectively.

myTextMatchingTest1 passes if the text to match string is present in the Display Content and matches exactly.

myTextMatchingTest2 passes if the text to match string is present in the Response header and matches the Regular Expression.

myTextMatchingTest3 fails if the text to match string is present in the Source HTML and matches the Wildcard.

http.assertText("myTextMatchingTest1", "window[@index='0']", 
 "match this text string", Source.DisplayContent, 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.assertText("myTextMatchingTest2", "window[@index='0']", 
 "jsessionid=(.+?)(?:\\\"|&)", Source.ResponseHeader, 
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.assertText("myTextMatchingTest3", "window[@index='0']",
 "match this *", Source.Html, 
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.assertTitle

Searches the <title> tag in the HTML content for the specified title pattern, reporting a failure if the test fails.

If the test fails, always fail the script unless the text matching test error recovery setting specifies a different action such as Warn or Ignore.

Format

The http.assertTitle method has the following command format(s):

http.assertTitle(title, matchOption);

http.assertTitle(documentXPath, title, matchOption);

Command Parameters

title

a String specifying the text pattern specifying the expected title.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

documentXPath

a String specifying the XPath to the document that contains the contents.

Throws

Exception

on any exception while navigating or transforming the data.

MatchException

if the assertion fails.

AbstractScriptException

on any other failure when attempting to assert the text.

Example

Adds a Verify only, never fail Text Title tests for the HTML document title using exact match, Regular Expression match, and Wildcard match respectively.

http.assertTitle("window[@index='0']", "Summary Report", MatchOption.Exact);
http.assertTitle("window[@index='0']", "Summary Report For (.+?)", MatchOption.RegEx);
http.assertTitle("window[@index='0']", "Summary Report For ???", MatchOption.Wildcard);

http.assertXPath

Extracts a value from the browser's last retrieved contents using XPath notation. Compare this value to the textToVerify parameter.

If the test fails, always fail the script unless the text matching test error recovery setting specifies a different action such as Warn or Ignore.

When playing back a script in Oracle Load Testing, always use Assertions; failed Verifications are not reported in the Oracle Load Test controller.

Format

The http.assertXPath method has the following command format(s):

http.assertXPath(testName, xpath, resultIndex, textToVerify, textPresence, matchOption);

Command Parameters

testName

a String specifying the test name.

xpath

a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null.

resultIndex

a 0-based index value specifying the specific result to retrieve if the XPath returns multiple results. A null value specifies that all results should be returned.

textToVerify

a String specifying the Text to match, or not match with the XPath result if TextPresence is set to TextPresence.PassIfPresent.

textPresence

a TestPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the test to pass or fail if the text to match is present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

Throws

AbstractScriptException

on any failure when attempting to verify the text.

Example

Adds Text Matching tests using XPath notation.

myTextMatchingTest1 passes if the text to match string is present and matches exactly.

myTextMatchingTest2 passes if the text to match string is present and matches the entire string exactly.

myTextMatchingTest3 passes if the text to match string is present and matches the Regular Expression.

myTextMatchingTest4 passes if the text to match string is present and matches the entire string from the Regular Expression.

myTextMatchingTest5 fails if the text to match string is present and matches the Wildcard.

http.assertXPath("myTextMatchingTest1", ".//input[@name='j_id_id3']" +
 "/@value", 0, "match this text string", 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.assertXPath("myTextMatchingTest2", ".//input[@name='j_id_id3']" +
 "/@value", 1, "match this text string", 
 TextPresence.PassIfPresent, MatchOption.ExactEntireString);
http.assertXPath("myTextMatchingTest3", ".//input[@name='j_id_id3']" +
 "/@value", 0, "jsessionid=(.+?)(?:\\\"|&)",
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.assertXPath("myTextMatchingTest4", ".//input[@name='j_id_id3']" +
 "/@value", 1, "jsessionid=(.+?)(?:\\\"|&)",
 TextPresence.PassIfPresent, MatchOption.RegExEntireString);
http.assertXPath("myTextMatchingTest5", ".//input[@name='j_id_id3']" +
 "/@value", 0, "match this *",
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.beginConcurrent

Begins a concurrent section used to make multiple HTTP requests at the same time by the same Virtual User using a different HTTP connection.

The maximum number of concurrent requests allowed by one Virtual User at any time is determined by the Maximum Connections playback setting.

When inside a concurrent section, the script will not wait for the completion of any HTTP requests that are started. Use http.endConcurrent to end a concurrent section and wait for all concurrent HTTP requests in the given section to finish.

While inside a concurrent section, responses for individual requests cannot be determined. For example, calling http.getLastBrowserResponse will throw a {@link oracle.oats.scripting.modules.http.api.exceptions.ConcurrentException}

Invoking this method more than once on the same concurrentSectionId is harmless and does not begin a new concurrent section with the existing ID.

Notes: The API getLastResult and the "result" variables will not work reliably inside HTTP script beginConcurrent/endConcurrent sections.

Accessing a databank directly within concurrent blocks is not supported. You can read the databank value outside of the concurrent block and save it to a local variable. You can then use the variable inside concurrent block. For example:

getVariables().set("url", "{{db.fmstocks.url}}"); 
[....]
// replace all requests inside the concurrent block with the variable, as follows:
http.get(23, "http://{{url}}/fmstocks/", null, null, true, "ASCII", "ASCII");

Format

The http.beginConcurrent method has the following command format(s):

http.beginConcurrent(concurrentSectionId);

Command Parameters

concurrentSectionId

a user-defined String specifying a unique identifier for the concurrent section. Multiple concurrent sections may be started and stopped independently of each other by providing a different name. Must not be null.

Throws

Exception

on any failure.

Example

Begins a concurrent section with the ID mySessionID_0001.

http.beginConcurrent("mySessionID_0001");

http.clearCookies

Clears the Cookies during playback.

Format

The http.clearCookies method has the following command format(s):

http.clearCookies( );

Example

Clears the browser Cookies added within the run section of a given script.

Cookies added to the browser in the initialize section will be preserved forever unless the playback setting "Preserve Cookies between Iterations" is set to false.

http.clearCookies();

http.delete

Requests a web page using an HTTP DELETE method with querystrings, deletedata, headers, URL encoding, and character sets.

Format

The http.delete method has the following command format(s):

http.delete(recid,urlPath,querystring, deletedata);

http.delete(recid,urlPath,querystring, deletedata, headers,encode);

http.delete(recid,urlPath,querystring, deletedata, headers,encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

querystring

a ParamCollection specifying the Query string data parameter collection. May be null.

deletedata

a ParamCollection specifying the Data to DELETE to the URL's host, in the form of a parameter collection or a String specifying the delete data. Must not be null.

headers

a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception on any exception while navigating or transforming the data.

Example

Specifies a DELETE navigation with querystrings, deletedata, headers, URL encoding, and character sets.

http.delete(9, "http://myServer.com/{{web.formaction.loginform,default.asp}}",
 http.deletedata(http.param("login", "{{web.input.login,ta793}}"), 
  http.param("password", "{{web.input.password,ta}}"),
  http.param("LoginButton", "{{web.input.LoginButton,Login}}")));

-or-

http.delete(12, "http://myServer.com",
 http.querystring(http.param("QueryString1", "QueryValue1"),
  http.param("QueryString2", "QueryValue2"),
  http.param("QueryString3", "QueryValue3")),
 http.deletedata(http.param("DeleteString1", "DeleteValue1"),
  http.param("DeleteString2", "DeleteValue2"),
  http.param("DeleteString3", "DeleteValue3"),
 http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
    Header.HeaderAction.Add),  
  http.header("HeaderString2", "HeaderValue2SetifNotSet", 
    Header.HeaderAction.SetIfNotSet),
  http.header("HeaderString3", "HeaderValue3ApplytoAll",
    Header.HeaderAction.GlobalAdd), 
  http.header("HeaderString4", "HeaderValue4BothActions",
    Header.HeaderAction.GlobalSetIfNotSet)), 
 true, "ASCII", "ASCII"); 

See Also

http.querystring and http.deletedata for creating a parameter collection.

http.deletedata

Convenience method to return a deletedata ParamCollection.

Format

The http.deletedata method has the following command format(s):

http.deletedata(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a DELETE navigation with deletedata parameters.

http.delete(9, "http://myServer.com", http.deletedata(
 http.param("DeleteString1", "DeleteValue1"), 
 http.param("DeleteString2", "DeleteValue2"),
 http.param("DeleteString3", "DeleteValue3")));

See Also

http.get and http.delete Methods.

http.element

Finds the element from the browser's DOM tree using XPath notation.

The element instance will be returned.

Format

The http.element method has the following command format(s):

http.element(xpathToElement);

Command Parameters

xpathToElement

a String specifying the XPath of the element describing which value to parse from the DOM tree. Must not be null.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

the element's reference.

Example

Finds the form element with ID 'frmTest' from the browser's DOM tree.

boolean element_xpath_exists = http.element("window[@index='0']" +
 "/frame[@name='right']//form[@id='frmTest' " +
 "and @name='frmTest']")
 .exists();
if(element_xpath_exists){
 info("WebHTTPElement exists");
}
else{
 warn("WebHTTPElement does not exist");
}

EncodeOptions

The EncodeOptions has the following values:

Table 9-3 List of EncodeOptions Values

Value Description

None

Leaves the input string alone; do not apply any additional encoding/decoding transformations.

URLEncode

URL-encodes a string. For example, the string abc/xyz becomes abc%2Fxyz.

URLDecode

URL-decodes a string. For example, the string abc%2Fxyz becomes abc/def.

XMLEncode

Encodes any characters that should be escaped for XML serialization. For example, the string abc<xyz becomes abc&lt;xyz.

XMLDecode

Decodes any characters that were escaped for XML serialization. For example, the string abc&lt;xyz becomes abc<xyz.

RemoveNewlines

Strips all newlines.

ConvertNewlinesToCRLF

Replaces \0A (not followed by \0D) with \0D\0A.

ConvertNewlinesToLF

Replaces \0D\0A with \0A.

EncodeURIComponent

Encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #


http.endConcurrent

Ends the specified concurrent section waiting the specified amount of time for requests to finish.

It waits the specified maximum amount of time for all pending HTTP requests in the specified concurrent section to finish.

Format

The http.endConcurrent method has the following command format(s):

http.endConcurrent(concurrentSectionId);

http.endConcurrent(concurrentSectionId, timeoutSeconds);

Command Parameters

concurrentSectionId

a String specifying the ID of the concurrent section that was already started using http.beginConcurrent. If null, this method will stop the most recently started concurrent section.

timeoutSeconds

a long specifying the maximum number of seconds allocated to wait for the concurrent section to finish. Specify Long.MAX_VALUE to wait forever. This method will return immediately after the requests finish, even if the timeout has not been reached.

Throws

Exception

on any exception that occurs when executing the concurrent requests.

ConcurrentException

if a timeout occurs while waiting for the concurrent requests to finish.

InterruptedException

if the thread is interrupted while waiting for the concurrent requests to finish.

Example

Ends a concurrent section previously started with the ID mySessionID_0001. It waits up to 15 seconds for all pending HTTP requests in the specified concurrent section to finish.

http.endConcurrent("mySessionID_0001", 15);

http.form

Finds the form element from the browser's DOM tree using XPath notation.

The element instance will be returned.

Format

The http.form method has the following command format(s):

http.form(recId, xpathToForm);

Command Parameters

recId

the ID of a previously recorded navigation, used for comparison purposes. May be null.

xpathToForm

a String specifying the XPath of the form element describing which value to parse from the DOM tree. Must not be null.

Throws

AbstractScriptException

on any exception while transforming xpathToForm.

Returns

The form element's reference.

Example

Gets the form named 'mainForm' under the first window.

boolean form_exists = http.form(142, "window[@index='0']" +
 "//form[@action='{{web.link.research," +
 "http://myServer.com/Ticker.asp}}']")
 .exists();
String form_exists_str = String.valueOf(form_exists);
if(form_exists){
 info("WebHTTPForm exists: + form_exists_str");
}
else{
 warn("WebHTTPForm exists: + form_exists_str");
}

http.frame

Finds the frame element from the browser's DOM tree using XPath notation.

The element instance will be returned.

Format

The http.frame method has the following command format(s):

http.frame(recId, xpathToFrame);

Command Parameters

recId

the ID of a previously recorded navigation, used for comparison purposes. May be null.

xpathToFrame

a String specifying the XPath of the frame element describing which value to parse from the DOM tree. Must not be null.

Throws

AbstractScriptException

on any exception while transforming xpathToFrame.

Returns

The frame element's reference.

Example

Gets the frame named 'right' under the first window.

http.frame(192, "window[@index='0']" +
 "/frame[@name='right']")
 .get("http://myServer.com/FramenumSet.htm",
 null, null, true, "ASCII", "ASCII");

http.get

Requests a web page using an HTTP GET method.

Format

The http.get method has the following command format(s):

http.get(recid, urlPath);

http.get(recid, urlPath, querystring);

http.get(recid, urlPath, querystring, encode);

http.get(recid, urlPath, querystring, headers, encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

querystring

an Object specifying the Query string data, either as a String or ParamCollection. May be null.

headers

a headers array specifying additional headers to add/remove from the request before submitting it to the server.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any exception while navigating or transforming the data.

Example

Requests the specified web pages using an HTTP GET method. Expanded examples add a query string parameter myQueryString and header actions.

http.get(30[...] requests the specified web page without parameters, headers, or URL-encoding.

http.get(31[...] requests the specified web page without URL-encoded parameters and will always add the header using ASCII character sets for the request and response headers.

http.get(32[...] requests the specified web page with URL-encoded parameters and will always add the header using ASCII character sets for the request and response headers.

http.get(33[...] requests the specified web page with URL-encoded parameters and will add the header only if it is not set using UTF-8 character sets for the request and response headers.

http.get(34[...] requests the specified web page with URL-encoded parameters and will add the header only if it is not set and add it to all navigations after using OracleBinary character sets for the request and response headers.

http.get(30, "http://myServer.com/", null, null, false, "ASCII", "ASCII");
http.get(31, "http://myServer.com/", http.querystring(
 http.param("myQueryString", "my String Value")),
 http.headers(http.header("myheaderName", "myHeaderValue", 
   Header.HeaderAction.Add)), false, "ASCII", "ASCII");
http.get(32, "http://myServer.com/", http.querystring(
 http.param("myQueryString", "my String Value")),
 http.headers(http.header("myheaderName", "myHeaderValue", 
   Header.HeaderAction.Add)), true, "ASCII", "ASCII");
http.get(33, "http://myServer.com/", http.querystring(
 http.param("myQueryString", "my String Value")),
 http.headers(http.header("myheaderName", "myHeaderValue", 
   Header.HeaderAction.SetIfNotSet)), true, "UTF-8", "UTF-8");
http.get(34, "http://myServer.com/", http.querystring(
 http.param("myQueryString", "my String Value")),
 http.headers(http.header("myheaderName", "myHeaderValue", 
   Header.HeaderAction.GlobalSetIfNotSet)), 
   true, "OracleBinary", "OracleBinary");

See Also

http.querystring for creating a parameter collection.

http.getBrowser

Gets a Thin browser for making HTTP requests.

Format

The http.getBrowser method has the following command format(s):

http.getBrowser( );

Returns

a Thin browser object for making HTTP requests.

Example

Gets a Thin browser object using an OpenScript script variable and a Java variable.

//using script variable
getVariables().set("browserId", http.getBrowser().getBrowserId());
info("The browser ID string using script var: {{browserId}}");
//using Java variable
ThinBrowser browser = http.getBrowser();
info("The browser ID is: " + browser.getBrowserId());

http.getHtmlContent

Gets the HTML content of a document which is specified by the XPath.

If the XPath refers to a window, the document is the document in the window. If the XPath refers to a frame, the document is the frame's content document. If the XPath refers to an element, the document is the owner document of the element.

Format

The http.getHtmlContent method has the following command format(s):

http.getHtmlContent(xpath);

Command Parameters

xpath

a String specifying the XPath to the window, document, frame, or element containing the HTML content.

Returns

the HTML content string.

Example

Gets the HTML contents of the document in the window with the index of 0.

//using Script variable
getVariables().set("htmlContents", 
 http.getHtmlContent("/window[@index=0]"));
info("HTML Contents Type in script var = {{htmlContents}}" );
//using Java variable
String htmlContents = http.getHtmlContent("/window[@index=0]");
info("HTML Contents = " + htmlContents);

http.getLastBrowserResponse

Gets the last retrieved response from this Virtual User's browser.

The result of this method is unpredictable if more than one navigation occurs at the same time for the same Virtual User. For example, when running multiple concurrent requests using http.beginConcurrent, the last response contents are indeterminate.

Regardless of how many threads are being run, this method will only ever return a response for the current Virtual User that owns this HTTP service instance. This method will never return a response from a different running Virtual User.

Format

The http.getLastBrowserResponse method has the following command format(s):

http.getLastBrowserResponse( );

Returns

this Virtual User's browser's last retrieved response. May be null.

Example

Gets the last retrieved response from this Virtual User's browser.

//using script variable
getVariables().set("contentType", 
 http.getLastBrowserResponse().getContentType());
info("Content Type in script var = {{contentType}}" );
//using Java variable
String contentType = http.getLastBrowserResponse().getContentType();
info("Content Type = " + contentType);

http.getLastResponseContents

Returns a String version of a given browser response from the specified source type.

Format

The http.getLastResponseContents method has the following command format(s):

http.getLastResponseContents( );

http.getLastResponseContents(sourceType);

http.getLastResponseContents(lastBrowserResponse, sourceType);

Command Parameters

sourceType

the Source enum specifying which contents to return as a String. If null, assumes Source.Html.

lastBrowserResponse

a Response object from which to return the last browser contents.

Returns

String version of the given browser response. Returns null when the last browser response is null.

Example

Get the contents of the Response Header, Display HTML and source HTML last retrieved by the browser for this Virtual User.

//using script variable
getVariables().set("lastRespHeader", 
 http.getLastResponseContents(http.getLastBrowserResponse(),
 Source.ResponseHeader));
info("Last Response Header in script var = {{lastRespHeader}}");
//using Java variable
String lastRespHeader = http.getLastResponseContents(
 http.getLastBrowserResponse(), Source.ResponseHeader);
info("Last Response Header = " + lastRespHeader);
//using script variable
getVariables().set("lastDisplayConts", http.getLastResponseContents(
 http.getLastBrowserResponse(), Source.DisplayContent));
info("Last Display Contents in script var = {{lastDisplayConts}}");
//using Java variable
String lastDisplayConts = http.getLastResponseContents(
 http.getLastBrowserResponse(), Source.DisplayContent);
info("Last Display Contents = " + lastDisplayConts);
//using script variable
getVariables().set("lastHtml", http.getLastResponseContents(
 http.getLastBrowserResponse(), Source.Html));
info("Last HTML Contents in script var = {{lastHtml}}");
//using Java variable
String lastHtml = http.getLastResponseContents(
 http.getLastBrowserResponse(), Source.Html);
info("Last HTML Contents = " + lastHtml);

http.getResponseHeaders

Gets the headers of a response and its ancestors that is received by a window specified by the XPath.

If the XPath refers to a frame, the window is the frame's window. If the XPath refers to an element, the window is the window of the element's owner document.

Format

The http.getResponseHeaders method has the following command format(s):

http.getResponseHeaders(xpath);

Command Parameters

xpath

a String specifying the XPath to the window, frame, or element containing the response headers.

Returns

the response headers String.

Example

Gets the HTML contents of the document in the window with the index of 0.

//using Script variable
getVariables().set("respHeader", 
 http.getResponseHeaders("/window[@index=0]"));
info("Response Headers in script var = {{respHeader}}" );
//using Java variable
String respHeader = http.getResponseHeaders("/window[@index=0]");
info("Response Headers = " + respHeader);

http.getSettings

Gets the settings for the HTTP service.

Format

The http.getSettings method has the following command format(s):

http.getSettings( );

Returns

all settings pertaining to the HTTP Service.

Example

Gets the settings for the HTTP service.

import java.util.List;
import oracle.oats.scripting.modules.http.api.Settings;
//[...]
info("Callling http.getSettings()...");
Settings settings = http.getSettings();
info("Connection Timeout: " + settings.getConnectTimeout());
info("Proxy Host: " + settings.getProxyHost());
info("Proxy Password: " + settings.getProxyPassword());
info("Proxy Port: " + settings.getProxyPort());
info("Proxy User Name: " + settings.getProxyUsername());
info("Socket Timeout: " + settings.getSocketTimeout());
info("Speed Emulation (Bytes/sec): " + 
   settings.getSpeedEmulationBytesPerSecond());
info("User Agent: " + settings.getUserAgent());
info("Cache Setting: " + settings.getCacheSetting());
info("Global Headers: " + settings.getGlobalHeaders());
List <String> resources = http.getSettings().getIgnoredResources();
if (resources != null) {
 for (int i=0; i<resources.size(); i++)
   info("IgnoredResources: " + resources.get(i));
 }
else info("IgnoredResources is null");
List <String> urls = http.getSettings().getIgnoredUrls();
if (urls != null) {
 for (int i=0; i<urls.size(); i++)
   info("IgnoredUrl: " + urls.get(i));
 }
else info("IgnoredUrl is null");
info("Preserve Connections: " + settings.getPreserveConnections());
info("Preserve Cookies: " + settings.getPreserveCookies());
info("Preserve Variables: " + settings.getPreserveVariables());
info("Proxy Enabled: " + settings.getProxyEnabled());
info("Use Cache: " + settings.getUseCache());

http.getValidatorList

Returns all the validators added by addValidator.

Format

The http.getValidatorList method has the following command format(s):

http.getValidatorList( );

Returns

an ArrayList copy of the validators or null when the validator list is empty.

Example

Gets an ArrayList copy of the validators and writes the simple name for each validator to the results.

import java.util.List;
//[...]
List<IValidator> list = http.getValidatorList();
  for (int i = 0; i < list.size(); i++) {
   IValidator validator = list.get(i);
   info("Validator Name: " + validator.getClass()
      .getSimpleName());
   if (validator.getClass().getSimpleName()
      .equals("LinkValidator")) {
    info("Removing LinkValidator");
   http.removeValidator(validator);
   } else if 
    (validator.getClass().getSimpleName()
      .equals("CategoryValidator")) {
    info("Removing CategoryValidator");
   http.removeValidator(validator);
   } else
    info("Other validator: " 
      + validator.getClass().getSimpleName());
  }

http.header

Convenience method for creating a new Header object.

Format

The http.header method has the following command format(s):

http.header(name, value, action);

Command Parameters

name

a String specifying the header name. May contain {{ }} syntax for transforming. Must not be null.

value

a String specifying the header value. May contain {{ }} syntax for transforming. Must not be null.

action

a HeaderAction object, such as remove or add the header.

Throws

AbstractScriptException

on any exception while transforming the name and value.

Returns

a new Header object, with the name and value transformed.

Example

Creates new headers using the specified header names, values, and actions.

http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
   Header.HeaderAction.Add), 
 http.header("HeaderString2", "HeaderValue2IfNotSet", 
   Header.HeaderAction.SetIfNotSet), 
 http.header("HeaderString3", "HeaderValue3ApplytoAll", 
   Header.HeaderAction.GlobalAdd), 
 http.header("HeaderString4", "HeaderValue4Both", 
   Header.HeaderAction.GlobalSetIfNotSet));

See Also

http.get and http.post Methods.

http.headers

Convenience method to create a new Header array.

Format

The http.headers method has the following command format(s):

http.headers(headers);

Command Parameters

headers

one or more Header objects.

Returns

a new Header array.

Example

Creates a new header collection using the specified header names, values, and actions.

http.headers(http.header("HeaderString1", "HeaderValue1NoActions",
   Header.HeaderAction.Add), 
 http.header("HeaderString2", "HeaderValue2IfNotSet", 
   Header.HeaderAction.SetIfNotSet), 
 http.header("HeaderString3", "HeaderValue3ApplytoAll", 
   Header.HeaderAction.GlobalAdd), 
 http.header("HeaderString4", "HeaderValue4Both", 
   Header.HeaderAction.GlobalSetIfNotSet));

See Also

http.get and http.post Methods.

http.httpdata

Convenience method to return a httpdata ParamCollection.

Format

The http.httpdata method has the following command format(s):

http.httpdata(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a navigation with httpdata parameters..

http.put(9, "http://myServer.com", http.httpdata(
 http.param("HttpString1", "HttpValue1"), 
 http.param("HttpString2", "HttpValue2"),
 http.param("HttpString3", "HttpValue3")));

See Also

http.delete and http.put Methods.

http.javaScriptPath

Builds the JavaScript path(s) to use to extract JavaScript strings using http.solveGroupJavaScript.

Format

The http.javaScriptPath method has the following command format(s):

http.javaScriptPath(name, scriptLanguage, scriptIndex, literalIndex, literalType);

Command Parameters

name

a String specifying the variable name to use.

scriptLanguage

an Integer specifying the the script language. 1 to parse JavaScript, 0 to parse VB Script.

scriptIndex

an Integer specifying the 0-based index of the script block in the HTML contents to parse.

literalIndex

an Integer specifying the 0-based index of the dynamic JavaScript literal inside the block to extract.

literalType

an Integer specifying the data type. Specify '0' to parse a String from JavaScript, or '1' to parse a number.

Returns

the javascript path.

Example

Extracts a JavaScript String from the page and stores it in the variable "varJavaScript" in the script's variables collection. It parses the first script block in the HTML contents for the third the dynamic JavaScript literal as a String from JavaScript.

http.solveGroupJavaScript("window[@index='1']", http.javaScriptPath("varJavaScript", 1, 1, 2, 0));
info("Java Script = {{varJavaScript}}");

http.link

Finds the link element from the browser's DOM tree using XPath notation.

The element instance will be returned.

Format

The http.link method has the following command format(s):

http.link(recId, xpathToLink);

Command Parameters

recId

the ID of a previously recorded navigation, used for comparison purposes. May be null.

xpathToLink

a String specifying the XPath of the link element describing which value to parse from the DOM tree. Must not be null.

Throws

AbstractScriptException

on any exception while transforming xpathToLink.

Returns

the link element's reference.

Example

Clicks the link with the text 'research a company' under the first window.

http.link(130, "window[@index='0']//a[@text='research a company']")
 .click();

http.loadKeystore

Loads the keystore file using the specified password.

Allows the current virtual user to use a client-side certificate when connecting to any secure website.

Specify a path to a Java keystore file containing the certificate that the Virtual User should use for as long as it is running. The Virtual User will only ever use one keystore at a time when creating secure connections.

Calling this method more than once for the same Virtual User will cause subsequent secure connections to use the most recently loaded keystore.

To stop using a keystore for new connections, call this method with a null or empty value for the keystoreFilePath.

Format

The http.loadKeystore method has the following command format(s):

http.loadKeystore(keystoreFilePath, keystorePassword);

Command Parameters

keystoreFilePath

a String specifying the Absolute path to a certificate keystore file on the machine where the script will be played back. The keystore file should be generated using Java's keytool.exe program. If the path is null, an empty string, or the file does not exist, no keystore will be used.

keystorePassword

a String specifying the password used to read certificates from the keystore.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

KeystoreLoadException

if the keystore cannot be loaded for any reason.

Example

Loads the keystore file using the specified password.

http.loadKeystore("C:\\keys\\DummyClientKeyFile.jks", "WebAS");

http.multipartPost

Requests a web page using a multipart HTTP POST method with querystring, postdata, headers, boundary, URL-encoding, and character sets.

This method formats the post data using a multi-part format.

Format

The http.multipartPost method has the following command format(s):

http.multipartPost(recid, urlPath, postdata);

http.multipartPost(recid, urlPath, querystring, postdata, headers, boundary);

http.multipartPost(recid, urlPath, querystring, postdata, headers, reqCharset, respCharset);

http.multipartPost(recid, urlPath, querystring, postdata, headers, boundary, encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying ther URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

postdata

a ParamCollection of the postdata to POST to the URL's host. Must not be null.

querystring

a ParamCollection of query string data parameters. May be null.

headers

a Header array of additional headers to add/remove from the request before submitting it to the server.

boundary

a String specifying the Multi-part post boundary string as it would appear in the header of the multi-part post.

For example, if the header is:

Content-Type: multipart/form-data; boundary=---------------------------7d82f120260a68

Specify boundary as:

---------------------------7d82f120260a68

Note that the boundary string submitted in the body of the multi-part post contains two additional "-" characters.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

Throws

Exception

on any exception while navigating or transforming the data.

Example

Requests a web page using a multipart HTTP POST method. This method formats the post data using a multipart format with query strings, postdata, headers, Boundary, URL-encoding, and character sets.

http.multipartPost(15, "http://myServer.com", 
 http.querystring(http.param("QueryString1", "QueryValue1"), 
   http.param("QueryString2", "QueryValue2"), 
   http.param("QueryString3", "QueryValue3")), 
 http.postdata(http.param("PostDataString1", "PostDataValue1Standard"),
   http.param("PostDataString2", "PostDataValue2FilePath", 
     "PostDataValue2FileName", "ASCII"), 
   http.param("PostDataString3", "C:\\OracleATS\\OFT\\DataBank\\mydata.csv", 
     "C:\\OracleATS\\OFT\\DataBank\\mydata.csv", "CSV")),
 http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
     Header.HeaderAction.Add), 
   http.header("HeaderString2", "HeaderValue2IfNotSet", 
     Header.HeaderAction.SetIfNotSet), 
   http.header("HeaderString3", "HeaderValue3ApplytoAll", 
     Header.HeaderAction.GlobalAdd), 
   http.header("HeaderString4", "HeaderValue4Both", 
     Header.HeaderAction.GlobalSetIfNotSet)), 
 "---------------------------7d82f120260a68", 
 true, "ASCII", "ASCII");

See Also

http.querystring and http.postdata for creating parameter collections.

http.navigate

Navigates to a web page using the specified ID, URL, additional headers, redirect, character set, method, and input stream. Only Multipart Post and XmlPost would call this method.

Format

The http.navigate method has the following command format(s):

http.navigate(id, url);

http.navigate(id, url, method);

http.navigate(url, postdata, method);

http.navigate(url, postdata, followRedirects, method);

http.navigate(id, url, postdata, followRedirects, method);

http.navigate(id, url, postdata, additionalHeaders, followRedirects, method);

http.navigate(id, url, postdata, additionalHeaders, followRedirects, method);

http.navigate(id, url, postdata, additionalHeaders, followRedirects, respCharset, method);

http.navigate(id, url, postdata, additionalHeaders, followRedirects, respCharset, method);

http.navigate(id, url, additionalHeaders, followRedirects, respCharset, method, postStream);

Command Parameters

id

the ID of a previously recorded navigation, used for comparison purposes. May be null.

url

a String specifying the URL to request. Must not be null.

method

an HTTPMethod enum specifing the HTTP request header method: GET or POST.

postdata

a String specifying the Postdata to POST to the URL's host. May be null.

followRedirects

a boolean specifying if redirects are followed. Set to false to specify that the browser should not follow any redirects, such as a 302 response.

additionalHeaders

a Headers object specifying additional headers to add to the request.

respCharset

a String specifying the character set to use when reading the response contents.

postStream

an InputStream containing postdata to POST to URL. Should be OpenScriptInputStream.

Throws

Exception

on any exception while navigating.

Example

Navigates to the specified URL using the specified headers, character set, POST method, and poststream. Does not follow redirects.

String filePath = "C:\\ADF_Load.xml";
String fileName = "ADFLoad";
Headers myheaders = new Headers();
myheaders.add("POST / HTTP/1.1", "");
myheaders.add("Accept-Encoding", "gzip, deflate");
ParamCollection postdata =  http.postdata(
 http.param("__EVENTTARGET","btnUploadTheFile"),
 http.param("__EVENTARGUMENT",""),
 http.param("__VIEWSTATE","dDwxNDc5ODAzNTs7PkPGUbP9tEJUQkJkazuBM8/TR8"),
 http.param("uplTheFile",filePath,fileName,"text/xml"));
InputStream postStream = postdata == null ? null : 
 buildMultiPartPostStream(postdata.getParams(), 
 "---------------------------7da1482d461390", "UTF8");
http.navigate(11, "http://myServer.com/mockups/uploadfile.aspx", 
 myheaders, false, "UTF8", HTTPMethod.POST, postStream);
//[...]
protected InputStream buildMultiPartPostStream(Param params[], String boundary, String reqCharset) throws AbstractScriptException
{
 if (boundary == null)
   boundary = MultiPartUtil.MULTIPART_HEADER_BOUNDARY_STRING;
 List<InputStream> inList = new ArrayList<InputStream>();
 ByteArrayOutputStream bis = new ByteArrayOutputStream();
 //sb.append("--");
 bis.write(45);
 bis.write(45);
 byte[] bBoundary = boundary.getBytes();
 try {
 bis.write(bBoundary);
 for (Param param : params) {
   //sb.append("\r\n")
   bis.write(13);
   bis.write(10);
   inList.add(new ByteArrayInputStream(bis.toByteArray()));
   bis.reset();
   inList.add(param.toStream(reqCharset));
   //sb.append("\r\n--").append(boundary)
   bis.write(13);
   bis.write(10);
   bis.write(45);
   bis.write(45);
   bis.write(bBoundary);
 }
   bis.write("--\r\n".getBytes());
 inList.add(new ByteArrayInputStream(bis.toByteArray()));
 bis.close();
}
catch (IOException e) {
 http.getCurrentVUSer().handleException(new ScriptException(e));
}
return new OpenScriptInputStream(inList);
}

http.param

Convenience method to create a new File Parameter object.

Format

The http.param method has the following command format(s):

http.param(value);

http.param(name, value);

http.param(name, value, fileName, contentType);

Command Parameters

name

a String specifying the parameter name.

value

a String specifying the parameter value.

fileName

a String specifying the full path to a file whose contents will be submitted to the server.

contentType

a String specifying the Content-type string to appear in the multi-part post parameter element when submitting the file contents to the server.

Returns

a new Param object with the given name and value.

Example

Specifies the file name and content type parameters as postdata for the multipart post navigation.

http.multipartPost(24, "http://myServer.com/", http.querystring(
 http.param("PostName","PostValue")), http.postdata(
   http.param("MyFileParameterName", 
     "C:\\myfile.txt", "C:\\myfile.txt", "ASCII")),
 null, "", false, "ASCII", "ASCII");

See Also

http.get and http.post, and http.multipartPost Methods.

http.patch

Requests a web page using an HTTP PATCH method with querystrings, putdata, headers, URL encoding, and character sets.

Format

The http.patch method has the following command format(s):

http.patch(recid,urlPath, patchdata);

http.patch(recid,urlPath, patchdata, encode);

http.patch(recid,urlPath,querystring, patchdata, headers,encode, reqCharset, respCharset);

http.patch(recid,urlPath,querystring, encode, patchdata, headers, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

querystring

a ParamCollection specifying the Query string data parameter collection. May be null.

patchdata

a ParamCollection specifying the Data to PATCH to the URL's host, in the form of a parameter collection or a String specifying the Data to PATCH to the URL's host. Must not be null.

headers

a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Example

Specifies a PUT navigation with querystrings, putdata, headers, URL encoding, and character sets.

http.patch(12, "http://myServer.com",
 http.querystring(http.param("QueryString1", "QueryValue1"),
  http.param("QueryString2", "QueryValue2"),
  http.param("QueryString3", "QueryValue3")),
 http.patchdata(http.param("PatchString1", "PatchValue1"),
  http.param("PatchString2", "PatchValue2"),
  http.param("PatchString3", "PatchValue3"),
 http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
    Header.HeaderAction.Add),  
  http.header("HeaderString2", "HeaderValue2SetifNotSet", 
    Header.HeaderAction.SetIfNotSet),
  http.header("HeaderString3", "HeaderValue3ApplytoAll",
    Header.HeaderAction.GlobalAdd), 
  http.header("HeaderString4", "HeaderValue4BothActions",
    Header.HeaderAction.GlobalSetIfNotSet)), 
 true, "ASCII", "ASCII"); 

See Also

http.querystring and http.patchdata Methods.

http.patchdata

Convenience method to return a patchdata ParamCollection.

Format

The http.patchdata method has the following command format(s):

http.patchdata(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a PATCH navigation with patchdata parameters.

http.patch(9, "http://myServer.com", http.patchdata(
 http.param("PatchString1", "PatchValue1"), 
 http.param("PatchString2", "PatchValue2"),
 http.param("PutString3", "PatchValue3")));

See Also

http.patch Method.

http.post

Requests a web page using an HTTP POST method with querystrings, postdata, headers, URL encoding, and character sets.

Format

The http.post method has the following command format(s):

http.post(recid, urlPath, postdata);

http.post(recid, urlPath, postdata, encode);

http.post(recid, urlPath, querystring, postdata, headers, encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

postdata

a ParamCollection or String specifying the data to POST to the URL's host. Must not be null.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters using the agent machine's default character set before submitting them to the sever.

querystring

a ParamCollection specifying the Query string data parameter collection. May be null.

headers

a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any exception while navigating or transforming the data.

Example

Specifies a POST navigation with querystrings, postdata, headers, URL encoding, and character sets.

http.post(12, "http://myServer.com",
 http.querystring(http.param("QueryString1", "QueryValue1"),
   http.param("QueryString2", "QueryValue2"), 
   http.param("QueryString3", "QueryValue3")), 
 http.postdata(http.param("PostString1", "PostValue1"), 
   http.param("PostString2", "PostValue2"), 
   http.param("PostString3", "PostValue3")), 
 http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
     Header.HeaderAction.Add), 
   http.header("HeaderString2", "HeaderValue2SetifNotSet", 
     Header.HeaderAction.SetIfNotSet), 
   http.header("HeaderString3", "HeaderValue3ApplytoAll", 
     Header.HeaderAction.GlobalAdd), 
   http.header("HeaderString4", "HeaderValue4BothActions", 
     Header.HeaderAction.GlobalSetIfNotSet)), 
 true, "ASCII", "ASCII"); 

See Also

http.querystring and http.postdata for creating parameter collections.

http.postdata

Convenience method to return a postdata ParamCollection.

Format

The http.postdata method has the following command format(s):

http.postdata(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a POST navigation with postdata parameters.

http.post(9, "http://myServer.com", http.postdata(
 http.param("PostString1", "PostValue1"), 
 http.param("PostString2", "PostValue2"),
 http.param("PostString3", "PostValue3")));

See Also

http.get and http.post, and http.multipartPost Methods. http.param for creating a Param object.

http.put

Requests a web page using an HTTP PUT method with querystrings, putdata, headers, URL encoding, and character sets.

Format

The http.put method has the following command format(s):

http.put(recid,urlPath,querystring, putdata);

http.put(recid,urlPath,querystring, putdata, headers,encode);

http.put(recid,urlPath,querystring, putdata, headers,encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

querystring

a ParamCollection specifying the Query string data parameter collection. May be null.

putdata

a ParamCollection specifying the data to PUT to the URL's host, in the form of a parameter collection or a String specifying the put data. Must not be null. None of the parameters will be URL-encoded before they are submitted to the server.

headers

a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception on any exception while navigating or transforming the data.

Example

Specifies a PUT navigation with querystrings, putdata, headers, URL encoding, and character sets.

http.put(9, "http://myServer.com/{{web.formaction.loginform,default.asp}}",
 http.putdata(http.param("login", "{{web.input.login,ta793}}"), 
  http.param("password", "{{web.input.password,ta}}"),
  http.param("LoginButton", "{{web.input.LoginButton,Login}}")));

-or-

http.put(12, "http://myServer.com",
 http.querystring(http.param("QueryString1", "QueryValue1"),
  http.param("QueryString2", "QueryValue2"),
  http.param("QueryString3", "QueryValue3")),
 http.putdata(http.param("PutString1", "PutValue1"),
  http.param("PutString2", "PutValue2"),
  http.param("PutString3", "PutValue3"),
 http.headers(http.header("HeaderString1", "HeaderValue1NoActions", 
    Header.HeaderAction.Add),  
  http.header("HeaderString2", "HeaderValue2SetifNotSet", 
    Header.HeaderAction.SetIfNotSet),
  http.header("HeaderString3", "HeaderValue3ApplytoAll",
    Header.HeaderAction.GlobalAdd), 
  http.header("HeaderString4", "HeaderValue4BothActions",
    Header.HeaderAction.GlobalSetIfNotSet)), 
 true, "ASCII", "ASCII"); 

See Also

http.querystring and http.putdata for creating a parameter collection.

http.putdata

Convenience method to return a putdata ParamCollection.

Format

The http.putdata method has the following command format(s):

http.putdata(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a PUT navigation with putdata parameters.

http.put(9, "http://myServer.com", http.putdata(
 http.param("PutString1", "PutValue1"), 
 http.param("PutString2", "PutValue2"),
 http.param("PutString3", "PutValue3")));

See Also

http.get and http.put Methods.

http.querystring

Convenience method to create a query string ParamCollection object.

Format

The http.querystring method has the following command format(s):

http.querystring(params);

Command Parameters

params

a Param object collection specifying all parameters to add to the collection.

Returns

a new ParamCollection object from the given Param objects.

Example

Specifies a POST navigation with querystring parameters.

http.post(12, "http://myServer.com", 
 http.querystring(http.param("QueryString1", "QueryValue1"),
   http.param("QueryString2", "QueryValue2"), 
   http.param("QueryString3", "QueryValue3")), 
 null, null, true, "ASCII", "ASCII");            

See Also

get, post, and multipartPost Methods. http.param for creating a Param object.

http.removeCookie

Removes the cookie named cookieName from the cookie jar.

This method removes all Cookies named cookieName for all domains and paths.

This method is identical to http.getBrowser().getCookieJar().removeCookie(String).

Format

The http.removeCookie method has the following command format(s):

http.removeCookie(cookieName);

Command Parameters

cookieName

a String specifying the case-sensitive name of the cookie. May contain {{ }} syntax for transforming. Must not be null.

For example: sessionid

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Removes the specified cookie from the cookie jar.

http.removeCookie("sessionid");

http.removeGlobalTextValidator

Removes a global text assertion or verification test that was previously added using the http.addGlobalAssertText.

If the specified test was not previously added, this method does nothing. No error is thrown.

Format

The http.removeGlobalTextValidator method has the following command format(s):

http.removeGlobalTextValidator(testName);

Command Parameters

testName

a String specifying the name of the test previously added by http.addGlobalAssertText.

Returns

true if the test was removed, otherwise false.

Example

Removes the global text matching test named "GlobalTextMatch".

boolean wasRemoved = http.removeGlobalTextValidator("GlobalTextMatch");
if(wasRemoved){
   info("Global Test Removed: " + wasRemoved);
}
else{
   info("Global Test Removed: " + wasRemoved);
}

http.removeValidator

Removes a previously added validator.

Format

The http.removeValidator method has the following command format(s):

http.removeValidator(validator);

Command Parameters

validator

a Validator previously added using http.addValidator

Returns

true if the validator was removed or false if the validator was not found in the list of validators previously added.

Example

Removes a previously added validator.

import java.util.List;
//[...]
List<IValidator> list = http.getValidatorList();
  for (int i = 0; i < list.size(); i++) {
   IValidator validator = list.get(i);
   info("Validator Name: " + validator.getClass()
      .getSimpleName());
   if (validator.getClass().getSimpleName()
      .equals("LinkValidator")) {
    info("Removing LinkValidator");
   http.removeValidator(validator);
   } else if 
    (validator.getClass().getSimpleName()
      .equals("CategoryValidator")) {
    info("Removing CategoryValidator");
   http.removeValidator(validator);
   } else
    info("Other validator: " 
      + validator.getClass().getSimpleName());
  }

http.setAcceptLanguage

Specifies the Accept-Language header that the browser should use when sending HTTP requests.

This can be used to emulate different language settings in a browser.

Format

The http.setAcceptLanguage method has the following command format(s):

http.setAcceptLanguage(acceptLanguage);

Command Parameters

acceptLanguage

a String specifying the value of the Accept-Language header.

Example

Specifies the Accept-Language header that the browser should use when sending HTTP requests.

http.setAcceptLanguage("en-us"); 

http.setUserAgent

Specifies the User-Agent header that the browser should use when sending HTTP requests.

This can be used to emulate different browsers.

Format

The http.setUserAgent method has the following command format(s):

http.setUserAgent(userAgent);

Command Parameters

userAgent

a String specifying the User-Agent header value. May contain {{ }} syntax for transforming. For example, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Sets the browser Request Header User-Agent string.

http.setUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; " +
 ".NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; " +
 ".NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648;" +
 ".NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); 

http.solve

Parses a value from the document found by XPath and stores it as a variable.

Format

The http.solve method has the following command format(s):

http.solve(varName, pattern);

http.solve(varName, pattern, errorMsg);

http.solve(varName, pattern, errorMsg, isOptional);

http.solve(varName, pattern, errorMsg, isOptional, sourceType);

http.solve(varName, pattern, errorMsg, isOptional, sourceType, resultIndex);

http.solve(varName, pattern, errorMsg, isOptional, sourceType, resultIndex, encodeOption);

http.solve(varName, documentXPath, pattern, errorMsg, isOptional, sourceType, resultIndex, encodeOption);

Command Parameters

varName

a String specifying the name of the script variable to create. Must not be null.

pattern

a String specifying the Regular Expression pattern specifying what to extract from the most recent navigation's contents. May contain a transform expression. Must not be null.

errorMsg

an optional String specifying the error message to display if the pattern cannot be solved. If null, a meaningful error message is automatically generated.

isOptional

a boolean specifying if the pattern must be solved or not. Set to true if the pattern does not have to be solved. If the pattern cannot be solved, the method quietly returns.

sourceType

the Source enum specifying which contents to return as a String. If null, assumes Source.Html.

resultIndex

a 0-based index value specifying the specific result to retrieve if the pattern matches more than one value. If null, all results will be added into the variables collection.

encodeOption

an EncodeOptions enum specifying the encoding or decoding operation to perform on the variable's value after solving the variable. A null value is equivalent to EncodeOptions.None.

documentXPath

a String specifying the XPath to the document containing the target html against which to solve the variable. Optional, may be null. If null, the variable will be solved against the last retrieved contents.

Throws

Exception

on any exception while navigating or transforming the data.

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the given pattern cannot be matched to the previous contents and the pattern is not optional.

Example

Parses a value from the most recent navigation's contents using a Regular Expression and stores it as a variable.

http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>", 
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.None);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.URLEncode);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.URLDecode);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.XMLEncode);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.XMLDecode);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, 
 EncodeOptions.ConvertNewlinesToCRLF);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.ConvertNewlinesToLF);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.RemoveNewlines);
http.solve("solvetitle", "window[@index='0']", "<TITLE>(.+)</TITLE>",
 "Cannot Solve Pattern", true, Source.Html, 0, EncodeOptions.EncodeURIComponent);

http.solveCookieHeader

Extracts the "Set-Cookie" header value which matches the cookie key from the last response header and stores it in the specified script variable.

Format

The http.solveCookieHeader method has the following command format(s):

http.solveCookieHeader(varName, key, lastValue, encodeOption);

Command Parameters

varName

a String specifying the variable name where the value will be stored. Must not be null.

key

a String specifying the 0-based key of the cookie header to look for. Must not be null.

lastValue

an optional String specifying the recorded or last known value of the value about to be parsed. May be null. For informational purposes only.

encodeOption

an EncodeOptions enum specifying the encoding or decoding operation to perform on the variable's value after solving the variable, . A null value is equivalent to EncodeOptions.None.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the referer cannot be solved.

Example

Extract the first (key value 0) "Set-Cookie" header value from the Repsonse header (last known value of "Color=Blue") with no encoding.

http.solveCookieHeader("varCookieHead", "0", "Color=Blue", 
 EncodeOptions.None);
info("Cookie Header = {{varCookieHead}}");

http.solveGroupJavaScript

Extracts a JavaScript string from a document by XPath using a String and stores it in the script's variables collection.

Format

The http.solveGroupJavaScript method has the following command format(s):

http.solveGroupJavaScript(paths);

http.solveGroupJavaScript(path);

http.solveGroupJavaScript(documentXPath, paths);

http.solveGroupJavaScript(documentXPath, path);

Command Parameters

paths

a String Array specifying the JavaScript paths to extract.

path

a String path specifying which JavaScript to extract. Path is a ":" separated list of arguments in the form varName:vbOrJava:blkIndex:literalIndex:literal, as follows:

  • varName: the name of the variable to add to the script's variables collection.

  • vbOrJava: 1 to parse JavaScript, 0 to parse VB Script.

  • blkIndex: 0-based index of the script block in the HTML contents to parse.

  • literalIndex: 0-based index of the dynamic JavaScript literal inside the block to extract.

  • literal: Specify '0' to parse a String from JavaScript, or '1' to parse a number.

documentXPath

a String specifying the document that provides the contents.

Throws

SolveException

if the specified JavaScript path identifiers cannot be found.

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Extracts a JavaScript String from the page and stores it in the variable "varJavaScript" in the script's variables collection. It parses the first script block in the HTML contents for the third the dynamic JavaScript literal as a String from JavaScript.

http.solveGroupJavaScript("window[@index='0']", "varJavaScript:1:0:2:0");
info("Java Script = {{varJavaScript}}");

http.solveHeader

Extracts the specified header value using from the last request's response header acccording to header name.

The value will be stored in the specified variable.

Format

The http.solveHeader method has the following command format(s):

http.solveHeader(varName, headerName, lastValue);

Command Parameters

varName

a String specifying the variable name where the value will be stored. Must not be null.

headerName

a String specifying the header name.

lastValue

an optional String specifying the recorded or last known value of the value. May be null. For informational purposes only.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the header cannot be solved.

Example

Extract the specified header value from the last request's response header and store it in the specified script variable.

http.solveHeader("varHeader", "X-ORACLE-BPMUI-CSRF", 
 "EC92521CFE4D4D8FDEBC3EA6AD36EFADCF87A2B29794A325D7044B14CF8D14597BD62732CEBE1F75C71FB3BF679F6B9E1B00705432C7137A3D64FCCE8571C060");
info("CSRF = {{varHeader}}");

http.solveRedirectNavs

Parses a value from the re-directed navigation's contents and stores it as a variable.

Always lookup from the latest redirected navigation. A SolveException is thrown if there is nothing found for all the re-directed navigations or no re-directed navigation at all.

This API can only be used manually in HTTP scripts.

This method honors the "Solve Variable Failed" error recovery setting. If "Solve Variable Failed" error recovery is not set to fail, then the script will continue running even if a non-optional variable cannot be solved.

Format

The http.solveRedirectNavs method has the following command format(s):

http.solveRedirectNavs(varName, pattern, errorMsg, isOptional, sourceType, resultIndex, encodeOption);

Command Parameters

varName

a String specifying the name of the variable to create. Must not be null.

pattern

a String specifying the Regular Expression pattern specifying what to extract from the most recent navigation's contents. May contain a transform expression. Must not be null.

errorMsg

an optional String specifying the error message to display if the pattern cannot be solved. If null, a meaningful error message is automatically generated.

isOptional

a boolean specifying if the pattern must be solved or not. Set to true if the pattern does not have to be solved. If the pattern cannot be solved, the method quietly returns.

sourceType

the Source enum specifying which contents to return as a String. If null, assumes Source.Html.

resultIndex

a 0-based index value specifying the specific result to retrieve if the pattern matches more than one value. If null, all results will be added into the variables collection.

encodeOption

an EncodeOptions enum specifying the encoding or decoding operation to perform on the variable's value after solving the variable. A null value is equivalent to EncodeOptions.None.

Throws

Exception

if redirected navigation cannot be solved.

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the given pattern cannot be matched to the previous contents and the pattern is not optional.

Example

Parses a value from the most recent re-directed navigation's specified source using a Regular Expression and stores it in a variable. An optional error message returns if the pattern cannot be solved. The pattern is optional and does not have to be solved. Includes a result index value of 0 to specify it should retrieve the first match result and encode or decode using the specified options.

http.solveRedirectNavs("varTitle0", "<TITLE>(.+)</TITLE>", 
 "Title not Found", true, Source.Html, 0, EncodeOptions.None);
info("Page Title = {{varTitle}}");

http.solveRefererHeader

Extracts the "Referer" header value using from the last request's response header using XPath notation.

The value will be stored in the specified variable.

Format

The http.solveRefererHeader method has the following command format(s):

http.solveRefererHeader(varName, lastValue);

http.solveRefererHeader(varName, documentXPath, lastValue);

Command Parameters

varName

a String specifying the variable name where the value will be stored. Must not be null.

lastValue

an optional String specifying the recorded or last known value of the value about to be parsed. May be null. For informational purposes only.

documentXPath

a String specifying the XPath to the document that provides the contents.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the referer cannot be solved.

Example

Extract the "Referer" header value from the last request's response header and store it in the specified script variable.

http.solveRefererHeader("varRefHeader", "window[@index='0']", 
 "http://myServer.com/");
info("Referer = {{varRefHeader}}");

http.solveXPath

Extracts a value from the specified document contents using XPath notation.

This API handles the following two rules:

  • Web DOM rule: Combine documentXPath with xpath to create a full XPath, and find the element in the DOM jBrowser.

  • XML Dom rule: Use documentXPath to find the document in DOM jBrowser, then use xpath to find the element in the document.

Format

The http.solveXPath method has the following command format(s):

http.solveXPath(varName, xpath, lastValue, resultIndex, encodeOption);

http.solveXPath(varName, documentXPath, xpath, lastValue, resultIndex, encodeOption);

Command Parameters

varName

a String specifying the variable name where the value will be stored. Must not be null.

xpath

a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null.

lastValue

an optional String specifying the recorded or last known value of the value about to be parsed. May be null. For informational purposes only.

resultIndex

a 0-based index value specifying the specific result to retrieve if the XPath returns multiple results. A null value specifies that all results should be returned.

encodeOption

an EncodeOptions enum specifying the encoding or decoding operation to perform on the variable's value after solving the variable. A null value is equivalent to EncodeOptions.None.

documentXPath

a String specifying the XPath to the document that provides the contents.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

HTMLParserException

on any failure to parse the HTML.

SolveException

if the XPath cannot be solved.

Example

Extracts a value from the browser's last retrieved contents using XPath notation and stores it in the specified script variable. Encode or decode using the specified options.

http.solveXPath("web.formaction.loginform", "/window[@index=0]", 
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.None);
info("Login form = {{web.formaction.loginform}}");
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.URLEncode);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.URLDecode);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.XMLEncode);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.XMLDecode);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.ConvertNewlinesToCRLF);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.ConvertNewlinesToLF);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.RemoveNewlines);
http.solveXPath("web.formaction.loginform", "/window[@index=0]",
 ".//FORM[@name='loginform']/@action", "default.asp", 0,
 EncodeOptions.EncodeURIComponent);

Source

The Source has the following values:

Table 9-4 List of Source Values

Value Description

Html

Raw HTML, including tags.

ResponseHeader

HTTP response header.

DisplayContent

Received HTML content, excluding markup tags.

RequestHeader

HTTP request header.


http.text

Convenience method to return a ParamCollection object.

Format

The http.text method has the following command format(s):

http.text(text);

Command Parameters

text

a String specifying the raw text data to include in the parameter collection.

Returns

a new ParamCollection object from the specified text.

Example

Returns a ParamCollection from the specified text.

ParamCollection collection = http.text("abc");
if(collection.getText().equals("abc")){
   info("passed!");
}
else{
   warn("failed!");
}

http.urlEncode

URL-encodes a given string using a specific character set excludng the specified character array.

For example, the string, 'the file "abc" is in rootetc', would be encoded as: the+file+%22abc%22+is+in+%5Croot%5Cetc

Format

The http.urlEncode method has the following command format(s):

http.urlEncode(s);

http.urlEncode(s, charset);

http.urlEncode(s, charset, noEncodeList);

Command Parameters

s

a String specifying the string to encode.

charset

a String specifying the character set to use to encoded the string. May be null.

noEncodeList

a char[] array of characters not to encode. May be null.

Throws

URLEncodingException

if any characters cannot be encoded.

Returns

a URL-encoded String.

Example

Encodes the specified string using the specified character set and excludes the specified character list.

char[] noEncodeList = {'&', '\\', '?', '"', '*'};
//using script variable
getVariables().set("urlEncoded", HTTPService
 .urlEncode("the file \"abc\" is in \\root\\etc\\*.*", 
   "ASCII", noEncodeList));
info("Encoded Text in script var = {{urlEncoded}}");
//using Java variable
String urlEncoded = HTTPService
 .urlEncode("the file \"abc\" & test?s in \\root\\etc\\*.*", 
   "ASCII", noEncodeList);
info("The Encoded String is: " + urlEncoded);

http.validate

Validates the browser result for correctness.

This method does nothing if the Response already has an exception set.

If a content failure is found, this method sets an error for the response by calling oracle.oats.scripting.modules.http.api.Response.setException(AbstractScriptException).

Scripts may add custom validation handlers to provide additional content validation, using http.addValidator.

Subclasses may override this method if they need to modify how the HTTP Service itself validates all browser responses.

Format

The http.validate method has the following command format(s):

http.validate(r);

Command Parameters

r

a Browser Response object. May be null.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Gets the last browser browser response for validation.

Response r = http.getLastBrowserResponse().getRequest()
 .getLastRequest().getResponse();
r.setResponseCode(600);
http.validate(r);
if (r.getException() != null&&r.getException().getMessage()
   .trim().equals("HTTP response code: 600  OK") ) {
 info("validate passed!");
}
else{
 warn("validate failed!");
}

http.verifyResponseTime

Tests the server response time for the previous request without failing.

This method does nothing if the Response already has an exception set.

This method will never cause a script to fail, regardless of the server response test error recovery settings.

Use http.assertResponseTime to make the script fail when the test fails.

When playing back a script in Oracle Load Testing, always use Assertions; failed Verifications are not reported in the Oracle Load Test controller.

Subclasses may override this method if they need to modify how the HTTP Service itself validates server response times.

Format

The http.verifyResponseTime method has the following command format(s):

http.verifyResponseTime(testName, minTime, maxTime);

Command Parameters

testName

an optional String specifying a descriptive name describing what request is being tested. The name may appear in results and counter names.

minTime

a double specifying the minimum server response time (inclusive).

maxTime

a double specifying the maximum server response time (inclusive).

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

ResponseTimeException

if no previous response to validate, or if the response time does not fall within the given range and stopIterationOnFailure is false.

Example

Adds a Verify only, never fail Server Response test with a minimum of 1 second and a maximum of 15 seconds.

http.verifyResponseTime("myServerResponseTest", 1.0, 15.0);

http.verifyText

Searches the HTML contents in the document specified by XPath notation for the specified text pattern.

If the test fails, report a warning.

This method will never cause a script to fail, regardless of the text matching test error recovery settings.

Use http.assertText to make the script fail when the test fails.

When playing back a script in Oracle Load Testing, always use Assertions; failed Verifications are not reported in the Oracle Load Test controller.

Format

The http.verifyText method has the following command format(s):

http.verifyText(testName, textToVerify, sourceType, textPresence, matchOption);

http.verifyText(testName, documentXPath, textToVerify, sourceType, textPresence, matchOption);

Command Parameters

testName

a String specifying the test name.

textToVerify

a String specifying the text to match on the page, or not match on the page if TextPresence is set to TextPresence.PassIfPresent.

sourceType

a Source enum specifying where to match the text: the HTML contents or HTTP response headers.

textPresence

a TestPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the test to pass or fail if the text to match is present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

documentXPath

a String specifying the XPath to the document that contains the contents.

Throws

AbstractScriptException

on any failure when attempting to verify the text.

Exception

on any exception while navigating or transforming the data.

Example

Adds a Verify only, never fail Text Matching tests for Display Content, Response Header, and Source HTML respectively.

myTextMatchingTest1 passes if the text to match string is present in the Display Content and matches exactly.

myTextMatchingTest2 passes if the text to match string is present in the Response Header and matches the Regular Expression.

myTextMatchingTest3 fails if the text to match string is present in the Source HTML and matches the Wildcard.

http.verifyText("myTextMatchingTest1", "window[@index='0']", 
 "match this text string", Source.DisplayContent, 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.verifyText("myTextMatchingTest2", "window[@index='0']", 
 "jsessionid=(.+?)(?:\\\"|&)", Source.ResponseHeader,
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.verifyText("myTextMatchingTest3", "window[@index='0']", 
 "match this *", Source.Html, 
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.verifyTitle

Searches the <title> tag in HTML content for the specified title pattern, reporting a warning if the test fails.

Format

The http.verifyTitle method has the following command format(s):

http.verifyTitle(title, matchOption);

http.verifyTitle(documentXPath, title, matchOption);

Command Parameters

title

a String specifying the text pattern specifying the expected title.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

documentXPath

a String specifying the XPath to the document that contains the contents.

Throws

Exception

on any exception while navigating or transforming the data.

MatchException

if the assertion fails.

AbstractScriptException

on any other failure when attempting to assert the text.

Example

Adds Text Title tests for the HTML document title using exact match, Regular Expression match, and Wildcard match respectively.

http.verifyTitle("window[@index='0']", "Summary Report", MatchOption.Exact);
http.verifyTitle("window[@index='0']", "Summary Report For (.+?)", MatchOption.RegEx);
http.verifyTitle("window[@index='0']", "Summary Report For ???", MatchOption.Wildcard);

http.verifyXPath

Verify the text of a DOM element in the browser's last retrieved contents.

Compare this value to the textToVerify parameter. If the test fails, report a warning.

This method will never cause a script to fail, regardless of the XPath test error recovery settings. Use http.assertXPath to make the script fail when the test fails.

When playing back a script in Oracle Load Testing, always use Assertions; failed Verifications are not reported in the Oracle Load Test controller.

Format

The http.verifyXPath method has the following command format(s):

http.verifyXPath(testName, xpath, resultIndex, textToVerify, textPresence, matchOption);

Command Parameters

testName

a String specifying the test name.

xpath

a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null.

resultIndex

a 0-based index value specifying the specific result to retrieve if the XPath returns multiple results. A null value specifies that all results should be returned.

textToVerify

a String specifying the text to match, or not match with the XPath result if TextPresence is set to TextPresence.PassIfPresent.

textPresence

a TestPresence enum specifying either PassIfPresent or FailIfPresent, depending on if you want the test to pass or fail if the text to match is present or not.

matchOption

a MatchOption enum specifying how the text to match should be searched on the page, such as using a Regular Expression, Wildcard, or exact match.

Throws

AbstractScriptException

on any failure when attempting to verify the text.

Example

Adds Text Matching tests using XPath notation.

myTextMatchingTest1 passes if the text to match string is present and matches exactly.

myTextMatchingTest2 passes if the text to match string is present and matches the entire string exactly.

myTextMatchingTest3 passes if the text to match string is present and matches the Regular Expression.

myTextMatchingTest4 passes if the text to match string is present and matches the entire string from the Regular Expression.

myTextMatchingTest5 fails if the text to match string is present and matches the Wildcard.

http.verifyXPath("myTextMatchingTest1", ".//input[@name='j_id_id3']" +
 "/@value", 0, "match this text string", 
 TextPresence.PassIfPresent, MatchOption.Exact);
http.verifyXPath("myTextMatchingTest2", ".//input[@name='j_id_id3']" +
 "/@value", 1, "match this text string", 
 TextPresence.PassIfPresent, MatchOption.ExactEntireString);
http.verifyXPath("myTextMatchingTest3", ".//input[@name='j_id_id3']" +
 "/@value", 0, "jsessionid=(.+?)(?:\\\"|&)",
 TextPresence.PassIfPresent, MatchOption.RegEx);
http.verifyXPath("myTextMatchingTest4", ".//input[@name='j_id_id3']" + 
 "/@value", 1, "jsessionid=(.+?)(?:\\\"|&)",
 TextPresence.PassIfPresent, MatchOption.RegExEntireString);
http.verifyXPath("myTextMatchingTest5", ".//input[@name='j_id_id3']" +
 "/@value", 0, "match this *",
 TextPresence.FailIfPresent, MatchOption.Wildcard);

http.window

Finds the window element from browser's DOM tree using the window index.

The element instance will be returned.

Format

The http.window method has the following command format(s):

http.window(recId, xpathToWindow);

Command Parameters

recId

the ID of a previously recorded navigation, used for comparison purposes. May be null.

xpathToWindow

a String specifying the XPath of the window element describing which value to parse from the DOM tree. Must not be null.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

the window element's reference.

Example

Finds the window element from browser's DOM tree indexed as 0.

boolean http_window_exists = http.window(184, "window[" +
 "@index='0']").exists();
if(http_window_exists){
 info("WebHTTPWindow exists: " + http_window_exists);
}
else{
 warn("WebHTTPWindow exists: " + http_window_exists);
}

http.xmlPost

Posts an XML string to a web server using the HTTP POST method.

Format

The http.xmlPost method has the following command format(s):

http.xmlPost(recid, urlPath, querystring, postdata, headers, encode, reqCharset, respCharset);

Command Parameters

recid

the ID of a previously recorded navigation, used for comparison purposes. May be null.

urlPath

a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null.

querystring

a ParamCollection specifying the query string data. May be null.

postdata

a String specifying the XML data to POST to the URL's host. Must not be null.

headers

a Header array of additional headers to add/remove from the request before submitting it to the server.

encode

a boolean specifying the parameter encoding. Set to true to URL-encode the querystring parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any exception while navigating or transforming the data.

Example

Specifies an XML POST navigation with querystrings, postdata, headers, URL encoding, and Character sets.

http.xmlPost(0, "http://myServer.com", 
 http.querystring(http.param("xmlQueryString1", "xmlQueryValue1"), 
   http.param("xmlQueryString2", "xmlQueryValue2"), 
   http.param("xmlQueryString3", "xmlQueryValue3")),  
 "xmlPostDataString", 
 http.headers(http.header("xmlHeaderString1", "xmlHeaderValue1NoAction", 
     Header.HeaderAction.Add), 
   http.header("xmlHeaderString2", "xmlHeaderValue2IfNotSet", 
     Header.HeaderAction.SetIfNotSet), 
   http.header("xmlHeaderString3", "xmlHeaderValue3ApplytoAll", 
     Header.HeaderAction.GlobalAdd), 
   http.header("xmlHeaderString4", "xmlHeaderValue4Both", 
     Header.HeaderAction.GlobalSetIfNotSet)), 
 false, "ASCII", "ASCII");

See Also

http.querystring for creating a parameter collection.