MWP object reference

Actions in MWP scripts can contain JavaScript code, and these objects described here can be used to add advanced functionality to script actions.

See Adding Actions to Scripts for more information about how to add JavaScript commands to actions. See also the MWP Scripting Reference.

Note

Names of objects, properties and methods are case sensitive.

Phone object

This object is used to dynamically access detail about the device being used for emulation when you run the script. Allows you to add additional checks or change logic, depending on the device.

String Phone.Manufacturer

(Read only) Manufacturer of the device of the device used for playback

Example: Actions.print(Phone.Manufacturer); will print in the debug log “Apple ” (if the script is run with an Apple iPhone).

String Phone.Model

(Read only) Model of the device used for playback

Example: Actions.print(Phone.Model); will print in the debug log “iPhone 4S ” (if the script is run with an iPhone 4s).

String Phone.UserAgent

(Read only) User agent of the device used for playback

Example: Actions.print(Phone. UserAgent); will print in the debug log “Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3 ” (if the script is run with an iPhone 4s).

Int Phone.Height

(Read only) Height of the screen of the device used for playback

Example: Actions.print(“”+ Phone.Height); will print in the debug log “416 ” (if the script is run with an iPhone 4s)

Int Phone.Width

(Read only) Width of the screen of the device used for playback.

Example: Actions.print(“”+ Phone.Height); will print in the debug log “320 ” (if the script is run with an iPhone 4s).

String Phone.UserAgentSuffix

(Read/write) Set or get the user agent suffix for each HTTP request. This can help you to filter MITE/MWP traffic from your web server logs. The string passed as the parameter will be appended to the current user agent string used depending on the device you use for playback.

Actions object

Actions.post(string url, string data);

Post string data to a URL. Data should be formatted in application/x-www-form-urlencoded.

Example: Actions.post(“www.google.com“, “q= test&lg=en”);

Actions.postEx(string url, string data, string content_type);

Post data to a URL. You can specify the content-type at the last parameter. You can also send binary data if base 64 encoded. Prefix the encoded data string to send with MAP.base64: .

Example: Actions.post(“www.google.com“, “mydata”, “text/plain”);
Actions.post(“www.google.com“, “ MAP.base64:bXlkYXRh”, “text/plain”);

Actions.print(string)

Print a string in the debug log available at the end of a run.

Actions.getPreviewStr()

Returns a base 64 string holding the preview screenshot of the last page rendered by the MITE script engine.

Actions.setUserAgentString(string)

Change the user agent string used for emulation (not the device property, just the user agent string) sent in each HTTP request as well as the value navigator.useragent that is accessed through client-side JavaScript in the web page.

Page object

Bool Page.findItemOnPage(string p_xPath)

If the XPath provided in the parameter returns a node element, the call returns true . If not, it returns false .

String Page.getItemContentOnPage(string p_xPath)

Returns the text of the first node element associated with the XPath provided as the parameter.

Int Page.getPageCount()

Some sites open popups or new pages; this object lets you know how many pages are open at any time in your script.

String Page.getPageNameByIndex(int index)

Index must be between 0 and Page.getPageCount()  -1; this will return the title of the page specified by the index.

String Page.getPageUrlByIndex(int index)

Index must be between 0 and Page.getPageCount()  -1; this will return the URL of the page specified by the index.

Int Page.getCurrentPageIndex()

Returns the index of the active page. The active page is the one on which any action such as clickName , clickOnLink Page.getDOMStr() will have effect.

Int Page.switchPage(int index)

Allows change from one page to another. The index should be between 0 and Page.getPageCount()  -1.

Int Page.closeCurrentPage()

Closes the current page.

VirtualProfiles object

Int VirtualProfiles.ProfilesCount()

Retrieves the number of virtual profiles defined in the script.

Int VirtualProfiles.FieldsCount()

Retrieves the number of fields defined in the profile.

String VirtualProfiles.FieldName(int index)

Retrieves the name of the field based on the index. Index is between 0 and VirtualProfiles.ProfilesCount()  -1.

String VirtualProfiles.FieldValueByName(string name)

When a script with virtual profiles is run, the virtual profile index has to be selected. This method will give you the value of the virtual profile that is actually used for the run based on the name of the field.

String VirtualProfiles.FieldValueByIdx(int index)

When a script with virtual profile is run, the virtual profile index must be selected. This method will give you the value of the virtual profile that is actually used for the run based on the index of the field. Index must be between 0 and VirtualProfiles.FieldsCount() -1.