-
Notifications
You must be signed in to change notification settings - Fork 61
User_Guide_Functions
Functions can be used to manipulate data during test execution. They can be used anywhere in place of a Value.
Functions and Variables both use the same format. They start with either
a # or $ and then are enclosed in parentheses. e.g.
#{functionType.function(param, param2)} or
Functions or variables can be nested in other functions. e.g. #{stringFunctions.base64(ioFunctions.getFileData(fileName)} In this example the variable is fileName which is passed to the getFileDataFunction which is passed to the base64 function.
There are 6 built in function types.
- ioFunctions
- stringFunctions
- dateFunctions
- monetaryFunctions
- numericFunctions
- taxFunctions
Declaring the function
#{stringFunctions.concat('Intuit ', 'Tank ',' Rocks')}
would yield
"Intuit Tank Rocks".
Declaring the function #{numericFunctions.mod(authId, 10)}
with the
variable ${authId} defined as 51 would result in 51 % 10 = 1.
getCSVData()
: Gets the value of the first column from the default csv file. equivalent of calling getCSVData('csv-data.txt', 0, false) (deprecated - use explicit csv file name)
\#{ioFunctions.getCSVData()}
returns the first column in the default csv file.
getCSVData(int columnIndex)
: Gets the value of the specified column from the default csv file. equivalent of calling getCSVData('csv-data.txt', columnIndex, false) (deprecated - use explicit csv file name)
1. columnIndex: Integer Zero indexed column number.
\#{ioFunctions.getCSVData(0)}
returns the first column in the default csv file.
getCSVData(int columnIndex, boolean loop)
: Gets the value of the specified column from the default csv file with the specified looping behavior. equivalent of calling getCSVData('csv-data.txt', columnIndex, loop) (deprecated - use explicit csv file name)
1. columnIndex: Integer Zero indexed column number.
2. loop: Boolean true to go back to the first line after all lines
are read.
\#{ioFunctions.getCSVData(0, true)}
returns the first column in the default csv file and loop if it uses
all lines.
getCSVData(String fileName)
: Gets the value of the first columnNumber from the specified csv file. equivalent of calling getCSVData(fileName, 0, false)
1. fileName: String indicating the name of the csv file to read
data from.
\#{ioFunctions.getCSVData('myData.csv')}
returns the first column in the csv file myData.csv.
getCSVData(String fileName, int columnIndex)
: Gets the value of the specified columnNumber from the specified csv file. equivalent of calling getCSVData(fileName, columnIndex, false)
1. fileName: String indicating the name of the csv file to read
data from.
2. columnIndex: Integer Zero indexed column number.
\#{ioFunctions.getCSVData('myData.csv', 1, true)}
returns the second column in the csv file myData.csv.
getCSVData(String fileName, int columnIndex, boolean loop)
: Gets the value of the specified columnNumber from the specified csv file.
1. fileName: String indicating the name of the csv file to read
data from.
2. columnIndex: Integer Zero indexed column number.
3. loop: Boolean true to go back to the first line after all lines
are read.
\#{ioFunctions.getCSVData('myData.csv', 1, true)}
returns the second column in the csv file myData.csv.
getFileData(String fileName)
: Reads the specified file and returns it as a String.
1. fileName: String indicating the name of the csv file to read
data from.
\#{ioFunctions.getFileData('myData.txt')}
returns the contents of the file myData.txt as a String
getFileBytes(String fileName)
: Reads the specified file and returns it as a byte array (byte[]). This function can only be used as input to another function that returns a String such as base64Encode.
1. fileName: String indicating the name of the csv file to read
data from.
\#{ioFunctions.getFileBytes('myData.txt')}
returns the contents of the file myData.txt as a String
concat(String ... values)
: Concatenates the given strings
1. values: Strings(comma seperated) The strings to concatenate
\#{stringFunctions.concat('Turbo', 'Scale', ' Rocks')}
will return Intuit Tank Rocks
substring(String subject, int start, int stop)
: Returns a new string that is a substring of subject. The substring begins at the specified start and extends to the character at index stop - 1. Thus the length of the substring is stop-start.
1. subject: String the string from which the substring is to be
found (required)
2. start: Integer the start index for the substring(inclusive)
(required)
3. stop: Integer the index at which to end the substring(exclusive)
(optional)
\#{stringFunctions.substring('hello world', 6)}
returns world and
\#{stringFunctions.substring('hello world', 0, 5)}
returns hello
substringBetween(String subject, String open, String close, int index)
: Returns the String that is nested in between two Strings.
1. subject: String the string from which the substring is to be
found (required)
2. open: the String before the substring, may be null (if null will
return the substring before the first occurance of the close
param) (required)
3. close: the String after the substring, may be null (if null will
return the substring after the last occurance of the open param)
(required)
4. index: the zero based index of the string to return. (optional)
\#{stringFunctions.substringBetween('yabcz', 'y', 'z')}
returns abc and
\#{stringFunctions.substringBetween('yabcz ydefz', 'y', 'z', 1)}
returns def
randomAlphaLower(int length)
: Generates a random string consisting of lower case alphabets of given length
1. length: Integer the length of the random string
randomAlphaUpper(int length)
: Generates a random string consisting of upper case alphabets of given length
1.
randomAlphaMixed(int length)
: Generates a random string consisting of lower and upper case alphabets of given length
1. length: Integer the length of the random string
randomAlphaNumeric(int length)
: Generates a random string consisting of numerals of given length
1. length: Integer the length of the random string
randomAlphaSpecial(int length)
: Generates a random string consisting of special characters of given length
1. length: Integer the length of the random string
randomAlphaMixedNumeric(int length)
: Generates a random string consisting of lower and upper case alphabets and numerals of given length
1. length: Integer the length of the random string
randomAlphaMixedSpecial(int length)
: Generates a random string consisting of lower and upper case alphabets and special characters of given length
1. length: Integer the length of the random string
randomAlphaMixedNumericSpecial(int length)
: Generates a random string consisting of lower and upper case alphabets, numerals and special characters of given length
1. length: Integer the length of the random string
userIdDate(int prefixLength, String format)
: Generates a Random String suitable for a user ID by combining a random character string and a date
1. prefixLength: Integer (required) The number of characters to use
for the prefix.
2. format: String (required) The date format string to use. If
empty, will use default for locale.
\#{stringFunctions.userIdDate(4,'yyyy-MM-dd')}
produces 'GdGE2011-11-15' on November 15, 2011
userIdFromDate(int prefixLength, String format)
: Generates a Random String suitable for a user ID by combining a random character string and a date
1. prefixLength: Integer (required) The number of characters to use
for the prefix.
2. format: String (required) The date format string to use. If
empty, will use default for locale.
\#{stringFunctions.userIdFromDate(4,'yyyy-MM-dd')}
produces 'GdGE2011-11-15' on November 15, 2011
userIdFromRange(int minId, int maxId)
: Generates a Integer user Id from the given range. Will distribute these ids equally among the different agents.
1. minId: Integer (required) The minmum id of the range.
2. maxId: Integer (required) The maximum id of the range.
\#{stringFunctions.userIdFromRange(1,1000)}
produces an unique integer between 1 and 1000
toBase64(String toEncode)
: Will encode the given string to base64 format
1. toEncode: String the string to base 64 encoding
fromBase64(String toDecode)
: Will decode the given string from base64 format
1. toDecode: String the base64 string to decode
urlEncode(String toEncode)
: Will encode the given string using URLEncoder
1. toEncode: String the string to encode
urlDecode(String toDecode)
: Will decode the given string Using URLDecoder
1. toDecode: String the encoded string to decode
addDays(int days, String format)
: Adds days to the current date.
1. days: Integer The number of days. Pass in a negative value to
subtract days.
2. format: String The date format string to use. If empty, will use
default for locale.
\#{dateFunctions.addDays(5,'yyyy-MM-dd')}
produces '2011-11-20' on November 15, 2011
currentDate(String format, String timeZone)
: Current Date. Get the current date.
1. format: String The date format string to use. If empty, will use
default for locale.
2. timeZone: String (optional) The timezone to use. ()e.g. 'PST',
'America/Los\_Angeles', or 'GMT'). If empty, will use default
for locale.
\#{dateFunctions.currentDate('yyyy-MM-dd', 'PST')}
produces '2011-11-15' on November 15, 2014
currentTimeMilis()
: Gets the current Time in miliseconds since January 1, 1970. (Unix epoch time)
\#{dateFunctions.currentTimeMilis()}
produces a long number like '1357842009812'
randomPositive(int length)
: Gets a random positive money amount.
1. length: Integer (required) The number of digits in the whole
amount.
\#{monetaryFunctions.randomPositive(3)}
produces a random monetary amount between 100.00 and 999.99
randomNegative(int length)
: Gets a random negative money amount.
1. length: Integer (required) The number of digits in the whole
amount.
\#{monetaryFunctions.randomNegative(3)}
produces a random monetary amount between -100.00 and -999.99
add(double... values)
: Adds a list of values
1. values: Doubles (required) Variable number of number to add
together.
\#{numericFunctions.add(3,2,6)}
results in 3 + 2 + 6 = 11
subtract(double... values)
: Subtracts a list of values from the first value
1. values: Doubles (required) Variable number of number to subtract
\#{numericFunctions.subtract(10,2,3)}
results in 10 - 2 - 3 = 5
mod(int value, int modulo)
: Preforms a modulo operation, or the whole remainder of a division operation
1. value: Integer (required) The number ot modulo.
2. modulo: Integer (required) The.
\#{numericFunctions.mod(5,4)}
results in 5 % 4 = 1
randomPositiveWhole(int length)
: Gets a random positive integer value.
1. length: Integer (required) The number of digits in the whole
amount.
\#{numericFunctions.randomPositiveWhole(3)}
produces a random value between 100 and 999
randomNegativeWhole(int length)
: Gets a random negative integer value.
1. length: Integer (required) The number of digits in the whole
amount.
\#{numericFunctions.randomNegativeWhole(3)}
produces a random value between -100 and -999
randomPositiveFloat(int length, int decimalPlaces)
: Gets a random positive float value.
1. length: Integer (required) The number of digits in the whole
amount.
2. decimalPlaces: Integer (required) The number of digits after the
decimal.
\#{numericFunctionS.randompPositiveFloat(3,2)}
produces a random value between 100.00 and 999.99
randomNegativeFloat(int length, int decimalPlaces)
: Gets a random negative float value.
1. length: Integer (required) The number of digits in the whole
amount.
2. decimalPlaces: Integer (required) The number of digits after the
decimal.
\#{numericFunctions.randomNegativeFloat(3,2)}
produces a random value between -100.00 and -999.00
random(int min, int max)
: Gets a random negative float value.
1. min: Integer (optional) The minimum value to return. default 0.
2. max: Integer (required) maximum value to return.
\#{numericFunctions.random(4,10)}
produces a random value between 4 and 10
getSsn(long startSSN)
: Gets a valid Social Security Number starting at at specific number. Each user will get a unique ssn. range is divided evenly across all agents.
1. startSSN: Integer The starting number to use as a ssn.
\#{taxFunctions.getSsn(562000000)}
returns the next ssn requested after the given number.