Built-in Functions
Built-in functions transform, calculate, execute parameters given to the function. The result is stored in the return parameter. These functions cannot be executed without handling the return parameter.
String
For working with strings, the following functions are available:
- SplitLeft("STRING", "SEPERATOR")
Returns the left part of the STRING from the beginning until the SEPERATOR.
Example: SplitLeft("Anthony.Brown", ".") returns the string "Anthony". - SplitRight("STRING", "SEPERATOR")
Returns the right part of the STRING beginning from SEPERATOR until the end of the defined string.
Example: SplitRight("David.Porter", ".") returns the string "Porter". - SubStr("STRING", BEGININDEX, CHARNUMBER)
Returns a substring from the defined STRING. CHARNUMBER characters are returned beginning at BEGININDEX (the index is zero-based).
Example: SubStr("Fabasoft app.test Agent", 9, 8) returns the string "app.test".
If you do not enter a number of characters, the string is returned from the defined index until the end of the string, e.g. SubStr("app.test", 4) returns the string "test". - StrReplace("STRING", "TARGET", "REPLACEMENT")
Replaces each substring of the STRING that matches the literal TARGET sequence with the specified literal REPLACEMENT sequence.
Example: StrReplace("abab", "b", "c") returns the string "acac". - StrLen("STRING")
Returns the length of the STRING.
Example: StrLen("Brown") returns "5". - StrTrim("STRING")
Returns a copy of the STRING, with leading and trailing whitespace omitted.
Example: StrTrim(" Brown ") returns the string "Brown". - IndexOf("STRING", "SUBSTRING")
Returns the index within the STRING of the first occurrence of the specified SUBSTRING. If the SUBSTRING does not occur as a substring, -1 is returned.
Example: IndexOf("David", "Dav") returns "0". - Contains("STRING", "SUBSTRING")
Returns "true" if and only if the STRING contains the specified SUBSTRING.
Example: Contains("David", "vi") returns "true". - Lower("STRING")
Converts all of the characters in the STRING to lower case.
Example: Lower("David") returns the string "david". - Upper("STRING")
Converts all of the characters in the STRING to upper case.
Example: Upper("David") returns the string "DAVID". - IsNullOrEmpty("STRING")
Returns "true" if and only if the VARIABLE is null or empty.
Example: IsNullOrEmpty("NotEmpty") returns "false".
Example: IsNullOrEmpty("") returns "true".
Example: IsNullOrEmpty("{~undefinedvariable~}") returns "true".
Note: A variable can also be used in this function. It is possible to pass a variable as string (IsNullOrEmpty("{~variable~}")) or directly (IsNullOrEmpty(variable)).
Date and Time
By default, Fabasoft app.test uses following format:
- dd.MM.yyyy (date)
- HH:mm:ss (time)
Date and time values can be formatted with following functions:
As locale the Java locale of Fabasoft app.test is used by default. But the locale can also be defined within the test.
Example |
Java.Locale = "en" Java.Locale = "de" // deletes the parameter Java.Locale = null |
For parsing and formatting date values the predefined Java format DateFormat.SHORT is used, for time values DateFormat.MEDIUM.
See http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html.
Example |
// formats the current date or time based on the locale d = DateFormat() t = TimeFormat() // parses and formats the string based on the locale d = DateFormat("DATE") t = TimeFormat("TIME") // parses the string based on the locale and formats based on the pattern d = DateFormat("DATE", "PATTERN") t = TimeFormat("TIME", "PATTERN") // parses and formats the location value based on the locale d = DateFormat() @LOCATION t = TimeFormat() @LOCATION // parses the location value based on the locale and formats based on the pattern d = DateFormat("PATTERN") @LOCATION t = TimeFormat("PATTERN") @LOCATION // calculations d = DateFormat(datenow + 365) t = TimeFormat(timenow - 60) |
Scripting
There are two different types how to start a script. On the one hand, a script can be executed directly and on the other hand by calling a script file.
ExecuteScript
When ExecuteScript is started, JavaScript is executed by default. The fsc annotated calls are forwarded to the backend. The script is called within the context of the web browser session.
Here are a few examples how to work with ExecuteScript:
Example |
// execute JavaScript (default) val = ExecuteScript("return document.querySelectorAll('.FscH').length") @document(0) // execute an expression with fsc and timeout [fsc, Timeout=130000] val = ExecuteScript("coouser.FSCEXPEXT@1.1001:Sleep(126000);") @document(0) selcount = ExecuteScript("return vapportlet.active.GetSelection(). getKeys().length”) @document(0). main.listbox(“{~fo~} – {~folistview~}”) |
The result of ExecuteScript can be saved in a variable. It is also important to specify a location (@document(0)) to run the script in the correct web browser window.
ExecuteScriptFromFile
The ExecuteScriptFromFile behaves in exactly the same way as the ExecuteScript, with the only difference that a file containing a script is executed. In the function the path of the file is specified.
Example |
tmpjsfile = "somepath/somejavascriptfile.js" tmpobjclass = ExecuteScriptFromFile("{~tmpjsfile~}") @document.region("Aktionen").heading |
When specifying the variable in the function which contains the path, it is necessary to write it under apostrophes (ExecuteScriptFromFile("{~tmpjsfile~}"). In addition, a location must be defined to run the script in the correct web browser window.
Location-Based Functions
The following functions can be used to retrieve attributes and values from locations:
- GetValue
Returns the value of the location (e.g. of an input field). - GetName
Returns the label of the location.
This should be the preferred property when the value is used to build a locator - Exists
Returns whether the location exists. - Count
Returns the number of child elements of the location. - GetAddress
Returns the object address (e.g. COO.15.512.3.123) of the object defined by the location. - IsSelected
Returns whether the location (row or cell in a list) is selected. - IsReadonly
Returns whether the location (e.g. an input field) is read-only. - IsRequired
Returns whether the location (e.g. an input field) is mandatory. - GetDescription
Returns the description of a location. - GetLanguage
Returns the language of the location as defined by the the lang or xml:lang attribute.
Example |
Assert("{~replacedoc~}"==GetValue) @LOCATION ger = Exists @LOCATION Assert("5"==Count("row")) @LOCATION branches = Count @LOCATION ooaddr1 = GetAddress @LOCATION Assert(IsSelected) @LOCATION Assert(IsReadonly) @LOCATION Assert(IsChangeable) @LOCATION Assert(IsRequired) @LOCATION errorvalue = GetDescription @LOCATION |
File System
Following functions can be used to access the file system:
- WriteFile("PATH", "CONTENT", "FLAG")
Replaces the content of the file denoted by PATH with CONTENT and returns the absolute path of the file. Creates the file if it does not exist. FLAG indicates the encoding of CONTENT. - AppendFile("PATH", "CONTENT", "FLAG")
Writes CONTENT to the end of the file denoted by PATH and returns the absolute path of the file. Creates the file if it does not exist. FLAG indicates the encoding of CONTENT. - ReadFile("PATH", "FLAG")
Returns the content of the file denoted by PATH. FLAG indicates the encoding of the file content.
A path may be absolute or relative, the latter starting from exportdocs.
The following flags can be used:
- plain
Use this flag to read or write plain text. - base16
Use this flag to read or write hexadecimal-encoded binary content. - base64
Use this flag to read or write base64-encoded binary content.
Example |
file = WriteFile("hello.txt", "Hello World!", "plain") Assert("{~file~}"=="{~exportdocs~}hello.txt") content = ReadFile("{~file~}", "plain") Assert("{~content~}"=="Hello World!") |