-
Notifications
You must be signed in to change notification settings - Fork 0
Language Syntax (v0.2)
The test 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.
Commands can appear on the same line or separate lines, it doesn't matter, as newline behaves exactly like space.
Set a browser preference.
See https://sites.google.com/a/chromium.org/chromedriver/capabilities
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>
Moves the browse window to the specified screen position.
browser pos <x>,<y>
Navigate the browser window to the specified url.
browser get "<url>"
Close the browser window.
browser close
Load and run the specified script.
include "<filename>"
A synonym for function.
Define a function or alias (there are interchangable) 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 ... }
Used to aid debugging the test engine, allows setting of a breakpoint within a script when running the engine under eclipse.
debugger
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>
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
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 ...> }
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 ScriptDriver version.
version
Simply echo's its argument to standard output.
echo "<string>"
Event handlers are special aliases, 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>)"
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>)"
Clicks the currently selected element (see selection)
click
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.
centerMoves the mouse position to the top left of the body element.
bodyClicks and holds the left mouse button.
downReleases the left mouse button.
upMoves the mouse position relatively by the specified
x,yoffsets."-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
}