Skip to content

User_Guide_Functions

Angleton, Denis edited this page Mar 31, 2015 · 15 revisions

Datafiles | Contents | Tools

Functions and Variables

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.

ioFunctions

  • getCSVData(String fileName) -- Gets the value of the first columnNumber from the specified csv file. equivalent of calling getCSVData(fileName, 0, false)
    Parameters:
    1. 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:

    1. fileName: String indicating the name of the csv file to read data from.
    2. 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:
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.

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:
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.

Parameters:
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

String Functions

concat(String ... values) -- Concatenates the given strings

Parameters:
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.

Parameters:
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.

Parameters:
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

Parameters:
1.  length: Integer the length of the random string

randomAlphaUpper(int length) -- Generates a random string consisting of upper case alphabets of given length

Parameters:
1.  

randomAlphaMixed(int length) -- Generates a random string consisting of lower and upper case alphabets of given length

Parameters:
1.  length: Integer the length of the random string

randomAlphaNumeric(int length) -- Generates a random string consisting of numerals of given length

Parameters:
1.  length: Integer the length of the random string

randomAlphaSpecial(int length) -- Generates a random string consisting of special characters of given length

Parameters:
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

Parameters:
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

Parameters:
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

Parameters:
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

Parameters:
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

Parameters:
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.

Parameters:
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

Parameters:
1.  toEncode: String the string to base 64 encoding

fromBase64(String toDecode) -- Will decode the given string from base64 format

Parameters:
1.  toDecode: String the base64 string to decode

urlEncode(String toEncode) -- Will encode the given string using URLEncoder

Parameters:
1.  toEncode: String the string to encode

urlDecode(String toDecode) -- Will decode the given string Using URLDecoder

Parameters:
1.  toDecode: String the encoded string to decode

Date Functions

addDays(int days, String format) -- Adds days to the current date.

Parameters:
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.

Parameters:
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)

Parameters:
`#{dateFunctions.currentTimeMilis()}`
produces a long number like '1357842009812'

Monetary Functions

randomPositive(int length) -- Gets a random positive money amount.

Parameters:
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.

Parameters:
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

Numeric Functions

add(double... values) -- Adds a list of values

Parameters:
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

Parameters:
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

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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

Tax Functions

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:
1.  startSSN: Integer The starting number to use as a ssn.

`#{taxFunctions.getSsn(562000000)}`
returns the next ssn requested after the given number.