MWP scripting reference

Actions in MWP scripts can contain JavaScript code, and the commands documented 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 MWP Object Reference

Mobile Web Perspective uses the Mozilla SpiderMonkey JavaScript engine. This help page documents MWP-specific scripting commands, but basic JavaScript can also be used in MWP scripts.

The command reference below is separated into three sections:

DNS override

DNS override forces the retrieval of content from a particular domain or IP address. This allows you to compare performance of mobile sites across different environments such as development, QA and production.

DNS Override commands give you the power to specify the alternate domain or the IP you want all request to go to. This advanced scripting feature allows recording one script and iteratively running it across different domains and or IPs.

DNS Override does not affect the computer’s DNS settings; only MITE is affected.

There is no limit in the size of the DNS table with multiple AddDNSEntry calls in the script.

DNS override functions

AddDNSEntry(String IP, String hostname, [optional] int caseSensitive= 0);

IP: An IP address or a domain name where you want to redirect when the hostname  has to be resolved

hostname: Entry point in the DNS table is associated with this name.

caseSensitive: If set to 1 , the name of the host that is resolved will be compared respecting the case.

ClearDNSEntries();

Example:

AddDNSEntry("212.62.10.59",  "registration.ft.com");
 Start("registration.ft.com");
 ClearDNSEntries();
 Start("registration.ft.com");

Common scripting functions

Conditions:

  1. Can be applied on current page.
  2. Can be the first action.
  3. Updates the current page.

ClickAccessKey

Conditions: 1, 3
Parameters: 1
  • (String) AccessKeyaccesskey attribute of the link you want to click
Syntax
AccessKey("1");
Description Click on the element that defines this AccessKey as its HTML accesskey attributes.

ClickBack

Conditions: 1, 3
Parameters: 0
Syntax
ClickBack
Description Navigates back to the previous page.

ClickNameWithWildcards

Conditions: 1, 3
Parameters: 2
  • (String) LinkName – Wildcard expression will filter a list of all elements that correspond to this expression.
  • (Integer) Position – Position in the list of elements retrieved with the linkName pattern; the list index starts at 1.
Syntax Click on the first link that contains the pattern Total (* elements) .
ClickNameWithWildcards(“Total (* elements)”, 1);
Click on the first link that contains this pattern Matrix 2\** , e.g., any link that starts with Matrix 2* such as Matrix 2*2 , Matrix 2*4 , etc.
ClickNameWithWildcards(“Matrix 2\**”, 1);
Description Click the link using a wildcards. Wildcards are:
  • * to match any multiple occurrences of characters or numbers
  • ? to match only one character or one number
  • You can encode characters in the wildcard expression using \ (back slash).
  • \\ to match a \
  • \? To match a ?
  • \* to match a *

Notes

Use * before and after string as wild card to match any number of characters Match position is a number to indicate matching position: 1 is the first match, 2 is the second match, etc.
Conditions: 1, 3
Parameters: 4
  • (String) LinkName – name of the link you want to click.
  • (String) Url – URL of the link you want to click.
  • (String) AccessKey - accesskey attribute of the link you want to click.
  • (Integer) Position – position of the link you want to click.
Syntax
ClickOnLink(“Search”, “/searchaction”, “s”, 4);
ClickOnLink(“map.select://div[@id=’myID’]/span[2]”, “/searchaction”, “s”, 4);
Description Navigates to a page using the given LinkName , or Url , or Accesskey , or Position in the given order.

Notes

The first field will first look for an element with an id attribute with the LinkName, then checks if the name attribute of the element contains the LinkName , and then looks at the text of the link or the alt of the image.
LinkName can also use the extended syntax to point to a specific element using map.select:{Xpath of the element} . The URL field is like a wildcard and will look if the form/@action or a/@href contains the Url . If first field has no match, the action tries the URL. If URL has no match, the action tries the Access Key. If the Access Key has no match, the action tries to navigate by link position.

ClickPosition

Conditions: 1, 3
Parameters: 1
  • (Integer) Position - position of the link you want to click
Syntax ClickPosition(2);
Description Click the link at given position and navigates to the page.

Note

Use this action only when it make sense, because link position could change anytime.

Tip

Use SearchInPage to validate the page returned.

ClickUrl

Conditions: 1, 3
Parameters: 1
  • (String) Url - URL of the link you want to click
Syntax
ClickUrl(“/searchsction”);
Description Navigates to the page for which the URL is given as input. The URL field is like a wildcard and will check if the form/@action or a/@href contains the Url .

EnterValue

Conditions: 1, 3
Parameters: 2
  • (String) Name – name of the textarea field
  • (String) Value – value you want to set in the textarea field
Syntax
EnterValue(“my_textarea”, “any text value you want”)
EnterValue(“map.select://textArea[@class=’bodyMessage’]”, “Hi Eric”)
Description Enters the value to the element after matching the id or the name attribute of the element.
The name can also use the extended syntax to point to a specific element using map.select:{Xpath of the element} .

InputValue

Conditions: 1, 3
Parameters: 3
  • (String) Name – name of the input field
  • (String) Value – value of the input field
  • (Integer) Position – position of the input field – used only if name can’t match anything.
Syntax
InputValue(“my_edit”, “test”, 0);
InputValue(“map.select://INPUT[@class=’adress’][2]”, “777 mariners island”, 0);
Description This function will allow you enter text into an input field. Input the given value to the element selected by the matching id or name attribute. The name can also use the extended syntax to point to a specific element using map.select:{Xpath of the element} .

SearchInContent

Conditions: 1
Parameters: 3
  • (String) Value – Value you are looking for in the text of the page
  • (0/1) IsNotContain – Allows you to make sure the text is in the page or NOT in the page.
  • (0/1) CaseSensitive – Allow you to do a case-sensitive search.
Syntax
SearchInContent(“text to find”, 0, 0);

Note

Make sure you have “text to find “ defined.
Description Searches all the content of the page for the given value. IsNotContain and CaseSensitive switches can be used.
Conditions: 1
Parameters: 3
  • (String) Value – Value you are looking for in a link
  • (0/1) IsNotContain – Allows you to make sure the text is in the page or NOT in the page.
  • (0/1) CaseSensitive – Allows you to do case-sensitive search.
Syntax
 SearchInLink(“Search”, 0, 0); 

Note

A link should contain the word “Search “.
Description Searches in all collected links of the page for the given value. IsNotContain and CaseSensitive switches can be used.

SearchInPage

Conditions: 1
Parameters: 3
  • (String) Value - Value you are looking for in the current page including HTML tags and attributes (DOM in case of HTML page, SMS content in case of SMS)
  • (0/1) IsNotContain – Allows you to make sure the text is in the page or NOT in the page.
  • (0/1) CaseSensitive – Allows you to do case-sensitive search.
Syntax
 SearchInPage(“test”, 0, 0);
Description Searches in the content of page for the given value. IsNotContain and CaseSensitive switches can be used.

SearchInTitle

Conditions: 1
Parameters: 3
  • (String) Value – Title you want to check
  • (0/1) IsNotContain – Allows you to make sure the text is in the page or NOT in the page.
  • (0/1) CaseSensitive – Allows you to do a case-sensitive search.
Syntax
SearchInTtile(“Nike home”, 0, 0);
Description Searches in the title of a page for the given value. IsNotContain and CaseSensitive switches can be used.

SelectValue

Conditions: 1, 3
Parameters: 4
  • (String) Name – Name of the select or radio button or check box.
  • (String) Value – Value that has to be found in the option
  • (String) Label – If a check box or radio button, 1 or 0 to select or unselect
  • (Integer) Position – Position of the options – index starts at 0 .
Syntax Select the item Red in the combo box named myComboColor .
 SelectValue(“myComboColor”, “Red”, “”, 0);
Select the third item in the combo box named myComboColor .
SelectValue(“myComboColor”, “”, “”, 3);
Check the box named myCheckBox if it is not already checked.
SelectValue(“myCheckBox”, “”, “1”, 0);
Description Once a <select> tag is matched, the option is selected with the name or with the position. If used on input type radio or checkbox , if the value is 1 the item is selected, if 0 then it is unselected. The name can also use the extended syntax to point to a specific element using map.select:{Xpath of the element} .
Option and value are exclsuive; if name is not empty then position is not used.

SelectValueFilter

Conditions: 1, 3
Parameters: 4
  • (String) Name – Name of the selection box
  • (String) Value – Value that has to be found
  • (String) ValueNotToBeFound – Value that should not be found
  • (Integer) StartPosition – Index number of the option from where to start
Syntax Find the option Size avoiding the option [Choose a size] starting at 0 .
SelectValueFilter(“myCountry”, “Size”, “[Choose a  size]”, 0);
Description Select an option from a selection box with advanced options.

Start

Conditions: 2, 3
Parameters: 1
  • (String) Url - URL of the website to open
Syntax
Start(“www.keynote.com”);
Description Navigates to the given website. The input parameter is the URL of the website to open. The HTTP GET method is used.

Advanced and specialized functions

These scripting functions are intended for advanced users and Keynote personnel.

Conditions:

  1. Can be applied on the current page.
  2. Can be the first action.
  3. Updates the current page.
Conditions: SMS page only
Parameters: 0
Description Finds the link from SMS content and clicks that link in the current page and navigates to it.

WaitForContent

Conditions: 1, 3
Parameters: 3
  • (String) Text to Find
  • (0/1) Negate
  • (String) Xpath
Description Waits for the given the string to be displayed on the current page loaded by the internal browser.

WaitSMS

Conditions: 3
Parameters: 2
  • (String)
  • Integer
Description Waits for an SMS message. Takes the sender number as well as the maximum wait time as inputs.

WaitSMSFilter

Conditions: 2, 3
Parameters: 2
  • Integer
  • (Integer) WaitTime
Description Used for OTA transactions. After this call, all requests will be done using the LAN interface of the machine. The user agent string specified in the parameter will be used for these calls. To revert and keep using the OTA, stack use the UseDefaultProfile action.

WaitSMSFilterShow

Conditions: 2, 3
Parameters: 4
  • (String)
  • Integer
  • (String)
  • Integer
Description

AddCookie

Conditions: 2
Parameters: 4
  • (String) Name - Name of the cookie
  • (String) Value - Cookie value
  • (String) Domain - Domain the cookie belongs to
  • (String) Path - Path the cookie belongs to
Syntax
AddCookie(String Name, String Value, String Domain, String Path);
For example:
AddCookie("CookieTestName", "valuetest", ".google.com", "/");
Description Adding a custom cookie—the  cookie is attached to the HTTP request only if the cookie’s domain and path match the request URL.

AddCustomHeader

Conditions: 2
Parameters: 2
  • (String) Name - name of the header
  • (String) Value - header value
Syntax
AddCustomHeader("Name", "Value");
For example, to add a customer header to every new HTTP request:
AddCustomHeader("X-Keynote", "12340594309-42-40");
To edit an existing header:
AddCustomHeader("Accept-Language", "fr-fr");
Description Modifies/sets an HTTP header Value for the given header Name . The custom header is sent with every HTTP request.