elenjo QA API

Methods

append(relativePath, data, encodingopt)

add data to the end of a local file
Parameters:
Name Type Attributes Default Description
relativePath string the local file path
data string the file content
encoding string <optional>
'utf8' other encodings are 'base64' and 'ascii'

aseq(message, val1, val2)

Test method: assert the two values are equal
Parameters:
Name Type Description
message string to throw when the two values are not equal
val1 any
val2 any

asrt(message, condition)

Test method: assert the condition is true
Parameters:
Name Type Description
message string to throw when the condition is false
condition boolean

attr(selector, attribute, indexopt) → {string}

get the value of an attribute of an HTML element.
Parameters:
Name Type Attributes Default Description
selector string CSS selector
attribute string HTML attribute name
index number <optional>
0 index of the elements array selected by selector
Returns:
document.querySelectorAll(selector)[index].getAttribute(attribute)
Type
string

baseUrl() → {string}

the base url of the current webview
Returns:
base url
Type
string

call(function, …varargs) → {object}

Run a function inside the webview with optional arguments (varargs). The function return value is returned.

Any exception thrown from function is returned as exception.

Note: The function execution is sandboxed. Run in the webview, it has no access to the elenjo variable or any other variables except for the explicitly-passed-in arguments: varargs. Of course it has access to environment and scripts loaded in the webview. Additionally window.log(string-text) can be called from inside the webview to invoke elenjo.log().

WARNING: do not call window.ack(data) as it disrupts script execution.

Parameters:
Name Type Attributes Description
function function a function to run in the webview
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}
Returns:
the return value of the function execution
Type
object

click(selector, indexopt)

Click on an element. Execution is NOT suspended. equivalent to: fire((s, n) => document.querySelectorAll(s)[n].click(), selector, index);
Parameters:
Name Type Attributes Default Description
selector string the CSS selector
index number <optional>
0 index into the elements array selected by selector

date2Str(d) → {string}

not async given a Date object, return a date string in the format of 'yyyy-mm-dd'
Parameters:
Name Type Description
d Date date
Returns:
a date string 'yyyy-mm-dd'
Type
string

deletelog(relativePath)

delete the log file from 'log' dir
Parameters:
Name Type Description
relativePath string the local log file path

download(relativePath, url, methodopt, dataopt, headersopt)

using the webview, download a document and save as a local file
Parameters:
Name Type Attributes Default Description
relativePath string the local file path
url string url to the document
method string <optional>
'GET' http method
data object <optional>
data to post if method is POST
headers object <optional>
http headers

exists(selector) → {number}

get the number of occurrences of the selector in the webview
Parameters:
Name Type Description
selector string the CSS selector
Returns:
document.querySelectorAll(selector).length
Type
number

exp(selection, timesopt, intervalopt)

Wait till selection appears, checking at most times at fixed interval
Parameters:
Name Type Attributes Default Description
selection string CSS selector
times number <optional>
10 # of times to poll
interval number <optional>
1000 time inetrval in milliseconds

fail(message)

Test method: signal test failure, throw Error with message
Parameters:
Name Type Description
message string to throw

fetchblob(relativePath, url, methodopt, headersopt)

without using the webview, download a document and save as a local file support GET only
Parameters:
Name Type Attributes Default Description
relativePath string the local file path
url string url to the document
method string <optional>
'GET' http method
headers object <optional>
http headers

fexists(relativePath) → {boolean}

check if the file exists
Parameters:
Name Type Description
relativePath string the local file path
Returns:
Type
boolean

fexistsjs(relativePath) → {boolean}

If the javascript (test script) exists in the 'js' dir.
Parameters:
Name Type Description
relativePath string the local file path
Returns:
Type
boolean

fexistslog(relativePath) → {boolean}

If the log file exists in the 'log' dir.
Parameters:
Name Type Description
relativePath string the local file path
Returns:
Type
boolean

fire(function, …varargs)

Run a function inside the webview with optional arguments (varargs). Fire and forget. Nothing is returned.

Any exception thrown from function is returned as exception.

Note: The function execution is sandboxed. Run in the webview, it has no access to the elenjo variable or any other variables except for the explicitly-passed-in arguments: varargs. Of course it has access to environment and scripts loaded in the webview. Additionally window.log(string-text) can be called to invoke elenjo.log() from inside the webview.

WARNING: do not call window.ack(data) as it disrupts script execution.

Parameters:
Name Type Attributes Description
function function a function to run in the webview
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}

get(url, methodopt, dataopt) → {string}

Download text-based content using XMLHttpRequest.
Parameters:
Name Type Attributes Default Description
url string the content url
method string <optional>
GET HTTP protocol method (GET or POST)
data object <optional>
the payload with POST method
Returns:
text-based content
Type
string

get2(url, methodopt, dataopt) → {array}

Download text-based content using XMLHttpRequest, returns also response headers.
Parameters:
Name Type Attributes Default Description
url string the content url
method string <optional>
GET HTTP protocol method (GET or POST)
data object <optional>
the payload with POST method
Returns:
[text-based content, response headers]
Type
array

get64(url, methodopt, dataopt, headersopt) → {string}

Download base-64 encoded content (PDF etc) using XMLHttpRequest.
Parameters:
Name Type Attributes Default Description
url string the content url
method string <optional>
GET HTTP protocol method (GET or POST)
data object <optional>
the payload with POST method
headers object <optional>
request HTTP headers
Returns:
base-64 encoded content
Type
string

getText()

not async

html(selector, 0opt) → {string}

get the outer HTML of the index'th element selected by the CSS selector
Parameters:
Name Type Attributes Description
selector string the CSS selector
0 index <optional>
index into the elements array selected by selector
Returns:
document.querySelectorAll(selector)[index].outerHTML
Type
string

ifattr(frameSelector, indexopt, selector, attribute, index2opt)

like attr() but in an iframe or frame. get the value of an attribute of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
attribute string attribute name
index2 number <optional>
0 the index of the elements array identified by selector @ @return {string} the value of an attribute of an element in an iframe or frame

ifcall(frameSelector, indexopt, function, …varargs) → {object}

like call() but in an iframe or frame
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
function function a function to run in the iframe/frame
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}
Returns:
whatever returned from function
Type
object

ifclick(frameSelector, indexopt, selector, index2opt)

like click() but in an iframe or frame. click on a link or element in an iframe or frame. Execution is NOT suspended.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector to click on
index2 number <optional>
0 the index of the elements array identified by selector

ifexists(frameSelector, indexopt, selector, index2opt)

like exists() but in an iframe or frame. get the number of occurrences of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
index2 number <optional>
0 the index of the elements array identified by selector @ @return {number} the number of occurrences of an element in an iframe or frame.

ifexp(frameSelector, indexopt, selector, timesopt, intervalopt)

like exp() but in an iframe or frame Wait for element identified by selector, checking # of times with fixed interval
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
times number <optional>
10 # of times to check
interval number <optional>
1000 interval default 1 second

iffire(frameSelector, indexopt, function, …varargs)

like fire() but in an iframe or frame. Fire and forget. Nothing is returned.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
function function a function to run in the iframe/frame
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}

ifhtml(frameSelector, indexopt, selector, index2opt)

like html() but in an iframe or frame. get the outer HTML of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
index2 number <optional>
0 the index of the elements array identified by selector @ @return {string} the outer HTML of an element in an iframe or frame.

ifinner(frameSelector, indexopt, selector, index2opt)

like inner() but in an iframe or frame. get the inner HTML of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
index2 number <optional>
0 the index of the elements array identified by selector @ @return the inner HTML of an element in an iframe or frame.

ifreq(frameSelector, indexopt, function, …varargs) → {object}

like req() but in an iframe or frame. Execution is suspended until window.ack(data) is run in the webview. If data.err and data.stack are not null, data is thrown as an exception. Otherwise, data is returned.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
function function a function to run in the iframe/frame
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}
Returns:
data as window.ack(data) executed in the webview
Type
object

iftext(frameSelector, indexopt, selector, index2opt)

like text() but in an iframe or frame. get the text of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
index2 number <optional>
0 the index of the elements array identified by selector @ @return {string} the text of an element in an iframe or frame.

ifvalue(frameSelector, indexopt, selector, index2opt)

like value() but in an iframe or frame. get the value of an element in an iframe or frame.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector
index2 number <optional>
0 the index of the elements array identified by selector @ @return {string} the value of an element in an iframe or frame.

ifvisit(frameSelector, indexopt, selector, index2opt)

like visit() but in an iframe or frame. Execution is suspended until a page navigation event is triggered and the page finished loading.
Parameters:
Name Type Attributes Default Description
frameSelector string selector for a frame
index number <optional>
0 the index of the selected iframe/frame array
selector string element selector to click on
index2 number <optional>
0 the index of the elements array identified by selector

inner(selector, 0opt) → {string}

get the inner HTML of the index'th element selected by the CSS selector
Parameters:
Name Type Attributes Description
selector string the CSS selector
0 index <optional>
index into the elements array selected by selector
Returns:
document.querySelectorAll(selector)[index].innerHTML
Type
string

log(txt)

not async log with newline appended
Parameters:
Name Type Description
txt string log text

log0(txt)

not async log without newline appended
Parameters:
Name Type Description
txt string log text

logtest(relativePath, data, encodingopt)

log the test
Parameters:
Name Type Attributes Default Description
relativePath string the local log file path
data string the log content
encoding string <optional>
'utf8' other encodings are 'base64' and 'ascii'

ls(relativePath) → {list}

list local files
Parameters:
Name Type Description
relativePath string the local file path
Returns:
the list of files including directories
Type
list

lsjs(relativePath) → {array}

List the javascript (test script) files in the 'js' dir
Parameters:
Name Type Description
relativePath string the local file path
Returns:
list of javascripts
Type
array

mkdir(relativePath)

create a directory
Parameters:
Name Type Description
relativePath string the local dir path
Run a function inside the webview with optional arguments (varargs). Execution is suspended until a page navigation event is triggered and the page finished loading.

Any exception thrown from function is returned as exception. There is no return data on successful execution.

Note: The function execution is sandboxed. Run in the webview, it has no access to the elenjo variable or any other variables except for the explicitly-passed-in arguments: varargs. Of course it has access to environment and scripts loaded in the webview. Additionally window.log(string-text) can be called from inside the webview to invoke elenjo.log().

WARNING: do not call window.ack(data) as it disrupts script execution.

Parameters:
Name Type Attributes Description
function function a function to run in the webview
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}

ok(title, message, okLabelopt, cancelLabelopt) → {boolean}

OK/Cancel dialog
Parameters:
Name Type Attributes Default Description
title string dialog title
message string dialog message
okLabel string <optional>
OK OK label
cancelLabel string <optional>
Cancel Cancel label
Returns:
true for OK, false for Cancel
Type
boolean

open(url)

navigate to the url. Script execution is suspended until a page navigation event is triggered and the page finished loading.
Parameters:
Name Type Description
url string

prompt(label, question, alertTypeopt, defaultValueopt, keyboardTypeopt) → {string}

prompt a question for an answer.
Parameters:
Name Type Attributes Default Description
label string prompt title
question string prompt question
alertType string <optional>
plain-text or 'secure-text' or 'login-password'.
defaultValue string <optional>
keyboardType string <optional>
default or 'email-address', 'numeric', 'phone-pad', 'ascii-capable', 'numbers-and-punctuation', 'url', 'number-pad', 'name-phone-pad', 'decimal-pad', 'twitter' or 'web-search'
Returns:
the answer, undefined when cancelled.
Type
string

read(relativePath, encodingopt) → {string}

read a local file, based on encoding
Parameters:
Name Type Attributes Default Description
relativePath string the local file path
encoding string <optional>
'utf8' other encodings are 'base64' and 'ascii'
Returns:
the file content
Type
string

readjs(relativePath, encodingopt) → {string}

read a javascript (test script), based on encoding
Parameters:
Name Type Attributes Default Description
relativePath string the local javascript path
encoding string <optional>
'utf8' other encodings are 'base64' and 'ascii'
Returns:
the javascript content
Type
string

req(function, …varargs)

Run a function inside the webview with optional arguments (varargs). Execution is suspended until window.ack(data) is run in the webview. If data.err and data.stack are not null, data is thrown as an exception. Otherwise, data is returned.

Also any exception thrown from function is returned as exception.

Note: The function execution is sandboxed. Run in the webview, it has no access to the elenjo variable or any other variables except for the explicitly-passed-in arguments: varargs. Of course it has access to environment and scripts loaded in the webview. Additionally two global functions: window.ack(data) and window.log(string-text). window.ack(data) must be invoked from inside the webview to resume the execution. window.log(string-text) can be called from inside the webview to invoke elenjo.log().

Parameters:
Name Type Attributes Description
function function a function to run in the webview
varargs * <repeatable>
each arg must be JSON-able using JSON.stringify()
Throws:
exception with {err:'some-error', stack:'some-stack'}
Returns:
data as window.ack(data) executed in the webview

sleep(delay)

pause execution for at least 'delay' milliseconds
Parameters:
Name Type Description
delay number in milliseconds

snap(relativePath, screenopt)

Take a screenshot of the webview or the screen only
Parameters:
Name Type Attributes Default Description
relativePath string the path to store the screenshot
screen boolean <optional>
false if true, take the screen only.

str2amount(amount)

convert a string amount to a number. The string can be prefixed with '$'.
Parameters:
Name Type Description
amount string string amount
Returns:
the number amount

text(selector, indexopt) → {string}

get the text of the index'th element selected by the CSS selector
Parameters:
Name Type Attributes Default Description
selector string the CSS selector
index number <optional>
0 index into the elements array selected by selector
Returns:
document.querySelectorAll(selector)[index].textContent
Type
string
delete a local file or directory (the directory has to be empty)
Parameters:
Name Type Description
relativePath string the local file/directory path

url() → {string}

the url of the current webview
Returns:
url
Type
string

value(selector, indexopt) → {string}

get the value of the index'th element selected by the CSS selector
Parameters:
Name Type Attributes Default Description
selector string the CSS selector
index number <optional>
0 index into the elements array selected by selector
Returns:
document.querySelectorAll(selector)[index].value
Type
string

visit(selector, indexopt)

Click on the link or element identified by selector. Execution is suspended until a page navigation event is triggered and the page finished loading. equivalent to: nav((s, n) => document.querySelectorAll(s)[n].click(), selector, index);
Parameters:
Name Type Attributes Default Description
selector string the CSS selector
index number <optional>
0 index into the elements array selected by selector

write(relativePath, data, encodingopt)

write data to a local file
Parameters:
Name Type Attributes Default Description
relativePath string the local file path
data string the file content
encoding string <optional>
'utf8' other encodings are 'base64' and 'ascii'