This chapter provides a complete listing and reference for the methods in the OpenScript HTTPService Class of HTTP Load Module Application Programming Interface (API).
The following section provides an alphabetical listing of the enums in the OpenScript HTTPService API.
The following table lists the HTTPService Enums in alphabetical order.
The following section provides an alphabetical listing of the methods in the OpenScript HTTPService API.
The following table lists the HTTPService API methods in alphabetical order.
Table 8-2 List of HTTPService Methods
Method | Description |
---|---|
Add a username and password to use when authenticating a URL that requires NTLM or Basic authentication. |
|
Adds a cookie to the cookie jar. |
|
Registers a text assertion test to run every time a page is requested. |
|
Registers a text verification test to run every time a page is requested. |
|
Adds a class to provide custom validation for all browser responses. |
|
Tests the server response time for the previous request. |
|
Searches the HTML contents of the specified document XPath for the specified text pattern. |
|
Searches the |
|
Extracts a value from the browser's last retrieved contents using XPath notation. |
|
Begins a concurrent section used to make multiple HTTP requests at the same time by the same Virtual User using a different HTTP connection. |
|
Clears the Cookies during playback. |
|
Finds the element from the browser's DOM tree using XPath notation. |
|
Ends the specified concurrent section waiting the specified amount of time for requests to finish. |
|
Finds the form element from the browser's DOM tree using XPath notation. |
|
Finds the frame element from the browser's DOM tree using XPath notation. |
|
Requests a web page using an HTTP GET method. |
|
Gets a Thin browser for making HTTP requests. |
|
Gets the HTML content of a document which is specified by the XPath. |
|
Gets the last retrieved response from this Virtual User's browser. |
|
Returns a String version of a given browser response from the specified source type. |
|
Gets the headers of a response and its ancestors that is received by a window specified by the XPath. |
|
Gets the settings for the HTTP service. |
|
Returns all the validators added by |
|
Convenience method for creating a new |
|
Convenience method to create a new |
|
Builds the JavaScript path(s) to use to extract JavaScript strings using http.solveGroupJavaScript. |
|
Finds the link element from the browser's DOM tree using XPath notation. |
|
Loads the keystore file using the specified password. |
|
Requests a web page using a multipart HTTP POST method with querystring, postdata, headers, boundary, URL-encoding, and character sets. |
|
Navigates to a web page using the specified ID, URL, additional headers, redirect, character set, method, and input stream. |
|
Convenience method to create a new File Parameter object. |
|
Requests a web page using an HTTP POST method with querystrings, postdata, headers, URL encoding, and character sets. |
|
Convenience method to return a postdata |
|
Convenience method to create a query string |
|
Removes the cookie named |
|
Removes a global text assertion or verification test that was previously added using the http.addGlobalAssertText. |
|
Removes a previously added validator. |
|
Specifies the |
|
Specifies the |
|
Parses a value from the document found by XPath and stores it as a variable. |
|
Extracts the "Set-Cookie" header value which matches the cookie key from the last response header and stores it in the specified script variable. |
|
Extracts a JavaScript string from a document by XPath using a String and stores it in the script's variables collection. |
|
Extracts the specified header value using from the last request's response header acccording to header name. |
|
Parses a value from the re-directed navigation's contents and stores it as a variable. |
|
Extracts the "Referer" header value using from the last request's response header using XPath notation. |
|
Extracts a value from the specified document contents using XPath notation. |
|
Convenience method to return a |
|
URL-encodes a given string using a specific character set excludng the specified character array. |
|
Validates the browser result for correctness. |
|
Tests the server response time for the previous request without failing. |
|
Searches the HTML contents in the document specified by XPath notation for the specified text pattern. |
|
Searches the |
|
Verify the text of a DOM element in the browser's last retrieved contents. |
|
Finds the window element from browser's DOM tree using the window index. |
|
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.
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.
The http.addAuthentication method has the following command format(s):
http.addAuthentication(url, username, password);
a String specifying the URL for this authentication information. May contain {{ }} syntax for transforming.
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.
a String specifying the password. May contain {{ }} syntax for transforming. Must not be null
.
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.
Sets username and encrypted password authentication for myServer.com
. See also the {@link oracle.oats.scripting.modules.basic.api.IteratingVUserScript.decrypt} and {@link oracle.oats.scripting.modules.basic.api.IteratingVUserScript.encrypt} methods in the Basic module API.
http.addAuthentication("http://myServer.com", "myUsername",
decrypt("38eHEwYhPOOG9ljr70eF6A=="));
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.
The http.addCookie method has the following command format(s):
http.addCookie(cookieString, charset);
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
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.
if charset
is not a supported character encoding.
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.
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.
The http.addGlobalAssertText method has the following command format(s):
http.addGlobalAssertText(testName, textToAssert, sourceType, textPresence, matchOption);
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
.
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
.
a Source enum specifying where to match the text: the HTML contents or HTTP response headers. Must not be null
.
a TextPresence enum specifying either PassIfPresent
or FailIfPresent
, depending on if you want the text to be present or not.
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.
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);
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.
The http.addGlobalVerifyText method has the following command format(s):
http.addGlobalVerifyText(testName, textToAssert, sourceType, textPresence, matchOption);
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
.
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
.
a Source enum specifying where to match the text: the HTML contents or HTTP response headers. Must not be null
.
a TextPresence enum specifying either PassIfPresent
or FailIfPresent
, depending on if you want the text to be present or not.
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.
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);
Adds a class to provide custom validation for all browser responses.
Custom IValidator instances are invoked after HTTPService performs its own validation.
The http.addValidator method has the following command format(s):
http.addValidator(validator);
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();
}
}
}
}
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.
The http.assertResponseTime method has the following command format(s):
http.assertResponseTime(testName, minTime, maxTime);
a String specifying a descriptive name describing what request is being tested. The name may appear in results and counter names.
a double specifying the minimum server response time (inclusive).
a double specifying maximum server response time (inclusive).
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.
if no previous response to validate, or if the response time does not fall within the given range and stopIterationOnFailure is true
.
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.
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);
a String specifying the test name.
a String specifying the text to match on the page, or not match on the page if TextPresence
is set to TextPresence.PassIfPresent
.
a Source enum specifying where to match the text: the HTML contents or HTTP response headers.
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.
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.
a String specifying the XPath to the document that contains the contents.
if the assertion fails. AbstractScriptException on any other failure when attempting to assert the text.
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.
if the assertion fails.
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);
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.
The http.assertTitle method has the following command format(s):
http.assertTitle(title, matchOption);
http.assertTitle(documentXPath, title, matchOption);
a String specifying the text pattern specifying the expected title.
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.
a String specifying the XPath to the document that contains the contents.
on any exception while navigating or transforming the data.
if the assertion fails.
on any other failure when attempting to assert the text.
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);
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.
The http.assertXPath method has the following command format(s):
http.assertXPath(testName, xpath, resultIndex, textToVerify, textPresence, matchOption);
a String specifying the test name.
a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null
.
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.
a String specifying the Text to match, or not match with the XPath result if TextPresence
is set to TextPresence.PassIfPresent
.
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.
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.
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);
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");
The http.beginConcurrent method has the following command format(s):
http.beginConcurrent(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
.
Begins a concurrent section with the ID mySessionID_0001
.
http.beginConcurrent("mySessionID_0001");
Finds the element from the browser's DOM tree using XPath notation.
The element instance will be returned.
a String specifying the XPath of the element describing which value to parse from the DOM tree. Must not be null
.
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.
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");
}
The EncodeOptions has the following values:
Table 8-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 |
URLDecode |
URL-decodes a string. For example, the string |
XMLEncode |
Encodes any characters that should be escaped for XML serialization. For example, the string |
XMLDecode |
Decodes any characters that were escaped for XML serialization. For example, the string |
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: , / ? : @ & = + $ # |
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.
The http.endConcurrent method has the following command format(s):
http.endConcurrent(concurrentSectionId);
http.endConcurrent(concurrentSectionId, timeoutSeconds);
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.
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.
on any exception that occurs when executing the concurrent requests.
if a timeout occurs while waiting for the concurrent requests to finish.
if the thread is interrupted while waiting for the concurrent requests to finish.
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);
Finds the form element from the browser's DOM tree using XPath notation.
The element instance will be returned.
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the XPath of the form element describing which value to parse from the DOM tree. Must not be null
.
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");
}
Finds the frame element from the browser's DOM tree using XPath notation.
The element instance will be returned.
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the XPath of the frame element describing which value to parse from the DOM tree. Must not be null
.
Requests a web page using an HTTP GET method.
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);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null
.
an Object specifying the Query string data, either as a String or ParamCollection
. May be null
.
a headers array specifying additional headers to add/remove from the request before submitting it to the server.
a boolean specifying the parameter encoding. Set to true
to URL-encode the querystring parameters before submitting them to the sever.
a String specifying the character set to use if URL-encoding any of the request parameters.
a String specifying the character set to use when reading the response contents.
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");
http.querystring for creating a parameter collection.
Gets a Thin browser for making HTTP requests.
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());
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.
The http.getHtmlContent method has the following command format(s):
http.getHtmlContent(xpath);
a String specifying the XPath to the window, document, frame, or element containing the HTML content.
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);
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.
The http.getLastBrowserResponse method has the following command format(s):
http.getLastBrowserResponse( );
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);
Returns a String version of a given browser response from the specified source type.
The http.getLastResponseContents method has the following command format(s):
http.getLastResponseContents( );
http.getLastResponseContents(sourceType);
http.getLastResponseContents(lastBrowserResponse, sourceType);
the Source enum specifying which contents to return as a String. If null
, assumes Source.Html
.
a Response object from which to return the last browser contents.
String version of the given browser response. Returns null
when the last browser response is null
.
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);
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.
The http.getResponseHeaders method has the following command format(s):
http.getResponseHeaders(xpath);
a String specifying the XPath to the window, frame, or element containing the response headers.
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);
Gets the settings for the HTTP service.
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());
Returns all the validators added by addValidator
.
The http.getValidatorList method has the following command format(s):
http.getValidatorList( );
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());
}
Convenience method for creating a new Header
object.
The http.header method has the following command format(s):
http.header(name, value, action);
a String specifying the header name. May contain {{ }} syntax for transforming. Must not be null
.
a String specifying the header value. May contain {{ }} syntax for transforming. Must not be null
.
a HeaderAction object, such as remove or add the header.
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));
Convenience method to create a new Header
array.
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));
Builds the JavaScript path(s) to use to extract JavaScript strings using http.solveGroupJavaScript.
The http.javaScriptPath method has the following command format(s):
http.javaScriptPath(name, scriptLanguage, scriptIndex, literalIndex, literalType);
a String specifying the variable name to use.
an Integer specifying the the script language. 1 to parse JavaScript, 0 to parse VB Script.
an Integer specifying the 0-based index of the script block in the HTML contents to parse.
an Integer specifying the 0-based index of the dynamic JavaScript literal inside the block to extract.
an Integer specifying the data type. Specify '0' to parse a String from JavaScript, or '1' to parse a number.
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}}");
Finds the link element from the browser's DOM tree using XPath notation.
The element instance will be returned.
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the XPath of the link element describing which value to parse from the DOM tree. Must not be null
.
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
.
The http.loadKeystore method has the following command format(s):
http.loadKeystore(keystoreFilePath, keystorePassword);
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.
a String specifying the password used to read certificates from the keystore.
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.
if the keystore cannot be loaded for any reason.
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.
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);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying ther URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null
.
a ParamCollection
of the postdata to POST to the URL's host. Must not be null
.
a ParamCollection
of query string data parameters. May be null
.
a Header array of additional headers to add/remove from the request before submitting it to the server.
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.
a String specifying the character set to use if URL-encoding any of the request parameters.
a String specifying the character set to use when reading the response contents.
a boolean specifying the parameter encoding. Set to true
to URL-encode the querystring parameters before submitting them to the sever.
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");
http.querystring and http.postdata for creating parameter collections.
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.
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);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the URL to request. Must not be null
.
an HTTPMethod enum specifing the HTTP request header method: GET or POST.
a String specifying the Postdata to POST to the URL's host. May be null
.
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.
a Headers object specifying additional headers to add to the request.
a String specifying the character set to use when reading the response contents.
an InputStream containing postdata to POST to URL. Should be OpenScriptInputStream.
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);
}
Convenience method to create a new File Parameter object.
The http.param method has the following command format(s):
http.param(value);
http.param(name, value);
http.param(name, value, fileName, contentType);
a String specifying the parameter name.
a String specifying the parameter value.
a String specifying the full path to a file whose contents will be submitted to the server.
a String specifying the Content-type string to appear in the multi-part post parameter element when submitting the file contents to the server.
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");
http.get and http.post, and http.multipartPost Methods.
Requests a web page using an HTTP POST method with querystrings, postdata, headers, URL encoding, and character sets.
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);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null
.
a ParamCollection
specifying the data to POST to the URL's host. Must not be null
.
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.
a ParamCollection
specifying the Query string data parameter collection. May be null
.
a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.
a String specifying the character set to use if URL-encoding any of the request parameters.
a String specifying the character set to use when reading the response contents.
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");
http.querystring and http.postdata for creating parameter collections.
Convenience method to return a postdata ParamCollection
.
a Param
object collection specifying all parameters to add to the collection.
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")));
http.get and http.post, and http.multipartPost Methods. http.param for creating a Param
object.
Convenience method to create a query string ParamCollection
object.
a Param
object collection specifying all parameters to add to the collection.
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");
get, post, and multipartPost Methods. http.param for creating a Param object.
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).
The http.removeCookie method has the following command format(s):
http.removeCookie(cookieName);
a String specifying the case-sensitive name of the cookie. May contain {{ }} syntax for transforming. Must not be null
.
For example: sessionid
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.
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.
The http.removeGlobalTextValidator method has the following command format(s):
http.removeGlobalTextValidator(testName);
a String specifying the name of the test previously added by http.addGlobalAssertText.
Removes a previously added validator.
The http.removeValidator method has the following command format(s):
http.removeValidator(validator);
a Validator previously added using http.addValidator
true
if the validator was removed or false
if the validator was not found in the list of validators previously added.
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()); }
Specifies the User-Agent
header that the browser should use when sending HTTP requests.
This can be used to emulate different browsers.
The http.setUserAgent method has the following command format(s):
http.setUserAgent(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)
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.
Parses a value from the document found by XPath and stores it as a variable.
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);
a String specifying the name of the script variable to create. Must not be null
.
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
.
an optional String specifying the error message to display if the pattern cannot be solved. If null
, a meaningful error message is automatically generated.
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.
the Source enum specifying which contents to return as a String. If null
, assumes Source.Html
.
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.
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
.
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.
on any exception while navigating or transforming the data.
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.
if the given pattern cannot be matched to the previous contents and the pattern is not optional.
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);
Extracts the "Set-Cookie" header value which matches the cookie key from the last response header and stores it in the specified script variable.
The http.solveCookieHeader method has the following command format(s):
http.solveCookieHeader(varName, key, lastValue, encodeOption);
a String specifying the variable name where the value will be stored. Must not be null
.
a String specifying the 0-based key of the cookie header to look for. Must not be null
.
an optional String specifying the recorded or last known value of the value about to be parsed. May be null
. For informational purposes only.
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
.
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.
if the referer cannot be solved.
Extracts a JavaScript string from a document by XPath using a String and stores it in the script's variables collection.
The http.solveGroupJavaScript method has the following command format(s):
http.solveGroupJavaScript(paths);
http.solveGroupJavaScript(path);
http.solveGroupJavaScript(documentXPath, paths);
http.solveGroupJavaScript(documentXPath, path);
a String Array specifying the JavaScript paths to extract.
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.
a String specifying the document that provides the contents.
if the specified JavaScript path identifiers cannot be found.
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.
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}}");
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.
The http.solveHeader method has the following command format(s):
http.solveHeader(varName, headerName, lastValue);
a String specifying the variable name where the value will be stored. Must not be null
.
a String specifying the header name.
an optional String specifying the recorded or last known value of the value. May be null
. For informational purposes only.
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.
if the header cannot be solved.
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}}");
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.
The http.solveRedirectNavs method has the following command format(s):
http.solveRedirectNavs(varName, pattern, errorMsg, isOptional, sourceType, resultIndex, encodeOption);
a String specifying the name of the variable to create. Must not be null
.
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
.
an optional String specifying the error message to display if the pattern cannot be solved. If null
, a meaningful error message is automatically generated.
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.
the Source enum specifying which contents to return as a String. If null
, assumes Source.Html.
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.
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
.
if redirected navigation cannot be solved.
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.
if the given pattern cannot be matched to the previous contents and the pattern is not optional.
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}}");
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.
The http.solveRefererHeader method has the following command format(s):
http.solveRefererHeader(varName, lastValue);
http.solveRefererHeader(varName, documentXPath, lastValue);
a String specifying the variable name where the value will be stored. Must not be null
.
an optional String specifying the recorded or last known value of the value about to be parsed. May be null
. For informational purposes only.
a String specifying the XPath to the document that provides the contents.
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.
if the referer cannot be solved.
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.
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);
a String specifying the variable name where the value will be stored. Must not be null
.
a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null
.
an optional String specifying the recorded or last known value of the value about to be parsed. May be null
. For informational purposes only.
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.
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
.
a String specifying the XPath to the document that provides the contents.
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.
on any failure to parse the HTML.
if the XPath cannot be solved.
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);
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
The http.urlEncode method has the following command format(s):
http.urlEncode(s);
http.urlEncode(s, charset);
http.urlEncode(s, charset, noEncodeList);
a String specifying the string to encode.
a String specifying the character set to use to encoded the string. May be null
.
a char[] array of characters not to encode. May be null
.
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);
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.
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.
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!");
}
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.
The http.verifyResponseTime method has the following command format(s):
http.verifyResponseTime(testName, minTime, maxTime);
an optional String specifying a descriptive name describing what request is being tested. The name may appear in results and counter names.
a double specifying the minimum server response time (inclusive).
a double specifying the maximum server response time (inclusive).
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.
if no previous response to validate, or if the response time does not fall within the given range and stopIterationOnFailure is false
.
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.
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);
a String specifying the test name.
a String specifying the text to match on the page, or not match on the page if TextPresence
is set to TextPresence.PassIfPresent
.
a Source enum specifying where to match the text: the HTML contents or HTTP response headers.
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.
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.
a String specifying the XPath to the document that contains the contents.
on any failure when attempting to verify the text.
on any exception while navigating or transforming the data.
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);
Searches the <title>
tag in HTML content for the specified title pattern, reporting a warning if the test fails.
The http.verifyTitle method has the following command format(s):
http.verifyTitle(title, matchOption);
http.verifyTitle(documentXPath, title, matchOption);
a String specifying the text pattern specifying the expected title.
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.
a String specifying the XPath to the document that contains the contents.
on any exception while navigating or transforming the data.
if the assertion fails.
on any other failure when attempting to assert the text.
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);
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.
The http.verifyXPath method has the following command format(s):
http.verifyXPath(testName, xpath, resultIndex, textToVerify, textPresence, matchOption);
a String specifying the test name.
a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null
.
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.
a String specifying the text to match, or not match with the XPath result if TextPresence
is set to TextPresence.PassIfPresent
.
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.
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.
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);
Finds the window element from browser's DOM tree using the window index.
The element instance will be returned.
The http.window method has the following command format(s):
http.window(recId, xpathToWindow);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the XPath of the window element describing which value to parse from the DOM tree. Must not be null
.
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.
Posts an XML string to a web server using the HTTP POST method.
The http.xmlPost method has the following command format(s):
http.xmlPost(recid, urlPath, querystring, postdata, headers, encode, reqCharset, respCharset);
the ID of a previously recorded navigation, used for comparison purposes. May be null
.
a String specifying the URL to request, excluding query string data. May contain {{ }} syntax for transforming. Must not be null
.
a ParamCollection
specifying the query string data. May be null
.
a String specifying the XML data to POST to the URL's host. Must not be null
.
a Header array of additional headers to add/remove from the request before submitting it to the server.
a boolean specifying the parameter encoding. Set to true
to URL-encode the querystring parameters before submitting them to the sever.
a String specifying the character set to use if URL-encoding any of the request parameters.
a String specifying the character set to use when reading the response contents.
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");
http.querystring for creating a parameter collection.