This is the primary object for simulating user actions in Mozmill
boolean check(in Elem element, in boolean state); (deprecated) |
boolean click(in Elem element, in int left, int top); (deprecated) |
boolean doubleClick(in Elem element, in int left, in int top); (deprecated) |
boolean dragDropElemToElem(in Elem elementStart, in Elem elementFinish); |
boolean keypress(in Elem element, in string keycode, in object modifiers); (deprecated) |
boolean mouseDown(in Elem element, in int button, in int left, in int top); (deprecated) |
boolean mouseOut(in Elem element , in int button, in int left, in int top ); (deprecated) |
boolean mouseOver(in Elem element , in int button, in int left, in int top ); (deprecated) |
boolean mouseUp(in Elem element , in int button, in int left, in int top ); (deprecated) |
boolean mouseMove(in obj start, in obj dest); |
boolean radio(in Elem element); (deprecated) |
boolean rightClick(in Elem element, in int left, in int top); (deprecated) |
boolean screenShot(in Elem element, in string name, in boolean save, in Array<elem> highlights); |
boolean select(in Elem element, in int index, in string label, in string value); (deprecated) |
void startUserShutdown(in int timeout, in boolean restart); |
boolean type(in Elem element, in string text); (deprecated) |
void sleep(in int timeout); |
void waitFor(in func callback, in string message, in int timeout, in interval, in object this); |
void waitForElement(in Elem element, in int timeout, in int interval); (deprecated) |
void waitForEval(in string, expression, in int timeout, in int interval, in object subject); (deprecated) |
void waitForImage(in Elem element, in int timeout, in int interval); |
void waitThenClick(in Elem element, in int timeout, in int interval); (deprecated) |
void waitForPageLoad(in document, in int timeout, in int interval); |
boolean assert(in func callback, in string message, in object this); |
boolean assertChecked(in Elem element); |
boolean assertDOMProperty(in Elem element, in string attribute, in string value); |
boolean assertImageLoaded(in Elem element); |
boolean assertJS(in string expression, in object subject); (deprecated) |
boolean assertJSProperty(in Elem element, in string attribute, in string value); |
boolean assertNode(in Elem element); |
boolean assertNodeNotExist(in Elem element); |
boolean assertNotChecked(in Elem element); |
boolean assertNotDOMProperty(in Elem element, in string attribute, in string value); |
boolean assertNotJSProperty(in Elem element, in string attribute, in string value); |
boolean assertSelected(in Elem element, in string value); |
boolean assertText(in Elem element, in string text); |
boolean assertValue(in Elem element, in string value); |
void open(in string uri); |
void goBack(); |
void goForward(); |
void refresh(); |
document tabs.activeTab(); |
document tabs.getTab(int in index); |
void tabs.selectTabIndex(int in index); |
Attribute | Type | Description | |
---|---|---|---|
window | Window Object | A reference to the global window object the controller is active in | |
rootElement (2.0+) | MozMillElement | A reference to the root element in the window, wrapped inside of a MozMillElement. This is handy for sending global keystrokes to, e.g:
controller.rootElement.keypress('t', {'ctrlKey':true});will open a new tab. |
|
menus |
Node |
A set of attributes to access the menus and menu items as elements. Click here for information | |
tabs.activeTab |
DOMDocument | Returns the document that is rendered by the current active tab in the browser | |
tabs.activeTabIndex |
int | Returns the index number of the currently active tab. It is a browser specific method |
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Fires a click at the given checkbox element to ensure it is either checked or not.
boolean check( in Elem element, in boolean state );
element
state
true
if the action succeeds, otherwise false
.
controller.check(new elementslib.ID(controller.window.document, 'foo'), true);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Fires a normal (left) click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean click( in Elem element, in int left, in int top );
element
left
top
true
if the action succeeds, otherwise false
.
controller.click(new elementslib.ID(controller.window.document, 'foo')); // Or specify coordinates controller.click(new elementslib.ID(controller.window.document, 'foo'), 20, 10);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Fires a normal (left) double click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean doubleClick( in Elem element, in int left, in int top );
element
left
top
true
if the action succeeds, otherwise false
.
controller.doubleClick(new elementslib.ID(controller.window.document, 'foo')); // Or specify coordinates controller.doubleClick(new elementslib.ID(controller.window.document, 'foo'), 20, 10);
Drags the element specified by elementStart to the x,y coordinates of the element specified by elementFinish. Currently only works in content space (i.e. on a web page).
boolean dragDropElemToElem( in Elem elementStart, in Elem elementFinish );
elementStart
elementFinish
true
if the action succeeds, otherwise false
.
controller.dragDropElemToElem(new elementslib.ID(controller.window.document, 'foo'), new elementslib.ID(controller.window.document, 'bar'));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Fires a keypress for the given keycode. The modifiers are a JSON object that specifies what key modifiers should be pressed in conjunction with the given key code. The available attribute names for the modifier object are: ctrlKey, altKey, shiftKey, metaKey, and accelKey. Try to avoid the usage of ctrlKey and metaKey if the shortcut is a combination of Ctrl (Windows/Linux) and Cmd (Mac) and use accelKey instead which will work regardless of which operating system your test is executing on.
boolean keypress( in Elem element, in string keycode, in object modifiers );
element
keycode
modifiers
true
if the action succeeds, otherwise false
.
// Fire an escape key strokes at element foo: controller.keypress(new elementslib.ID(controller.window.document, 'foo'), 'VK_ESCAPE', {}); // Fire a simple key stroke at element foo using the control/command and shift keys controller.keypress(new elementslib.ID(controller.window.document, 'foo'), 'b', {shiftKey: true, accelKey: true});
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Simulates the left button being depressed on the mouse when the mouse is over the given element.
boolean mouseDown( in Elem element, in int button, [in int left], [in int top] );
element
button
left
top
true
if the action succeeds, otherwise false
.
controller.mouseDown(new elementslib.ID(controller.window.document, 'foo'));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Simulates the mouse leaving the area over an event without clicking on it. If the element is out of view, the element will be scrolled into view before initiating the mouseOut.
boolean mouseOut( in Elem element, in int button, [in int left], [in int top] );
element
button
left
top
true
if the action succeeds, otherwise false
.
controller.mouseOut(new elementslib.ID(controller.window.document, 'foo'));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Simulates the mouse entering the area over an event without clicking on it. If the element is out of view, the element will be scrolled into view before inititating the mouseOver
boolean mouseOver( in Elem element, in int button, [in int left], [in int top] );
element
button
left
top
true
if the action succeeds, otherwise false
.
controller.mouseOver(new elementslib.ID(controller.window.document, 'foo'));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Simulates the left button being released on the mouse when the mouse is over the given element.
boolean mouseUp( in Elem element, in int button, [in int left], [in int top] );
element
button
left
top
true
if the action succeeds, otherwise false
.
controller.mouseUp(new elementslib.ID(controller.window.document, 'foo'));
Simulates the mouse being moved from the start coordinates to the end coordinates.
boolean mouseMove( in document doc, [in list start], [in list dest] );
doc
start
dest
true
if the action succeeds, otherwise false
.
// Move the mouse from position (10,10) in the current tab to (20,20) controller.mouseMove(controller.tabs.activeTab, [10, 10], [20, 20]);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Selects the given radio button by firing a click at it.
boolean radio( in Elem element, );
element
true
if the action succeeds, otherwise false
.
controller.radio(new elementslib.ID(controller.window.document, 'foo'));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Fires a right click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean rightClick( in Elem element, in int left, in int top );
element
left
top
true
if the action succeeds, otherwise false
.
controller.rightClick(new elementslib.ID(controller.window.document, 'foo')); // Or specify coordinates controller.rightClick(new elementslib.ID(controller.window.document, 'foo'), 20, 10);
Takes a screenshot of the passed in window or DOM element. Screenshots can either be saved to the temporary directory or be returned to the reporting as a dataURL. An array of elements to be highlighted with a red rectangle can also be passed in.
boolean screenShot( in Elem element, in string name, [in boolean save], [in Array<elem> highlights] );
element
name
save
true
if the action succeeds, otherwise false
.
var elem = findElement.ID(controller.tabs.activeTab, 'elemID'); var child = elem.getNode().childnodes[0]; // Take a screenshot of 'elem' and draw a red rectangle around it's first child element controller.screenShot(elem, 'demo', true, [child]);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Handles selecting an option from a menu list or an HTML select element. The "element" corresponds to the list. There are multiple ways to select from such a list, either by "index", "label", or by the "value" associated with that option.
boolean select( in Elem element, in int index, in string label, in string value );
element
index
null
if you do not wish to specify an index. -1 will reset the selection.label
null
value
null
true
if the action succeeds, otherwise false
.
// Select only using the index controller.select(new elementslib.ID(controller.window.document, 'foo'), 2); // Select using the label of the given element controller.select(new elementslib.ID(controller.window.document, 'foo'), null, 'bar');
Creates a timeout window during which the browser is allowed to be restarted or shutdown, for example by selecting 'Quit' from the 'File' menu. If startUserShutdown() is called and the test does not restart or shutdown the browser within the specified timeout, the test will fail. The browser must also be shutdown within the same test that called startUserShutdown(). Note: This is only available in Mozmill 1.4.2 and later.
timeout
The number of milliseconds during which the browser is allowed to be restarted or shutdown
.restart
True if a restart is to be expected, false if a shutdown is to be expected.
None
controller.startUserShutdown(2000, false); controller.click(new elementslib.Elem(controller.menus["file-menu"].menu_FileQuitItem));
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Types a string of text at the given element.
boolean type( in Elem element, in string text );
element
text
true
if the action succeeds, otherwise false
.
controller.type(new elementslib.ID(controller.window.document, 'foo'), 'some text to type');
Causes the test to pause its execution until "timeout" milliseconds have passed. This is the least granular of the wait methods and is NOT encouraged to be used. It is only included here because it is sometimes useful when debugging. You should use other wait methods in your tests in order to ensure your tests are more deterministic.
void sleep( in int timeout );
timeout
None
// Sleeps one second controller.sleep(1000);
Waits until the callback handler returns true. The handler gets called every "interval" milliseconds, and if "timeout" milliseconds have passed without the handler return true, it gives up and causes the test to fail. If you use the defaults, then it will check the return value once every 100ms and will throw an error after 30 seconds have passed.
void waitFor( in func callback, in string message, in int timeout, in int interval, in object this );
callback
message
timeout
interval
this
None
// Accept the default settings var value = { message: "g" }; controller.waitFor(function () { return value.message === 'foo'; }, "This is expected to fail."); // Wait until the location bar is visible, check every 100ms, and if it isn't true by 1000ms then throw an error. var locationBar = new elementslib.ID('urlbar'); controller.waitFor(function () { return locationBar.getNode().visibility === true; }, "Location bar should be visible", 1000, 100);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Waits for the "element" to appear in the user interface (for instance if you wanted to wait for part of a page or dialog to load). It checks for "element" every "interval" milliseconds, and gives up if "timeout" milliseconds have passed without the "element" appearing, causing the test to fail. If you accept the defaults, it will check for the element every 100ms and will throw an error if 30 seconds pass without the element appearing.
void waitForElement( in Elem element, in int timeout, in int interval );
element
timeout
interval
None
// Typical usage - accept defaults. See waitForEval() to see non-default operation controller.waitForElement(new elementslib.ID(controller.window.document, 'foo'));
Removed as of Mozmill 2.0 - This method was removed due to a potential security vulnerability. Use waitFor() instead.
Waits for the JavaScript "expression" to be true. It checks to see if the expression is true once every "interval" milliseconds, and if "timeout" milliseconds have passed without the expression becoming true, it gives up and causes the test to fail. If you use the defaults, then it will check the expression once every 100ms and will throw an error after 30 seconds have passed. The subject parameter which is passed as last argument will be substituted with the "subject" string inside the expression string. This method is deprecated, use the waitFor
method instead.
void waitForEval( in string expression, in int timeout, in int interval, in object subject );
expression
timeout
interval
subject
None
// Accept the default settings controller.waitForEval('foo==true'); // Wait until the location bar is visible, check every 100ms, and if it isn't true by 1000ms then throw an error. let locationBar = new elementslib.ID('urlbar') controller.waitForEval('subject.visibility == true', 1000, 100, locationBar.getNode());
Waits for the image represented by "element" to appear in the user interface. It checks for the image every "interval" milliseconds, and gives up if "timeout" milliseconds have passed without the "element" appearing, causing the test to fail. If you accept the defaults, it will check for the image every 100ms and will throw an error if 30 seconds pass without the image appearing.
void waitForElement( in Elem element, in int timeout, in int interval );
element
timeout
interval
None
// Typical usage - accept defaults. See waitForEval() to see non-default operation controller.waitForImage(new elementslib.ID(controller.window.document, 'foo'));
This is a browser specific method. It blocks the test until the current page completes loading.
void waitForPageLoad( in DOMDocument document, in int timeout, in int interval );
document
timeout
interval
None
// Waits for the current tab to load, timing out after 3 seconds have passed and
// it will check if the page is loaded every 100ms
controller.waitForPageLoad();
// Waits for the current page to load and will timeout once the given number of
// milliseconds have passed. For example, this times out after 1 second:
controller.waitForPageLoad(1000);
// The third version allows you to specify each parameter. This allows you to specify
// what document is loading, the time that it must load within and how often to check that
// loading is complete. For example, this waits for the page in tab 3 to load, and will
// check whether that page is loaded every 500ms, and will timeout after 2s have passed.
controller.waitForPageLoad(controller.tabs.getTab(3), 2000, 500);
Deprecated as of Mozmill 2.0 - Use the mozmill element object instead.
Waits for the "element" to appear in the user interface. It checks for "element" every "interval" milliseconds, and gives up if "timeout" milliseconds have passed without the "element" appearing, causing the test to fail. Once "element" appears, a click event is immediately fired at it. This is a simple shortcut API for the common pattern of waiting for an element to appear before firing a click event on it.
void waitThenClick( in Elem element, in int timeout, in int interval );
element
timeout
interval
None
// Typical usage - accept defaults. See waitForEval() to see non-default operation controller.waitThenClick(new elementslib.ID(controller.window.document, 'foo'));
Asserts that the callback function returns true.
boolean assert( in func callback, in string message, in object this );
callback
message
this
Boolean - returns true if assertion holds true, returns false if assertion is not true
// Run specific javascript that evaluates to a non-zero value controller.assert(function() { return 2 > 1; }); // Check if an array has the value as element (This will raise an exception with the given message) var value = 5; var items = [1, 2, 3, 4]; controller.assert(function() { return items.indexOf(value) !== -1; }, "The array has '5' as element.");
Asserts that the passed-in checkbox "element", is checked. It will cause a failure if the checkbox is not checked. Returns true if the box is checked, false if not.
boolean assertChecked( in Elem element );
element
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertChecked(new elementslib.ID(controller.window.document, 'foo'));
If the value parameter is not specified, asserts that the given DOM attribute exists for the given element. If the value parameter is specified, asserts that the given DOM attribute on the given element is the specified value. If the assertion passes, it returns true, otherwise, it returns false and marks a failure in the test. Note: This method is only available in Mozmill 1.4.2 and later.
boolean assertDOMProperty( in Elem element in string attribute, [in string value] );
element
attribute
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
// True if the DOM attribute called 'class' exists controller.assertDOMProperty(new elementslib.ID(controller.window.document, 'foo'), 'class'); // True if the DOM attribute called 'class' has a value of 'bar' controller.assertDOMProperty(new elementslib.ID(controller.window.document, 'foo'), 'class', 'bar');
Asserts that the image refrerenced by "element" is loaded. It will cause a failure if the image is not loaded. Returns true if the image is loaded, false if not.
boolean assertImageLoaded( in Elem element );
element
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertImageLoaded(new elementslib.ID(controller.window.document, 'foo'));
Removed as of Mozmill 2.0 - This method was removed due to a potential security vulnerability.
Asserts that JavaScript expression evaluates to true or to a non-zero value. You can optionally pass in an object for the "subject" parameter and that object will be substituted for the string "subject" in the expression.
boolean assertJS( in string expression, in object subject );
expression
subject
Boolean - returns true if assertion holds true, returns false if assertion is not true
// Run specific javascript that evaluates to a non-zero value controller.assertJS('2 > 1'); // Check if an array has three elements (this one would return false and cause a failure) var items = ['1', '2', '3', '4']; controller.assertJS('subject.length == 3', items);
If the value parameter is not specified, asserts that the given Javascript object property exists for the given element. If the value parameter is specified, asserts that the given Javascript object property on the given element is the specified value. If the assertion passes, it returns true, otherwise, it returns false and marks a failure in the test. Note: This method is only available in Mozmill 1.4.2 and later.
boolean assertJSProperty( in Elem element in string attribute, [in string value] );
element
attribute
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
// True if the Javascript object property called 'class' exists controller.assertJSProperty(new elementslib.ID(controller.window.document, 'foo'), 'class'); // True if the Javascript object property called 'class' has a value of 'bar' controller.assertJSProperty(new elementslib.ID(controller.window.document, 'foo'), 'class', 'bar');
Asserts that the given element exists. If the element does not exist, this returns false and marks a failure in the test. Note that this tests existence, not visibility. If the element is not visible, but it does exist in the DOM, this will return true.
boolean assertNode( in Elem element );
element
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertNode(new elementslib.ID(controller.window.document, 'foo'));
Asserts that the given element DOES NOT exist. If the element does not exist, this returns true and if it does exist, it returns false and marks a failure in the test. Note that like assertNode
this tests existence, not visibility.
boolean assertNodeNotExist( in Elem element );
element
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertNodeNotExist(new elementslib.ID(controller.window.document, 'foo'));
Asserts that the given element is not in a "checked" state. So, if the element is unchecked, this returns true, otherwise false.
boolean assertNotChecked( in Elem element );
element
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertNotChecked(new elementslib.ID(controller.window.document, 'foo'));
If the value parameter is not specified, asserts that the given DOM attribute does not exist on the given element. If the value parameter is specified, asserts that the given DOM attribute for the given element is not equal to the given value. If the assertion passes, it returns true, otherwise, it returns false and marks a failure in the test. This is very useful for asserting that various controls are not disabled, options are not selected etc. Note: This method is only available in Mozmill 1.4.2 and later.
boolean assertNotDOMProperty( in Elem element in string attribute [in string value] );
element
attribute
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
// True if there is no DOM attribute called 'disabled' controller.assertNotDOMProperty(new elementslib.ID(controller.window.document, 'fooControl'), 'disabled'); // True if the DOM attribute called 'name' doesn't have a value of 'bar' controller.assertNotDOMProperty(new elementslib.ID(controller.window.document, 'fooControl'), 'name', 'bar');
If the value parameter is not specified, asserts that the given Javascript object property does not exist for the given element. If the value parameter is specified, asserts that the given Javascript object property for the given element is not equal to the given value. If the assertion passes, it returns true, otherwise, it returns false and marks a failure in the test. This is very useful for asserting that various controls are not disabled, options are not selected etc. Note: This method is only available in Mozmill 1.4.2 and later.
boolean assertNotJSProperty( in Elem element in string attribute [in string value] );
element
attribute
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
// True if there is no Javascript object property called 'disabled' controller.assertNotJSProperty(new elementslib.ID(controller.window.document, 'fooControl'), 'disabled'); // True if the Javascript object property called 'name' doesn't have a value of 'bar' controller.assertNotJSProperty(new elementslib.ID(controller.window.document, 'fooControl'), 'name', 'bar');
Asserts that the given drop-down (or option) element has the given value selected. It uses the specified value of the selected option to verify this, you will have to usually look at the DOM Inspector to determine what this value should be.
boolean assertSelection( in Elem element, in string value );
element
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertSelected(new elementslib.ID(controller.window.document, 'foo'), 'optionvalue');
Asserts that the given element's innerHTML is equal to a given string of text.
boolean assertText( in Elem element, in string text );
element
text
Boolean - returns true if assertion holds true, returns false if assertion is not true
// Simple use for text boxes. controller.assertText(new elementslib.ID(controller.window.document, 'foo'), '<b>bar</b>'); // If you had a XUL Description field of the form: <description id="mydesc">Some text here</description> // Then you could use this statement to verify the "Some text here" string: controller.assertText(new elementslib.ID(controller.window.document, 'mydesc'), '<i>Some text here</i>');
Asserts that the element contains the given value. This is typically used with input controls, like form elements, or textboxes. A primary use case is to shortcut when looking for the "value" attribute and ascertaining that it contains a certain value. You could of course just use the assertDOMProperty
method.
boolean assertValue( in Elem element, in string value );
element
value
Boolean - returns true if assertion holds true, returns false if assertion is not true
controller.assertValue(new elementslib.ID(controller.window.document, 'foo'), 'bar');
Opens a given URI in the browser.
void open( in string uri );
uri
None
controller.open('http://www.mozilla.org');
Causes the browser to go back one step into the history for this page.
boolean goBack();
None
None
controller.goBack();
Causes the browser to go forward one step into the back/forward history for this page.
void goForward();
None
None
controller.goForward();
Causes the browser to refresh the current page.
void refresh();
None
None
controller.refresh();
Gets a reference to the document rendered by the tab corresponding to the given index.
DOMDocument tabs.getTab();
index
DOMDocument
let doc = controller.tabs.getTab(0); let fooelement = doc.getElementById('foo');
Switches to a tab based on the given zero-based index. This is the equivalent of clicking on the tab in the tab bar with the mouse to "focus" a tab.
void tabs.selectTabIndex();
index
None
controller.tabs.selectTabIndex(0);