Web Object API
Squish for Web provides a comprehensive API for Web Objects, which is documented here in its entirety. Some of these APIs are also available when testing embedded web browsers in other Squish editions.
Testing custom AJAX/DHTML/JavaScript widgets
The Web Object Extension API explains how to support testing of custom AJAX/DHTML/JavaScript widgets.
Web Object API Functions
Changes the active tab in the browser | |
Returns the active browser tab. | |
Connects Squish to an already running web browser instance. | |
Automates interaction with a native browser's authentication dialog. | |
Returns a list of active BrowserTab. | |
Cancels the JavaScript 'prompt' dialog. | |
Simulates choosing an HTML color from a color picker. | |
Simulates user interaction with a date picker. | |
Automates interaction with a file chooser. | |
Forces a refresh of Squish's internal object cache. | |
Clicks a button. | |
Clicks on an item in a view widget. | |
Clicks on an anchor (hyperlink). | |
Clicks on a tab in a tab widget. | |
Clicks expand/collapse on a tree item. | |
Clicks 'Ok' in a JavaScript alert dialog. | |
Clicks 'Yes' on a JavaScript 'confirm' dialog. | |
Types text into a JavaScript 'prompt' dialog. | |
Closes the browser window. | |
Double-clicks the mouse on a widget. | |
Performs a drag and drop operation. | |
Evaluates a string of JavaScript code. | |
Returns true if a browser tab accessible to Squish has a matching context. | |
Installs a global event handler. | |
Returns true if a native browser dialog is open. | |
Returns true if a browser is running and hooked to Squish. | |
Returns true if the page has been completely loaded. | |
Returns the text reported by the last 'alert' function. | |
Returns the text reported by the last 'confirm' function. | |
Returns the default text from the last 'prompt' dialog. | |
Returns the text from the last 'prompt' dialog. | |
Clicks the mouse on the specified widget. | |
Simulates a native mouse click on a given widget/position. | |
Opens a new tab in the browser, loading a given URL. | |
Tries to raise the browser window to the top of the stack. | |
Reconnects Squish to a web browser. | |
Returns a JsObject which has the result of evaluating a JavaScript snippet. | |
Scrolls the browser so that a given widget is visible. | |
Selects options in form elements. | |
Sends an event to an object. | |
Sets input focus on a particular element. | |
Sets the current frame in a webpage with frames. | |
Sets the text of an editable form element. | |
Starts the browser and loads a URL. | |
Functions to support separate drag and drop operations. | |
Clicks to toggle an expandable section header. | |
Types text into an editable form element. | |
Uninstalls an event handler. | |
Waits for an item to be visible, enabled in a CalendarView or CustomItemView. |
Web Object API Classes and Objects
Provides information about the currently-used browser. | |
Provides operations on/information about a browser tab. | |
Represents an RGB color + alpha value. | |
HTML Anchor (hyperlink) element | |
A JavaScript Array | |
API for HTML Buttons and submit input elements. | |
Base class for all HTML input button types. | |
API to support calendar events. | |
API to support web calendar widgets. | |
API for HTML CheckBox buttons. | |
API for HTML color picker elements. | |
API for supporting highly customized HTML buttons. | |
Abstract base class for highly-customized HTML buttons. | |
API to support customized checkboxes. | |
API to support custom combo boxes. | |
Abstract API for accessing items in views. | |
Abstract item view API. | |
A customized radio button. | |
A customized multi-selection list. | |
A customized text editor field. | |
An HTML date picker. | |
Represents a web page's HTML document. | |
An HTML expandable section header element. | |
API for HTML form elements. | |
Base class for HTML form elements. | |
API for HTML image input elements. | |
API for HTML menus and menubars. | |
API for HTML menu buttons. | |
API for HTML menu items. | |
Ultimate base class for HTML elements. | |
API for HTML option elements. | |
API for HTML progress bars. | |
API for HTML radio buttons input elements. | |
API for HTML selection input elements. | |
API for accessing an element's CSS. | |
API for HTML tab widget tabs. | |
API for HTML tab widgets. | |
API for HTML tables. | |
API for HTML text input elements. | |
API for HTML textarea input elements | |
Base class for HTML text input elements. | |
When an XPath expression is evaluated, this is returned. | |
API for accessing references to JavaScript objects. |
Web Object API Function Parameters
In all the functions listed here that take an objectOrName
argument, the argument can be a reference to an object or the name of an object.
Some of the Web Object API functions can take a modifierState
argument which indicates which special keys are pressed at the time of a mouse click, and if the right button is clicked. Tthe default is the left button.
The modifierState
can be one or more of the following: HTML_Event.AltKey
, HTML_Event.ControlKey
, HTML_Event.ShiftKey
, HTML_Event.RightButton
. The form shown here works for Python and JavaScript. For Perl and Ruby replace the period with two colons, e.g., HTML_Event::ControlKey
, and for Tcl use the enum function, e.g., enum HTML_Event Control
.
The modifierState
values can be combined by using bit-wise OR, for example (JavaScript, Perl, JavaScript, Ruby) mouseClick(..., HTML_Event.ShiftKey | HTML_Event.RightButton)
.
Interacting with Multiple Tabs or Browser Windows
Squish supports interaction with multiple browser windows or tabs for Firefox, Microsoft Edge, Safari on Mac, Google Chrome and Chromium-based Applications at the moment. It uses the concept of an active browser tab to execute clicks in or query object information. So whever the active tab is changed by opening a new tab or window or using the dedicated tab functions provided by Squish for Web the interactions and object lookups will happen in the newly activated tab.
The individual tabs are represented by the BrowserTab Class and can be accessed either through the activeBrowserTab(), browserTabs() or by using multi-property names as described for the BrowserTab Class.
The support for Chromium-based Applications is somewhat limited as Squish can only access the contents of multiple web views inside such an application. If the application allows changing which web views are visible and which ones are hidden - for example because it uses a tab widget to show them - Squish cannot record or replay such changes.
Native Variants of Web Functions
Many of the interaction functions (such as, mouseClick, setText, clickItem, or selectOption) that do not mention native generate events inside the web page on the JavaScript level. Whereas the ones that do mention native generate operating system events.
The native variants need to properly determine the place of the object on the screen, which can be a challenge depending on the browser and web site content. They also require that nobody interacts with the system and disturbs them. The functions that use JavaScript events generally work even if you use the mouse or keyboard for something else.
However, certain interactions are limited by browsers for security reasons, so they must not be triggered from the JavaScript on the web site. Further, the JavaScript-based functions might not be able to replicate the original intent properly. For example setText cannot properly generate keyboard events in JavaScript, so it sets the value of the field and triggers a change event, which is not sufficient to make some web sites aware of the new value.
Synthetic Properties in Web Objects
The objects representing HTML elements in the DOM tree provide access to the common properties and attributes of HTML elements according to HTML standards. In addition to that, they may provide Synthetic Properties for convenience. Most Synthetic Properties in Squish for Web can not be used as part of realnames for looking up web objects, as Squish provides them through a mechanism that is not available directly for object lookup. So for example the HTML_Object.height property cannot be used in realnames. There are some exceptions to this rule noted in the individual property documentation, for example HTML_Object.simplifiedInnerText.
Web Object API Classes and Objects (Tree)
Here are some quick links to the Web Object API's objects and classes (shown in terms of their inheritance hierarchy):
- Browser Object
- BrowserTab Class
- HTML_Object Class
- HTML_Anchor Class
- HTML_Array Class
- HTML_CalendarEvent Class
- HTML_ColorField Class
- HTML_CustomButtonBase Class
- HTML_CustomCheckbox Class
- HTML_CustomItem Class
- HTML_CustomRadioButton Class
- HTML_DateChooser Class
- HTML_Document Class
- HTML_ExpandableSectionHeader Class
- HTML_Form Class
- HTML_FormElement Class
- HTML_Menu Class
- HTML_MenuItem Class
- HTML_Option Class
- HTML_ProgressBar Class
- HTML_Style Class
- HTML_Table Class
- HTML_Tab Class
- HTML_TabWidget Class
- HTML_XPathResult Class
- JsObject
Deprecated Functions
Returns an HTML_Array of references to hooked browser windows. | |
Returns the context string of a given window. | |
Returns the currently active browser window. | |
Returns true if an window with matching URL can be accessed by Squish. | |
Opens a web browser and loads a given URL. | |
Changes the active Window. | |
Waits for context to be loaded. |
© 2024 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.