# Best Practice
# Virtuoso Syntax
The following is a list of the syntax used for authoring journeys in Virtuoso:
Navigate
Commands like browse, go, navigate, or open are used to go to a URL. Adding in new tab allows navigation in a new tab.
Examples:
go to https://google.com
open https://amazon.com
browse http://virtuosoqa.com
navigate to https://duckduckgo.com
navigate to "https://google.com" in new tab
open "https://amazon.com" in new tab
Click
The command click is used to interact with elements. It can use dynamic targets with variables and can fall back to "force-click" if needed.
Examples:
click on bottom "Submit"
click "search"
click in "Name"
click $variableTarget
Write
Commands like type, enter, or write are used to input values in text fields.
Examples:
write "Joe" in "First name"
type "24" in "Age"
Select
The commands select or pick are used to choose an option from a dropdown list. Options can be selected by value or index.
Examples:
select "March" from "Month"
pick "March" from "Month"
pick second option from "list"
pick last option from "Month"
pick option 7 from "Addresses"
Wait
Commands like wait or pause can be used to delay for a certain time or wait for an element. Time intervals can be in milliseconds, seconds, or minutes.
Examples:
wait 1
wait one second
pause two minutes
wait 500ms
wait three seconds for "Logged in!"
wait for "Welcome"
Waiting for an element without specifying the time causes Virtuoso to wait for up to 20 seconds or until the element appears. The maximum wait time Virtuoso can execute is currently 10 minutes (if you enter a value higher than this your test will fail during its execution).
Mouse actions
Commands to perform mouse actions, like double click, right-click,enter, etc., either on elements or coordinates.
Examples:
* Targeting elements:
mouse double click "Element"
mouse right click "Element"
mouse enter "Name"
mouse over "Categories"
hover "Categories"
* Targeting coordinates:
mouse move to 100, 400
mouse move to coordinate $myVariable
mouse move by 10, 40
mouse move by coordinate $myVariable with default "-10, 40"
* Without elements (use current position of the mouse):
mouse click
mouse right click
mouse double click
Drag and Drop
Commands like drag to and drag by are used to perform drag-and-drop actions to specific coordinates or elements.
Examples:
mouse drag to "target element"
mouse drag to 240, 402
mouse drag to coordinate $myVariable
mouse drag by 0, -50
mouse drag by coordinate $myVariable with default "100,-100"
mouse over "A"
mouse drag to "B"
Store
The store command is used to save element content or exact values in variables, which can be referenced later.
Examples:
store element text of "password" in $user_pass
store element details of top link "login" in $login_link
store value "Hello World" in $myVariable
store text "John Smith" in $user_name
Frames and Tabs
The switch command is used to change the active frame or tab
Examples:
switch frame to "search"
switch iframe to id "menu-bar-frame"
switch to parent frame
switch to previous tab
switch tab to 3
Scroll
The scroll command is used to scroll the page to a specific element or coordinate.
Examples:
scroll to page top
scroll to page bottom
scroll to "search"
scroll to 20, 40
scroll by 20, 40
Upload
The upload command uploads files via file input fields, providing the URL of the file and the target element.
Examples:
upload "http://www.mypersonalpage.com/resume.pdf" in "Résumé:"
upload "https://www.myhomepage.com/me.jpg" to "Drop image here"
Due to browser limitations, upload is not supported in the following environments:
- Edge 15
- All Safari versions
- Mobile devices
Cookie management
The cookie command is used to add, remove, or manipulate browser cookies.
Examples:
cookie "login" set to "username"
cookie create "login" as "username"
cookie remove "login"
cookie wipe all
Window
The window command is used to resize or manipulate the active window.
Examples:
window resize to 640, 480
Execute (extension execution)
Allows executing scripts or language extensions, with the possibility of returning results to variables.
Examples:
execute "my script name"
execute scriptName using "Jon Snow" as name, 42 as counter and $age as age returning $result
checkBrokenLinks
validateElement ("#my .element-selector")
sumNumbers ($price, 42) returning $total
Dismiss
The dismiss command is used to handle browser alerts, confirms, or prompts.
Examples:
dismiss alert
dismiss confirm reply ok
dismiss confirm respond cancel
dismiss prompt respond "text to write"
dismiss prompt reply cancel
Press keyboard keys
The press command allows simulating key presses individually or in groups.
Examples:
press ENTER in "Search"
press SHIFT_A in "target"
press 'H E L L O SPACE W O R LD' in "Element"
press $variable
press TAB
press CTRL_SHIFT_X
press X
press '1 2 3 4'
press "Hello SPACE world"
press 'TAB First Name TAB Last N a m e TAB ENTER'
Assertions
A set of commands like assert is used to verify various properties and values of page elements.
Examples:
Assert Exists:
look for "Submit"
see "Submit"
assert exists "First name"
see element $var
Assert Not Exists:
assert not exists "Please confirm you are not a robot"
assert not exists element "Request failed"
Assert Equals:
assert "First name" equals "John"
assert that "Last name" is equal to "Smith"
assert that "Age" == 25
assert "age" = 25
Assert Not Equals:
assert "First name" not equals "John"
assert that "Last name" is not equal to "Smith"
assert that "Age" != 25
assert "age" <> 25
Assert Less Than:
assert "age" less than 18
assert "age" < 18
assert that "age" is less than 25
Assert Less Than Or Equal:
assert "age" less than or equal to 18
assert "age" <= 18
assert that "age" is less than or equal to 25
Assert Greater Than:
assert "age" greater than 18
assert "age" > 18
assert that "age" is greater than 25
Assert Greater Than Or Equal:
assert "age" greater than or equal to 18
assert "age" >= 18
assert element "age" >= 18
assert that "age" is greater than or equal to 25
Assert Matches:
assert that "First name" matches /[a-zA-Z]*/
assert "Email" matches /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
assert "//title" matches "My page title"
assert "#parent > .selector" matches /Price:\s*42.11/
Assert Selected:
assert that "March" is selected in "Month"
Assert Checked:
assert "Male" is checked
assert "I agree" ticked
Assert Variable:
assert $result equals "expected value"
assert $foo is less than 4
assert $bar is less than or equal 100
assert $pi is greater than 3.14
assert $var starts with "expected start value"
assert $sample contains "some text"
assert ${1 + 2} equals "3"
assert ${$var1 == $var2} equals "true"
assert ${42 + $var1 * $total == $price} equals "true"
assert ${document.title} contains "Virtouso"
Comments
You can add comments to tests using //, optionally emphasizing with TODO or FIXME.
Examples:
// FIXME: add some assertion to make sure the login modal is shown
Click on "Login"
Write $username in field "username"
// TODO Button implementation is not ready yet
// Click on button "Continue"
API call
Allows performing API requests within a journey execution using input arguments and returning outputs to variables.
Examples:
API call "folder.apiTest"
API call "virtuoso.users.listUsers" returning users as $users
API call "virtuoso.users.deleteUser" using $id as userId
API call "virtuoso.login" using $password as password returning token as $token
API call "virtuoso.login" using $password as password returning token as $tokenName, $result
API call "virtuoso.users.deleteUser" ($id)
API call "virtuoso.login" ($password) returning token as $token
api "folder.apiTest"
api "virtuoso.users.listUsers" returning users as $users
# Interrelationships
Some actions have in-built interrelationships, for example assertions and click actions. If, for example, you look for an item on an e-commerce shopping page and then ask Virtuoso to click on an "Add to bag" button, Virtuoso will use the context of the assertion to click on the button most associated with the element you asserted against.
Example:
look for "Raspberry jam"
click on "Add to bag"
Here, Virtuoso would locate an item on the page called "Raspberry jam" and click the button connected with it.
#
# Read more
For further details, go to our Guide: