3 Adobe Flex (AMF) Load Module

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

3.1 AmfService API Reference

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

3.1.1 Alphabetical Command Listing

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

Table 3-1 List of AmfService Methods

Method Description

amf.assertText

Search the AMF contents of all documents in all browser windows for the specified text pattern.

amf.post

Post an AMF request to the AMF server identified by recID, description, and urlPath.

amf.solve

Parses a value from the most recent navigation's contents and store it as a variable.

amf.solveXpath

Extract a value from the last retrieved response using XPath notation.

amf.verifyText

Search the AMF contents of all documents in all browser windows for the specified text pattern.


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


amf.assertText

Search the AMF contents of all documents in all browser windows 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 amf.assertText method has the following command format(s):

amf.assertText(testName, 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 says TextPresence.FailIfPresent.

sourceType

an AmfSource enum specifying where to match the text, i.e. in the XML 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.

Throws

MatchException

if the assertion fails.

AbstractScriptException

on any other failure when attempting to assert the text.

Example

Adds Text Matching tests for Response Header and XML Content.

myTextMatchingTest1 passes if the text to match string is present in the XML 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 XML Content and matches the Wildcard.

amf.assertText("myTextMatchingTest1", "match this text string",
 AmfSource.Content, TextPresence.PassIfPresent,
 MatchOption.Exact);
amf.assertText("myTextMatchingTest2", "jsessionid=(.+?)(?:\\\"|&)", 
 AmfSource.ResponseHeader, TextPresence.PassIfPresent,
 MatchOption.RegEx);
amf.assertText("myTextMatchingTest3", "match this *",
 AmfSource.Content, TextPresence.FailIfPresent, 
 MatchOption.Wildcard);

amf.post

Post an AMF request to the AMF server identified by recID, description, and urlPath.

Reads the XML postMessage as a String, serializes it into an ActionScript (AMF) object and then makes a post to the urlPath provided.

Format

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

amf.post(description, urlPath, postMessage);

amf.post(recId, description, urlPath, postMessage);

Command Parameters

description

a String specifying a human-readable description of the operation which will be invoked on the server. Used for reporting and script display purposes only.

urlPath

a String specifying the AMF endpoint on the server where all AMF requests are posted. For example: "http://server:8080/todolist-web/messagebroker/amf"

postMessage

a String specifying an XML string containing the AMF message which will be posted to the urlPath.

recId

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

Throws

AbstractScriptException

on any exception posting data to the server.

Example

Posts the xml postMessage as an ActionScript (AMF) object to the specified URL.

amf.post(10, "Click the button", "http://server-xyz:8080/openamf/gateway", 
 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
 "<amf version=\"0\">" +
  "<headers><header name=\"amf_server_debug\" required=\"true\"> " +
   "<asobject type=\"NetDebugConfig\">" +
    "<entry key=\"m_debug\" type=\"boolean\">true</entry>" +
    "<entry key=\"coldfusion\" type=\"boolean\">true</entry>" +
    "<entry key=\"error\" type=\"boolean\">true</entry>" +
    "<entry key=\"amf\" type=\"boolean\">false</entry>" +
    "<entry key=\"trace\" type=\"boolean\">true</entry>" +
    "<entry key=\"httpheaders\" type=\"boolean\">false</entry>" +
    "<entry key=\"recordset\" type=\"boolean\">true</entry>" +
    "<entry key=\"amfheaders\" type=\"boolean\">false</entry>" +
   "</asobject>" +
  "</header></headers>" +
  "<bodies>" +
   "<body operation=\"org.openamf.examp.Test.getNumber\" response=\"/1\">" +
   " <list><item type=\"double\">123.456</item></list>" +
   "</body>" +
  "</bodies>" +
 "</amf>");

amf.solve

Parses a value from the most recent navigation's contents and store it as a variable.

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 amf.solve method has the following command format(s):

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

Command Parameters

varName

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

pattern

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

errorMsg

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

isOptional

True if the pattern does not have to be solved. If the pattern cannot be solved, the method quietly returns.

sourceType

an AmfSource enum specifying where to match the text, i.e. in the XML contents or HTTP response headers.

resultIndex

an index value specifying the 0-based index of 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 specifing 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 an error parsing the value.

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

Parse a value from the most recent navigation's specified source using a Regular Expression and store 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.

amf.solve("flex.dsid", 
 "<entry key=\"DSId\" type=\"string\">(.+?)</entry>",
 "DSId is a required field", true, AmfSource.Content,
 0, EncodeOptions.URLEncode);

amf.solveXpath

Extract a value from the last retrieved response using XPath notation.

The value will be stored to the given variable.

Format

The amf.solveXpath method has the following command format(s):

amf.solveXpath(varName, 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 to the 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

an index value specifying the 0-based index of 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 specifing 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.

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.

amf.solveXpath("amf.formaction.loginform", 
 ".//FORM[@name='loginform']/@action",
 "default.asp", 0, EncodeOptions.None);
info("Login form = {{amf.formaction.loginform}}");

amf.verifyText

Search the AMF contents of all documents in all browser windows for the specified text pattern.

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

Use amf.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 OLT.

Format

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

amf.verifyText(testName, 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 says TextPresence.FailIfPresent.

sourceType

an AmfSource enum specifying where to match the text, i.e. in the XML 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.

Throws

MatchException

if the assertion fails.

AbstractScriptException

on any other failure when attempting to assert the text.

Example

Adds a Verify only, never fail Text Matching tests for Response Header and XML Content.

myTextMatchingTest1 passes if the text to match string is present in the XML 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 XML Content and matches the Wildcard.

amf.verifyText("myTextMatchingTest1", "match this text string",
 AmfSource.Content, TextPresence.PassIfPresent,
 MatchOption.Exact);
amf.verifyText("myTextMatchingTest2", "jsessionid=(.+?)(?:\\\"|&)", 
 AmfSource.ResponseHeader, TextPresence.PassIfPresent,
 MatchOption.RegEx);
amf.verifyText("myTextMatchingTest3", "match this *",
 AmfSource.Content, TextPresence.FailIfPresent, 
 MatchOption.Wildcard);