-
Notifications
You must be signed in to change notification settings - Fork 61
User_Guide_Functions
Contents | Preface | Introduction | Projects | Scripts | Filters | Datafiles | Functions | Tools | Users | Admin
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
${functionType.function(param, param2)}
. Variables have no parentheses.
e.g. ${varName}
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(String fileName) -- Gets the value of the first columnNumber from the specified csv file. equivalent of calling getCSVData(fileName, 0, false)
Parameters:
- fileName: String indicating the name of the csv file to read data from.
Example
#{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)
Parameters:
- fileName: String indicating the name of the csv file to read data from.
- columnIndex: Integer Zero indexed column number.
Example
#{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.
Parameters:
- fileName: String indicating the name of the csv file to read data from.
- columnIndex: Integer Zero indexed column number.
- loop: Boolean true to go back to the first line after all lines are read.
Example
#{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.
Parameters:
- fileName: String indicating the name of the csv file to read data from.
Example
#{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.
Parameters:
- fileName: String indicating the name of the csv file to read data from.
Example
#{ioFunctions.getFileBytes('myData.txt')}
returns the contents of the file myData.txt as a String
-
concat(String ... values) -- Concatenates the given strings
Parameters:
- values: Strings(comma separated) The strings to concatenate
Example
#{stringFunctions.concat('Turbo', 'Scale', ' Rocks')}
returns 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.
Parameters:
- subject: String the string from which the substring is to be found (required)
- start: Integer the start index for the substring(inclusive) (required)
- stop: Integer the index at which to end the substring(exclusive) (optional)
Example
#{stringFunctions.substring('hello world', 6)}
returns world#{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.
Parameters:
- subject: String the string from which the substring is to be found (required)
- open: the String before the substring, may be null (if null will return the substring before the first occurrence of the close param) (required)
- close: the String after the substring, may be null (if null will return the substring after the last occurrence of the open param) (required)
- index: the zero based index of the string to return. (optional)
Example
#{stringFunctions.substringBetween('yabcz', 'y', 'z')}
returns abc#{stringFunctions.substringBetween('yabcz ydefz', 'y', 'z', 1)}
returns def -
randomAlphaLower(int length) -- Generates a random string consisting of lower case alphabets of given length
Parameters:
- length: Integer the length of the random string
-
randomAlphaUpper(int length) -- Generates a random string consisting of upper case alphabets of given length
Parameters:
- length: Integer the length of the random string
-
randomAlphaMixed(int length) -- Generates a random string consisting of lower and upper case alphabets of given length
Parameters:
- length: Integer the length of the random string
-
randomAlphaNumeric(int length) -- Generates a random string consisting of numerals of given length
Parameters:
- length: Integer the length of the random string
-
randomAlphaSpecial(int length) -- Generates a random string consisting of special characters of given length
Parameters:
- 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
Parameters:
- 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
Parameters:
- 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
Parameters:
- 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
Parameters:
-
prefixLength: Integer (required) The number of characters to use for the prefix.
-
format: String (required) The date format string to use.
Example
#{stringFunctions.userIdDate(4,'yyyy-MM-dd')}
returns '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
Parameters:
- prefixLength: Integer (required) The number of characters to use for the prefix.
- format: String (required) The date format string to use.
Example
#{stringFunctions.userIdFromDate(4,'yyyy-MM-dd')}
returns 'GdGE2011-11-15' on November 15, 2011 -
userIdFromRange(int minId, int maxId) -- Generates an Integer user Id from the given range. Will distribute these ids equally among the different agents.
Parameters:
- minId: Integer (required) The minimum id of the range.
- maxId: Integer (required) The maximum id of the range.
Example
#{stringFunctions.userIdFromRange(1,1000)}
returns an unique integer between 1 and 1000 -
toBase64(String toEncode) -- Will encode the given string to base64 format
Parameters:
- toEncode: String the string to base 64 encoding
-
fromBase64(String toDecode) -- Will decode the given string from base64 format
Parameters:
- toDecode: String the base64 string to decode
-
urlEncode(String toEncode) -- Will encode the given string using URLEncoder
Parameters:
- toEncode: String the string to encode
-
urlDecode(String toDecode) -- Will decode the given string Using URLDecoder
Parameters:
- toDecode: String the encoded string to decode
-
addDays(int days, String format) -- Adds days to the current date.
Parameters:
- days: Integer The number of days. Pass in a negative value to subtract days.
- format: String The date format string to use. If empty, will use default for locale.
Example
#{dateFunctions.addDays(5,'yyyy-MM-dd')}
returns '2011-11-20' on November 15, 2011 -
currentDate(String format, String timeZone) -- Current Date. Get the current date.
Parameters:
- format: String The date format string to use. If empty, will use default for locale.
- timeZone: String (optional) The timezone to use. (e.g. 'PST', 'America/Los_Angeles', or 'GMT'). If empty, will use default for locale.
Example
#{dateFunctions.currentDate('yyyy-MM-dd', 'PST')}
returns '2011-11-15' on November 15, 2014 -
currentTimeMilis() -- Gets the current Time in milliseconds since January 1, 1970. (Unix epoch time)
Example
#{dateFunctions.currentTimeMilis()}
returns a long number like '1357842009812'
-
randomPositive(int length) -- Gets a random positive money amount.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
Example
#{monetaryFunctions.randomPositive(3)}
returns a random monetary amount between 100.00 and 999.99 -
randomNegative(int length) -- Gets a random negative money amount.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
Example
#{monetaryFunctions.randomNegative(3)}
returns a random monetary amount between -100.00 and -999.99
-
add(double... values) -- Adds a list of values
Parameters:
- values: Doubles (required) Variable number of number to add together.
Example
#{numericFunctions.add(3,2,6)}
returns 11 (3 + 2 + 6 = 11) -
subtract(double... values) -- Subtracts a list of values from the first value
Parameters:
- values: Doubles (required) Variable number of number to subtract
Example
#{numericFunctions.subtract(10,2,3)}
returns 5 (10 - 2 - 3 = 5) -
mod(int value, int modulo) -- Preforms a modulo operation, or the whole remainder of a division operation
Parameters:
- value: Integer (required) The number of modulo.
- modulo: Integer (required) The.
Example
#{numericFunctions.mod(5,4)}
returns 1 (5 % 4 = 1) -
randomPositiveWhole(int length) -- Gets a random positive integer value.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
Example
#{numericFunctions.randomPositiveWhole(3)}
returns a random value between 100 and 999 -
randomNegativeWhole(int length) -- Gets a random negative integer value.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
Example
#{numericFunctions.randomNegativeWhole(3)}
returns a random value between -100 and -999 -
randomPositiveFloat(int length, int decimalPlaces) -- Gets a random positive float value.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
- decimalPlaces: Integer (required) The number of digits after the decimal.
Example
#{numericFunctionS.randompPositiveFloat(3,2)}
returns a random value between 100.00 and 999.99 -
randomNegativeFloat(int length, int decimalPlaces) -- Gets a random negative float value.
Parameters:
- length: Integer (required) The number of digits in the whole amount.
- decimalPlaces: Integer (required) The number of digits after the decimal.
Example
#{numericFunctions.randomNegativeFloat(3,2)}
returns a random value between -100.00 and -999.00 -
random(int min, int max) -- Gets a random negative float value.
Parameters:
- min: Integer (optional) The minimum value to return. default 0.
- max: Integer (required) maximum value to return.
Example
#{numericFunctions.random(4,10)}
returns 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.
Parameters:
- startSSN: Integer The starting number to use as a ssn.
Example
#{taxFunctions.getSsn(562000000)}
returns the next ssn requested after the given number.
Contents | Preface | Introduction | Projects | Scripts | Filters | Datafiles | Functions | Tools | Users | Admin