This topic explains how to modify the user actions simulated by a web scenario.
Sections include:
To view and modify the action taken by a specific scenario step:
You can use data sources to parameterize user actions—for instance, to have a type action iterate through a set of different values stored in an Excel spreadsheet.
For details on how to add and use data sources to parameterize tests, see Parameterizing Tests with Data Sources, Variables, or Values from Other Tests. |
The element that is the source of a user action will be highlighted with a solid blue border in the scenario step’s Pre-Action Browser Contents tab.
To quickly change the target of a user action, right-click the related element in the Pre-Action Browser Contents tab, then choose the appropriate Modify command.
If the user action that you want to change is not associated with a specific element (for instance, a "close" or "navigate" action), you can right-click anywhere in the Pre-Action Browser Contents tab, then choose Change User Action.
This opens the User Action tab, which allows you to modify the target.
As you create and modify user actions for page elements, you may want to inspect the HTML to determine if you are adding actions to the appropriate elements.
To see the HTML for a given element by right-click that element, then choose Inspect <Element> from the shortcut menu.
Understanding Preset ActionsYou can configure most common user actions by selecting from the list of preset actions, then customizing them as needed to suit your needs. The available preset actions are described below. |
The configuration section for many preset user actions contains an "Element Locator" section. This section allows you to specify the element associated with the action via element properties, XPath, or script.
Use XPath allows you to enter an XPath to be used as an identifier.
Use Script allows you to enter a script that defines the desired user action.
Use Element Properties allows you to specify properties via the following controls:
Also, note that many actions allow you to configure Window Name. This allows you to specify the name of the window you would like the action to occur in. Leaving this field blank indicates that the default window will be used.
Specifying Specialized Element Locators (CSS, ALT attribute, etc.)With Selenium, you can specify a variety of specialized element locators by setting Element Locator to Use XPath, then setting one of the available locator prefixes to the desired value. Available prefixes are:
For example, to use the CSS locator Errors for Popup DialogsIf one of the three types of JavaScript popup dialogs (alert, confirm, and prompt) opens in an action other than Accept Script Dialog, Dismiss Script Dialog, or Type into Script Dialog, then an error will be reported—unless you are using the Selenium engine and this is the last test in your scenario. If a popup dialog opens during a wait action on the Selenium engine, an error will not reported. Accept Script DialogSelenium Only This action presses the OK button on any of the three types of JavaScript popup dialogs: alert, confirm, and prompt. AddselectionFor a multiselect combo box, this action adds one option to the selection. This can be the first selection or an additional selection. To select multiple items, use this action multiple times. AnsweronnextpromptDeprecated for 9.8—not recorded with the current engine This action adds text to a prompt dialog. This action is deprecated; use Accept Script Dialog, Type into Script Dialog, and Dismiss Script Dialog instead. Configuration notes:
AssertalertDeprecated for 9.8—not recorded with the current engine This action validates the text in an alert dialog message. This action is deprecated; use Accept Script Dialog, Type into Script Dialog, and Dismiss Script Dialog instead. Configuration notes:
AssertconfirmationDeprecated for 9.8—not recorded with the current engine This action validates the text in a confirmation dialog message. This action is deprecated; use Accept Script Dialog, Type into Script Dialog, and Dismiss Script Dialog instead. Configuration notes:
AssertpromptDeprecated for 9.8—not recorded with the current engine This action validates the text in a prompt dialog message. This action is deprecated; use Accept Script Dialog, Type into Script Dialog, and Dismiss Script Dialog instead. Configuration notes:
CheckThis action checks a check box. ChoosecancelonnextconfirmationDeprecated for 9.8—not recorded with the current engine This action presses the Cancel button in a confirm dialog. This action is deprecated; use Accept Script Dialog, Type into Script Dialog, and Dismiss Script Dialog instead. Configuration notes:
ClickThis action clicks the specified element. Configuration notes:
CloseThis action closes the specified window. Dismiss Script DialogSelenium Only For popup dialogs (alert, confirm, and prompt), this action either presses the Cancel button (for confirm and prompt) or presses the X (for all 3 types of alert dialogs). DoubleclickThis action double-clicks an element. DragdropThis action drags one element to another location. Configuration notes: There are 4 ways to indicate how to move an element. For all of the following indicators, actions start at the element that will be dragged. All numbers are in pixels. The 4 options are
Execute JavaScriptSelenium Only This action executes the specified JavaScript within the context of the current web page. The specified JavaScript will execute in the same frame as the element defined by the element locator. If no element is defined, the JavaScript will execute in the top-most frame. To configure this user action:
Configuration notes:
Example - Hovering over elements:
Note that this code executes an "onMouseOver" event on an element. In most cases, this will cause the hover behavior to trigger. In some cases, this is insufficient and more code will be necessary to trigger the hover. Example - Clicking hidden elements:
Note that this code executes the click function on an element. In most cases, this will cause the click behavior to trigger. In some cases, this is insufficient and more code will be necessary to trigger the click. FireeventTargeted for Legacy This action fires a JavaScript event on a particular page element. This covers JavaScript events that are defined in the code of the page (not visible to the user). Configuration notes:
Go BackThis action presses the browser’s Back button. No arguments are needed. Go FowardThis action presses the browser’s Forward button. No arguments are needed. Keydown / Keypress / KeyupTargeted for Legacy These actions fires keydown, keypress, or keyup JavaScript events on an element. Configuration notes:
Maximize WindowSelenium Only This action maximizes the specified browser window. Configuration notes:
Mousedown / Mouseover / MouseupTargeted for Legacy These actions fire mousedown, mouseover, or mouseup JavaScript events on an element. Configuration notes:
NavigateThis action navigates to the provided URL as though it was entered in the browser’s URL bar. Configuration notes:
New BrowserLegacy Only This action opens a new browser populated with the page at the specified start URL. OtherEnables you to add a custom action. RefreshThis action has presses the Refresh button. RemoveselectionIn a multiselect combo box, this action removes one option from the selection. This is the equivalent of shift-clicking on a selected combo box selection. To remove multiple items, use this action multiple times. Scroll BySelenium Only This action scrolls the web application by the number of pixels specified for the x and y axis. Negative values indicate "scroll left" (for the x-axis) or "scroll up" (for the y-axis). Scroll ToSelenium Only This action scrolls the web application to the specified pixel position (x and y axes). SelectIn a single-select combo box, this action selects a single option in the combo box. If an option is already selected, this action will change the selection. Configuration notes:
SubmitThis action submits a form, or an element within a form, to the remote server. Configuration notes:
TypeThis action types the specified text into the specified element.
Type (Without Focus) Legacy OnlyThis action types the specified text into the specified element without any focus.
Type into Script Dialog Selenium OnlyThis action enters text into a prompt dialog. Configuration notes:
Type PasswordThis action types specified text into the specified element. The text will be masked in the field as well as encrypted upon storage.
Type Password (Without Focus)Legacy Only This action types the specified text into the specified element without any focus. The text will be masked in the field as well as encrypted upon storage.
UncheckThis action unchecks/clears a checked check box. WaitThis action simulates the browser waiting the specified number of milliseconds before continuing to the next step.
|
def typeTestThenTab() { return "test\uE004"; } |
Note that this does NOT act as a key modifier. For example, you CANNOT perform a "control-click" by sending the control character and then performing a click. Sending the character simulates a user pressing and releasing the corresponding button.
With SOAtest 9.9.2 and earlier, it was possible to add custom user actions that could be called from Browser Playback tools. These custom actions applied only to executing browser scenarios using the legacy engine. They could be added in two ways: by defining new functions within UserCustomizableOptions.js or in BrowserDriver.js. Parasoft generally recommend defining the custom actions in UserCustomizableOptions.js, but in some cases we suggested using BrowserDriver.js in order to support Chrome.
These functions would take the form
_wk_BrowserDriver.prototype.doXXX = function(locator) { ....
where XXX is the name of the custom user action.
For example, you could have UserCustomizableOptions.js define an action such as the following:
_wk_BrowserDriver.prototype.doContextMenu = function(locator) { var element = this.findElement(locator); _wk_HTMLUtil.triggerMouseEvent(element, 'contextmenu', true); }; |
You would then reference this custom action in SOAtest by choosing an Other action and typing in contextmenu
(legacy engine only).
Starting with SOAtest 9.9.3, adding custom actions like this is no longer supported on Firefox (due to new Firefox extension requirements). Properly migrated custom user actions are still supported for the legacy engine and for playback on Chrome or Internet Explorer.
To migrate your existing custom actions:
_wk_
, change them to reference com.parasoft.extension
. In other words, change _wk_XXX
to com.parasoft.extension.XXX
For example, the example script above changes to
com.parasoft.extension.BrowserDriver.prototype.doContextMenu = function(locator) { var element = this.findElement(locator); com.parasoft.extension.HTMLUtil.triggerMouseEvent(element, 'contextmenu', true); } |
Note that wk_BrowserDrive
r became com.parasoft.extension.BrowserDriver
and _wk_HTMLUtil
became com.parasoft.extension.HTMLUtil
.