Expect/Reply Types
The Test Case can specify the Expect Type as a Message, Function, or Notification.
Message
The Message type is meant for testing Web Chat applications with normal conversation flow between the Client and Agent. This will be entered as text that will be matched exactly as it is received either by the Agent or the Client.
If a Message type is used, you must specify which Message Resolver to use. This enables the script to locate the Agent’s messages and to send the Client's reply back.
When using the Message type, the Expect field can utilize a wildcard tag {*} to ignore parts of the expected message from the Agent.
Conditions and Restrictions
- Only allowed in the Expect field
- May be used multiple times in the same prompt
- Cannot be followed by another wildcard tag
Examples of usage:
- Very changeable parts of prompt text such as a changing time or Agent's name
- Unrecognized words
For example: A Message Resolver can be created when you import a Web Test Case for chat testing. If the uploaded document contains an element for the Message Resolver, this will be created (or replaced if it matches an existing name).
Expect
Matches("p.agentsays:last-child", "{Value}")
Reply
SetValue("#chatTextArea", "{Value}");
FireEvent("input[type=submit]", "click");
Matches("p.customersays:last-child", "{Value}");
Here the
Expect section is trying to match the expect
text from the Step (passed in using
{Value}
).
The
Reply section sets the value of an input field
with an ID of
chatTextArea
with the value supplied by the Step
(passed in using
{Value}
). Then the function clicks on a
Submit button and waits for the echo of the
customer's message to appear in the Chat window.
Web Test Cases support additional tags such as the Choice Tag, see the full list of Tags available to use on the Tags Article Here.
Function
The Function type allows you to call a number of predefined functions to perform a scripted action. A global function list is available to all scripts while a more specific set of functions is available for the currently logged-in Account. At present, these custom Account functions will need to be set up by Cyara Professional Services.
Global Functions
The following section provides the list of supported global function calls. The arguments named Script can contain any valid Javascript that runs within the context of the executing page. When a frame is referenced as an argument to a function, this can either be by an index value (number) or by the name of the frame.
Frame Wildcards
Additionally you can instead include a wildcard of * for a frame reference, which will automatically identify the frame that has defined the selector of your function. Refer to the example below which will match the text "Welcome Back" inside any frame.
Contains("Welcome back", "*")
You can add comments inside a block of script in either the
Expect or
Reply fields. Any text wrapped inside
/* */
will be removed.
For example:
/* This will check the page heading for Welcome Back */
Contains(null, "Welcome back", null,
"document.querySelector('H1').innerText")
Contains(null, "Welcome back", null,
"document.querySelector('H1').innerText");
/* GetCookie("CookieName"); */
BeginFrame("frame", "selector")
When the "frame" is a wildcard the frame will be selected bu inspecting all frames for the supplied selector.This is useful if you want to use the JavaScript function against a wildcard frame.
This function executes any subsequent Steps against that
iframe
until an
EndFrame
function is reached.
BeginFrame("1")
BeginFrame("topframe")
EndFrame()
Ends the frame context supplied by a previous call to
BeginFrame
.
Contains
Searches for a string value within the result string of the
supplied
script
or
selector
.
Contains("selector", "value", "frame", "script")
This is a polling action that performs a case-insensitive text
comparison of the results of the supplied
script
or
selector
and looks for the occurrence of the
supplied value. If the value is not found, the process is repeated, with a
delay of 250 milliseconds (defined by the Configuration Setting
DomUpdatedSleepTime
). If the timeout for the Step is
reached, the function fails.
Example | Description |
---|---|
|
Matches the text "Welcome Back" anywhere within the results of the script. |
|
Matches the text "Welcome Back" anywhere within the H1 heading. |
|
Matches the text "Welcome Back" inside the last paragraph of a frame at index position 1. |
BeginShadowRoot
Allows for native support for navigating the DOM to traverse shadow root elements.
BeginShadowRoot("elem1", "elem2", ...")
A shadow dom is unaddressable from a normal selector. This function will help to write test scripts for sites that use the shadow dom. You can pass 1 or more arguments for a selector that contains the shadow root. Once the innermost root has been identified, all future selectors will perform against this document.
The example below will locate an element identified by the selector shadow-root-1 and will locate another element shadow-root-2 within its own DOM. The FireEvent function will then call the click event on the button element found under shadow-root-2.
BeginShadowRoot("shadow-root-1", "shadow-root-2");
FireEvent("button", "click");
EndShadrowRoot();
EndShadrowRoot()
EndShadrowRoot
Ends a previously defined shadow root context.
EndShadrowRoot()
FireEvent
Executes an event on a given element.
FireEvent("selector", "event", "frame")
This function is useful for executing any number of available events for a particular element such as submitting a form, focusing an input element, or clicking a link.
If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Submits the first form found on the page. |
|
Locates a link that navigates to the
home.html page and clicks it.
|
GetCookie
Gets a named cookie and stores it with the results metadata.
GetCookie("CookieName")
Reads the value of a cookie from the supplied name and stores this
in the metadata of the test result. The name of the cookie is case-insensitive.
Cookies are not accessible when using
localhost
domains (the browser will consider a
domain with less than two dots invalid).
Example | Description |
---|---|
|
Gets a cookie called
jspsessionid and records this in the test
results metadata.
|
GetText
Gets the text from the supplied
selector
and optionally parses and stores it in the
results metadata.
GetText("selector", "regex", "metakey", "frame")
Gets the inner text of the element from the supplied
selector
. An optional regular expression can be used
to extract portions of the text and optionally store this in the results
metadata with the supplied name.
If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Gets the text from the last paragraph and
stores it in the results metadata with a Key name of
"Last Paragraph" .
|
|
Gets the text from a span tag with a
class of
ixn and extracts the details following the
pattern
IXN= . Stores this text in the test results
metadata with the Key name of
IXN .
|
GetValue
Gets the text from an input element and optionally parses and stores it in the results metadata.
GetValue("selector", "regex", "metakey", "frame")
Gets the element's value from the supplied
selector
. An optional regular expression can be used
to extract portions of the value and optionally store this in the results
metadata with the supplied name. If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Gets the value from an input element
named 'email' and extracts the details following the pattern
IXN= . Stores this value in the test results
metadata with the Key name of
IXN .
|
CompareValue
Compares the value supplied against an input elements value and fails if unsuccessful.
CompareValue("selector", "value", "frame", "script")
Gets the element's value from the supplied selector. This value is compared with the supplied one and if it doesn’t match, it fails. If the given selector does not match any element, the function fails.
Example | Description |
---|---|
|
Gets the value from an input element named 'email' and compares this value with "hello@cyara.com". |
JavaScript
Executes one or more Javascript statements.
JavaScript("script", "frame")
This function is used to execute
Javascript
within the context of the running page.
It can be used to execute code that is not covered by our existing function
library or to call functions that are already loaded inside the page.
Example | Description |
---|---|
|
Execute a function called
startChat within the context of the
currently executing page.
|
Cyara Web Test Cases also support JavaScript functions that use async code or promises.
Example | Description |
---|---|
|
JavaScript function with return value. Any non empty string returned will result in the Step failure. |
|
Perform an async code block with a return value. Any non empty string returned will result in the Step failure. |
|
Perform an async code block with no return value. |
|
Perform an async code block with a return value. |
Matches
Matches a string value within the result string of the supplied
script
or
selector
.
Matches("selector", "value", "frame", "script")
This is a polling action that performs a case-insensitive text
comparison of the results of the supplied script or selector looking for a
matched value. If the value is not found the process is repeated, with a delay
of 250 milliseconds (defined by the Configuration Setting
DomUpdatedSleepTime
). If the timeout for the Step is
reached, the function fails.
This function can take advantage of the wildcard tag. This tag can be used to ignore certain parts of the script result value.
Example | Description |
---|---|
|
Matches the text inside the result of the script, ignoring the Agent's Name (between the words 'Agent' and 'how' in the Example column to the left). |
|
Matches the text inside the last paragraph, ignoring the Agent’s name (between the words 'Agent' and 'how' in the Example column to the left). |
MouseMove
Moves the mouse to specific coordinates on the browser.
MouseMove("x", "y")
This function will move the mouse to the supplied coordinates, measured in pixels from the top left corner of the browser.
Example | Description |
---|---|
|
Moves the mouse 100 pixels from the left of the browser, to 200 pixels from the top. |
MouseSweep
Moves the mouse from one set of coordinates to another.
MouseSweep("origin x", "origin y", "destination x", "destination y", "step pixels", "step ms")
This function will move the mouse from one set of coordinates to another, moving a specific number of pixels each time with a given delay in between.
Example | Description |
---|---|
|
Moves the mouse from 100 x 100 to 200 x 200 moving 2 pixels at a time with a delay of 100 milliseconds in between each Step. |
PressEnter
Simulates a user pressing the Enter key on a given element.
PressEnter("selector", "frame")
This function will simulate a user pressing the Enter key on the
element defined in the supplied Selector. If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Presses the Enter key on an input element
that has a class of
submit .
|
Check
Checks a checkbox or radio button.
Check("selector", "value", "frame")
Sets the checkbox of a radio button defined by the given selector
with the supplied value. If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Sets the checkbox defined by the selector to checked (ticked). |
SetActiveWindow("index")
Sets the active window using the index
supplied. The active
window will be the target document for all subsequent functions and commands.
"0" will be the main window and this will increment as you open new
windows/tabs.
SetValue
Sets an element's value.
SetValue("selector", "value", "frame")
Sets the input element defined by the given
selector
with the supplied value. If the given
selector
does not match any element, the function
fails.
Example | Description |
---|---|
|
Sets an element with an ID of
chatTextArea with a value of "Hi there!"
|
Wait
Pauses execution.
Example | Description |
---|---|
|
Pauses the test execution for the number of milliseconds supplied. This can be used to force arbitrary wait times with a Step. |
WaitFor
Wait for an element described by the given selector to be either visible (shown), hidden (invisible) or missing.
Example | Description |
---|---|
|
Pauses the test execution until a defined
element in the supplied Selector is visible. If the given
selector does not match any element, the
function fails. |
Custom Functions
A Custom function is a block of one or more function calls abstracting a particular common block of code.
Example | |
---|---|
Name | PrimeChat |
Parameters | 2 |
Sample |
PrimeChat("fred",
"password")
|
Script |
|
Notification
This type is currently not supported.
Comments
0 comments
Please sign in to leave a comment.