-
Notifications
You must be signed in to change notification settings - Fork 0
Language Syntax (v0.1)
The dalang script engine processes test scripts which comprise lists of commands and tests using the following syntax:
The parser consumes words and strings and integers separated by white space. //
and
/* ... */
comments are also supported.
keyword keyword "string" 0 11 22 ...
Some commands enclose their arguments in { ... }
braces generally where the number of arguments may vary for example when calling an external script or defining an alias.
Aliases or functions may also take an argument name sequence defined as ( name1, name2, .. )
. These can be referenced inside the alias/function using $name
or when embedded in a string, $(name)
or $I(name)
.
Commands can appear on the same line or separate lines, it doesn't matter, as newline behaves exactly like space.
[not implemented] Set a browser preference.
browser prefs <preference> <value>
Sets a browser command line option.
browser option "<option-string>"
Start the browser using the options and preferences defined so far.
browser start
Specifies the size of the browser chrome (used in conjunction with browser size
to correctly size the inner window).
browser chrome <width>,<height>
Sizes the browser window to the specified width and height.
browser size <width>,<height>
[todo]
Moves the browse window to the specified screen position.
browser pos <x>,<y>
Navigate the browser window to the specified url.
browser get "<url>"
Performs an F5 or CMD+R (refresh) of the browser.
browser refresh
Navigate backward, same as pressing the back button.
browser back
Navigate forward, same as pressing the forward button..
browser forward
Close the browser window.
browser close
[deprecated] Sets the timeout used to wait for elements. If not defined, the normal wait timer is used
browser wait <seconds>
Load and run the specified script.
include "<filename>"
A synonym for function
.
Define a function or alias (they are interchangeable) that can be called using its name. They become keywords that can be used anywhere a keyword can and can optionally support passing a fixed number of named arguments.
alias <name> { <statements> ... }
function <name> (<params>) { <statements> ... }
Create an alias that will click the currently element and then sleep for 1 second.
alias CLICK { click sleep 1 }
test-id "mybutton" CLICK
Create a function that checks the value of a cell within a grid. Parameters are expanded
using either $name
if its the only value, or using $(name)
if part of a
larger string. The $I(name)
syntax is used to convert the parameter to an integer and
should e used where an integer value is required, for example in an :nth-child(1)
css
selector.
alias CHECK_CELL (row, col, value) {
echo "Checks if cell at $I(row),$I(col) matches $(value)"
select ".gridRow:nth-child($I(row)) :nth-child($I(col))" check $value
}
CHECK_CELL 1 3 "test value"
Runs an external <command>
passing the supplied arguments. If no arguments are required
use { }
.
exec <command> { args ... }
exec <command> { }
Similar to exec
except that if the script returns an exit status of 0, standard output
from the command is processed as an included test script.
exec-include <command> { args ... }
Pause execution for the specified number of seconds
sleep <seconds>
Used to specify a timeout for following select statements, allowing the script to wait for elements to become available but respond to them as soon as they do (whereas sleep always waits for the specified duration). This allows scripts to perform as fast a possible but be able to cater for subtile timing differences between runs.
wait <seconds>
Sets the default wait timeout if one is not specified when a test would otherwise fail.
default wait <seconds>
Sets the default screen shot path. If defined, this path will be prefixed to any path
name specified in the screenshot
command
default screenshot <path>
Pushes the current wait timeout onto the stack. Designed to be used by aliases, functions
and included scripts. The wait timeout can be restored by calling pop wait
.
push wait
pop wait
Wait for an event. Currently only one event is supported, navigation
. Use this after performing an action that reloads the page, for instance submitting a form. This command waits for the page to finish loading, and re-initialises the testing context to testing can continue.
wait-for navigation
If the test-statements yield a positive result (only selectors can do this) the then part is processed otherwise the else part is processed.
if <test-statement> then <statements> else <statements> endif
Repeatedly executes { statement ... }
until it fails.
while { statement ... }
Calls RegressionTest.test(verb, args)
in the executing web page. This can be useful for
performing custom actions within your page.
call <verb> { <arg ...> }
[todo]
Allows the script to respond to browser alerts. Only supported verb is *accept
which OKs the dialog.
alert accept
Causes the current script to fail. If executed within the body of a while
statement causes
the while statement to stop executing.
fail "<message>"
Selectors are use to select the current element which other commands then operate on.
Locate an element with a test-id attribute matching id-string and make it the current context.
test-id "<id-string>"
Locate an element using css-selector and make it the current context.
select "<css-selector>"
Locate an element using xpath-expression and make it the current context.
xpath "<xpath-expression>"
Tests if the current elements's value or text node (depending on type of element) matches string-value, if not aborts the test.
check "<string-value>"
Within a function
| alias
with named parameters:-
check $<name>
check "$(<name>)"
check "Test $(<name>)"
check "$I(<name>)"
Tests if a checksum of the current element's value or text node matches <checksum>
.
checksum "<checksum>"
Test if the current element's tag name matches tag-name, if not aborts the test.
tag "<tag-name>"
Tests if the current element is displayed (is visible), if not aborts the test.
displayed
Tests if the current element is enabled, if not aborts the test.
enabled
Tests if the current element is selected, if not aborts the test.
selected
Test if the location of the current context is at the specified position,
if not aborts the test. The wildcard *
can be substituted for the x position
and means any x
position will pass the test.
at <x>,<y>
Test if the location of the current context size matches the specified size,
if not aborts the test. The wildcard *
can be substituted for the width
and means any width will pass the test. A range can also be specified for
the width by specifying <min-width>:<max-width>,<height>
.
size <width>,<height>
Reverses the result of a condition.
not check ""
not enabled
not displayed
if not test-id "some-field" then
do-something
endif
Dumps the info for a the current context in a form suitable for inclusion in a test script.
info
Dumps the info for all elements with a test-id in a form suitable for inclusion in a test script. This is particuarly useful when initially building scripts. Get to a certain point and the dump to get a bunch of checks for all the fields with test-ids.
dump
Dumps the browsers console.log to standard output, and then clears it. This can be helpful when so that when a test fails, the console output can be seen at point of failure.
log dump
Enables or disables automatic logging of the console to standard output. When auto logging is enabled, the browsers console log is copied to standard output before each command is executed.
log auto <on|off>
log auto <true|false>
Displays the Puppeteer version.
version
Simply echo
's its argument to standard output.
echo "<string>"
Takes a screen shot of the current browser window and saves it to the named file.
The path is relative to the current directory or can be absolute if it begins with
a / or a drive letter as in C:. If a default screenshot
path is specified and
the path specified here is relative, the default screenshot path is prepended to
this path to build the full path name. Screen shots are output in PNG format.
screenshot "<path>/<name>.png"
screenshot "<name>.png"
Event handlers are special alias
es, that are called when an event occurs. Two events are
currently supported:
alias "--onfail" { dump log dump sleep 30000 }
alias "--onsuccess" { sleep 1 }
As their name suggests, --onsuccess
is called when the tests script run through to
completion and --onfail
is called whenever a test fails (which also terminates
the script).
Clears the current context's input data.
clear
Sends characters to current context. Note that this does not replace the current contents, it adds to them.
send "<string>"
Within a function
| alias
with named parameters:-
send $<name>
send "$(<name>)"
send "Test $(<name>)"
Sends a special character to current context. Note that this does not replace the current contents, it adds to them.
send <charCode>
Within a function
| alias
with named parameters:-
sendkey $<name>
sendkey "$(<name>)"
sendkey "Test $(<name>)"
Simulate pressing a keyboard key. A list of key names can be found here: https://github.com/GoogleChrome/puppeteer/blob/master/lib/USKeyboardLayout.js#L33
press <keyName>
Within a function
| alias
with named parameters:-
press $<name>
press "$(<name>)"
press "Test $(<name>)"
Set the current context to the specified value. The set command is equivalent to doing
clear send "string"
.
set "<string>"
Within a function
| alias
with named parameters:-
set $<name>
set "$(<name>)"
set "Test $(<name>)"
The click
command clicks the currently selected element (see selection). The script engine will wait for
the element to become clickable before attempting to click it. This is not always desirable, particularly when
the element that matches the current selector changes. Waiting does not pick up this new element so the click just waits until it times out. For those cases, use click-now
which will not wait for the element to become clickable, it will just try and click it, and if it fails, the normal wait
retry logic kicks in which will reselect the element using the current selector before retrying the click.
click
click-now
Scrolls the currently selected element into view, forces it to be within the visible part of the viewport.
scroll-into-view
Starts a sequence of mouse movements in relation to the current context.
mouse { <mouse-cmd> ... }
All mouse commands are relative to an element. There are two elements that can be
used, one is the currently selected element (that has previously been selected with
test-id
or select
etc) the other is the body
element. Mouse commands are a
sequence of keywords or co-ordinates enclosed within { ... }
braces of the mouse
command arguments.
The following mouse commands are available:-
Moves the mouse position to the top left corner of the current context.
origin "0,0"
Moves the mouse position to the center of the current context.
center
Moves the mouse position to the top left of the body element.
body
Clicks and holds the left mouse button.
down
Releases the left mouse button.
up
Moves the mouse position relatively by the specified
x
,y
offsets."-100,100"
Performs a left mouse click at the current position.
click
// Setup Some Aliases
alias HOME { dump log dump call "goHome" select ".rmcMenuBar :first-child" log dump }
alias No { select ".rmcAlertDialog .prompt :last-child" click sleep 0.1 }
alias Yes { select ".rmcAlertDialog .prompt :first-child" click sleep 0.1 }
alias OK { select ".rmcAlertDialog .buttons :first-child" click sleep 0.1 }
alias SBL { select ".rmcTabStripSBL" click sleep 0.1 }
alias PROMPT { wait 1 select ".rmcAlertDialog .type-prompt .title" }
alias SYNC { select "#signal-on" click }
alias ANSWER
mouse {
"0,0"
down "387,0" "0,205" "-387,0" "0,-205" up
center "-25,-25"
down "50,0" "0,50" "-50,0" "0,-50" up
center "-50,-50"
down "100,0" "0,100" "-100,0" "0,-100" up
center "-75,-75"
down "150,0" "0,150" "-150,0" "0,-150" up
center "-100,-100"
down "200,0" "0,200" "-200,0" "0,-200" up
}