git-link:docs/manual/testdefinition/sakuli-api-environment.adoc{git-view} | git-link:docs/manual/testdefinition/sakuli-api-environment.adoc{git-edit}
Environment - Represents the environment of the current test host.
Params
-
optResumeOnException
Boolean- (optional) if this parameter is undefined, it will be false.
Members
Set a new default similarity for the screen capturing methods.
Params
-
similarity
number- value between 0 and 1, default = 0.8
Returns: - this Environment or NULL on errors.
Resets the current similarity of the screen capturing methods to the original default value of 0.8.
Returns: - this Environment or NULL on errors.
Get a Region object from the current focused window
Returns: - a Region object from the current focused window or NULL on errors.
Takes a screenshot of the current screen and saves it to the assigned path. If there ist just a file name, the
screenshot will be saved in your current testcase folder.
Supported formats: jpg and png
Params
-
filename
String-pathname/filename.formator justfilename.formatfor exampletest.png.
Returns: Path - to the created screenshot OR null on errors
Example
environment.takeScreenshot("test.png");
Takes a screenshot of the current screen and add the current timestamp in the file name like e.g.:
Params
-
filenamePostfix
String- postfix for the final filename Default: screenshot -
optFolderPath
String- optional FolderPath, where to save the screenshot. If null or empty: testcase folder will be used -
optFormat
string- optional format, for the screenshot (currently supported: jpg and png) If null or empty use propertysakuli.screenshot.format
Returns: Path - to the created screenshot OR null on errors
Example
env.takeScreenshotWithTimestamp("my-screenshot");
saved under: mytestsuite/testcase1/2017_08_03_14_06_13_255_my_screenshot.png
Blocks the current testcase execution for x seconds
Params
-
seconds
number- to sleep
Returns: - this Environment or NULL on errors.
Blocks the current testcase execution for x milliseconds
Params
-
milliseconds
number- to sleep
Returns: - this Environment or NULL on errors.
Returns: - the current content of the clipboard as String or NULL on errors
sets the String parameter to the system clipboard
Params
-
text
String- text as string
Returns: - this Environment.
pastes the current clipboard content into the focused area. Will do the same as "CTRL + V".
Returns: - this Environment.
copy the current selected item or text to the clipboard. Will do the same as "CTRL + C".
Returns: - this Environment.
Clean the content of the clipboard.
pastes the text at the current position of the focus/carret <br/>using the clipboard and ctrl/cmd-v (paste keyboard shortcut)
Params
-
text
String- a string, which might contain unicode characters
Returns: - this Environment or NULL on errors.
makes a masked paste(String) without any logging.
Params
-
text
String- a string, which might contain unicode characters
Returns: - this Environment or NULL on errors.
combines pasteMasked(String) and decryptSecret(String).
Params
-
text
String- encrypted secret
Returns: - this Environment or NULL on errors.
Enters the given text one character/key after another using keyDown/keyUp. <p/> About the usable Key constants see documentation of Key. The function could also type UTF-8 unicode characters, if the OS supports it. The text is entered at the current position of the focus.
Params
-
text
String- containing characters and/or Key constants -
optModifiers
String- (optional) an String with only Key constants.
Returns: - this Environment or NULL on errors.
Enters the given text one character/key after another using keyDown/keyUp. The entered text will be masked at the logging. <p/> About the usable Key constants see documentation of Key. The function could also type UTF-8 unicode characters, if the OS supports it. The text is entered at the current position of the focus.
Params
-
text
String- containing characters and/or Key constants -
optModifiers
String- (optional) an String with only Key constants.
Returns: - this Environment or NULL on errors.
Decrypt and enters the given text one character/key after another using keyDown/keyUp. The entered text will be masked at the logging. For the details of the decryption see decryptSecret(String). <p/> About the usable Key constants see documentation of Key. The function could also type UTF-8 unicode characters, if the OS supports it. The text is entered at the current position of the focus.
Params
-
text
String- containing characters and/or Key constants -
optModifiers
String- (optional) an String with only Key constants.
Returns: - this Environment or NULL on errors.
Decrypt a encrypted secret and returns the value at runtime. The decryption will only work like described at https://github.com/ConSol/sakuli/blob/master/docs/manual/testdefinition/advanced-topics/sakuli-encryption.adoc . There will be no logging with the decrypted secret during this step. <p/> To create a encrypted secret see "sakuli-manual.md".
Params
-
secret
String- encrypted secret as String
Returns: - decrypted String
Press and hold the given keys including modifier keys <br/> use the key constants defined in class Key, <br/> which only provides a subset of a US-QWERTY PC keyboard layout <br/> might be mixed with simple characters<br/> use + to concatenate Key constants
Params
-
keys
String- valid keys
Returns: - this Environment or NULL on errors.
release the given keys (see Environment.keyDown(…)).
Params
-
keys
String- valid keys
Returns: - this Environment or NULL on errors.
Compact alternative for type() with more options
-
special keys and options are coded as #XN. or #X+ or #X- where X is a reference for a special key and N is an optional repeat factor
A modifier key as #X. modifies the next following key the trailing . ends the special key, the + (press and hold) or - (release) does the same, but signals press-and-hold or release additionally.
except #W / #w all special keys are not case-sensitive
a #wn. inserts a wait of n millisecs or n secs if n less than 60
a #Wn. sets the type delay for the following keys (must be > 60 and denotes millisecs) -
otherwise taken as normal wait
Example: wait 2 secs then type CMD/CTRL - N then wait 1 sec then type DOWN 3 times
Windows/Linux: write("#w2.#C.n#W1.#d3.")
Mac: write("#w2.#M.n#W1.#D3.")
for more details about the special key codes and examples consult the sikuliX docs.
Params
-
text
String- a coded text interpreted as a series of key actions (press/hold/release)
Returns: - this Environment or NULL on errors.
move the mouse pointer to the given target location and move the wheel the given steps down.
Params
-
steps
number- the number of steps
move the mouse pointer to the given target location and move the wheel the given steps up.
Params
-
steps
number- the number of steps
Returns: boolean - true, if the OS is any instance of an Windows based OS
Returns: boolean - true, if the OS is any instance of an Linux based OS
Returns: string - identifier of the current OS
Runs the assigned command on the host and returns the result. Attention: this is OS depended feature! So be
aware which os you are running, maybe us to check Environment#isLinux() or Environment#isWindows().
Params
-
command
string- OS depended command asString -
optThrowException
boolean- defines if an exception should be thrown, if the exit code != 0
Returns: - the result as CommandLineResult object, you can use the methods result.getOutput() and result.getExitCode()
Example:
var app; if(environmen.runCommand('uname --machine') == 'x86_64'){ //open app from other path app = new Application('/lib64/appname'); } else { app = new Application('/lib/appname'); }
Reads out the environment variable with the assigned key
Params
-
key
string- of environment variable
Returns: string - value or null
Reads out the property value with the assigned key
Params
-
key
string- of property
Returns: string - value or null