Using Functions

Introduction

It is often useful when building Test Cases to enter values which are tailored to their context. In Provar this is done using functions.

This page describes each function available and how it can be used.

Use the following links to navigate to the relevant section:

Usage

Functions generally have brackets () after the function name. String parameters to be passed into functions should be within double quotes (“e.g.”).

Function definitions are also available in the Assistant when a specific function is highlighted in the variable picker.

Date Functions

Date Add

This function adds a defined number of days to a given date to create a later date value. This is useful for avoiding hardcoding a date in a Test Step, e.g. populating an Opportunity Close Date to be 5 days after today’s date.

Format: DateAdd(date,amount,unit)

There are two internal functions which are useful when managing dates:

  • TODAY will create a date and use the system date
  • NOW will create a date timestamp and use the system date

Examples:

  • {TODAY} – This will default to system date, e.g. 2015-01-16
  • {NOW} – This will default to system date and time, e.g. 2015-01-16 10:13:43.0
  • {DateAdd(TODAY,1)} – This will default to tomorrow, e.g. 2015-01-17
  • {DateAdd(TODAY,”-1″)} – This will default to yesterday, e.g. 2015-01-15
  • {DateAdd(TODAY,1,MONTH)} – This will add one month to current date, e.g. 2015-02-16
  • {DateAdd(NOW,”-2″,HOUR)} – This will remove two hours from current datetime, e.g. 2015-01-16 08:15:27.0

Date Format

This function converts a date into a specific format. Refer to SimpleDateFormat for more information on available date formats.

Format: DateFormat(date,output format,timezone)

Examples:

  • {DateFormat()} – Defaults to system date in the format yyyy-MM-dd, e.g. 2015-01-16
  • {DateFormat(TODAY,”MM-dd-YYYY”)} – Modify date format to be month-first, e.g. 01-16-2015
  • {DateFormat(DateAdd(TODAY,5),”MM-dd-YYYY”)} – Use with other functions, e.g. 01-21-2015
  • {DateFormat(NOW,”MM-dd-YYYY hh a zzzz”,”GMT”)} – Including a timezone, e.g. 01-16-2015 10 AM Greenwich Mean Time

Date Parse

This function converts a date from a String into a Date.

FormatDateParse(DateString,InputFormat,OutputFormat)

Examples:

  • {DateParse(“2015-03-15”, “yyyy-MM-dd”)} – Will return this string as a date, e.g. 2015-03-15
  • {DateParse(“2015-03-15”, “yyyy-MM-dd”,”MM-dd-yyyy”)} – Will return this string as a date and convert the date into a new format, e.g. 03-15-2015

List Functions

Count

This function counts the number of items in a list. This is useful in conjunction with checking the number of values returned when executing a SOQL or SQL Test Step.

FormatCount(List)

Examples:

  • {Count(AccountRows)} – If there are two accounts returned, this function will return 2
  • {Count(AccountRows) > 0} – This can be used in expressions and used in conjunction with a With Row Test Step. This expression will return true or false

IsSorted

This function tests whether a supplied list of values is Sorted in Ascending or Descending order.

FormatIsSorted(Values,’Name/ColNumber,Order,Type,Format’)

Examples:

  • {IsSorted(Col.columns.dueDateTimeColumnMain.columnValues, “1 ASC DATE dd/MM/yyyy hh:mm aaa”)} – Results true if supplied list of values with mentioned dateformat is in Ascending order
  • {IsSorted(Col.columns.caseNumber.columnValues, “1 DESC”)} – Results true if supplied list of values with default type and format is in Descending order

String Functions

String Trim

This function trims whitespace from a string.

FormatStringTrim(SourceString, TrimType)

Examples:

  • {StringTrim(”     String     “)} – This will default to trimming both ends of the string, e.g. “String.
  • {StringTrim(”     String     “, LEADING)} – This will remove white space just at the beginning of the string, e.g. “String     “

String Replace

Use this function when you need to modify parameterize a body of text.

FormatStringReplace(SourceString, FindString, ReplaceString)

Examples:

  • {StringReplace(“Dear Customer”, “Customer”, CustomerName)} – Where CustomerName is a Variable, e.g. “Dear David”
  • {StringReplace(Template, “TODAYSDATE”, TODAY)} – Where Template is a file from the file system with the text “Today is TODAYSDATE”, e.g. Today is 2015-01-16

String Normalize

This function compares strings.

Format: StringNormalize(SourceString,trimlines)

Examples:

  • {StringNormalize(“Extra space              Extra space”)} – Remove consecutive whitespace, e.g. “Extra space Extra space”
  • {StringNormalize(“Carriage return\r\nCarriage Return”)} – Replace carriage return and line feed with line feed, e.g. “Carriage return\nCarriage Return”
  • {StringNormalize(”        leading and end space       “)} – Remove leading and trailing whitespace, e.g. “leading and end space”
  • {StringNormalize(”        leading and end space   “} – Option to remove leading and trailing spaces for each line, e.g. “leading and end space\ntest lines” test lines      “,true)}

Other Functions

Unique Id

This function generates a unique value. This is typically used in a Set Values Test Step to create a variable, which can then be referred to to generate and identify test data during a test.

FormatUniqueId(Length, Format)

Examples:

  • {UniqueId(12,”NUMERIC”)} – This will generate a unique ID length 12 and a Number, e.g. 412373164167
  • {UniqueId(12,”ALPHA”)} – This will generate a unique ID length 12 and Alpha, e.g. GTWAWNZYWSIC
  • {UniqueId(8)} – This will generate a unique ID length 8 and defaults to Alphanumeric, e.g. I67OOO54
  • {UniqueId(36,”UUID”)} – This will generate a unique ID length 36 and will create a universally unique id

Round

This function rounds a number to a defined specification.

FormatRound(number,decimal places,rounding mode)

Examples:

  • {Round(3.2)} – Defaults to 0 decimal places, e.g. 3
  • {Round(3.4444,2)} – Round to 2 decimal places, e.g. 3.44
  • {Round(3.999,2,DOWN)} – Round Down, e.g. 3.99
  • {Round(3.999,2,UP)} – Round Up, e.g. 4.0

2017-05-12T11:35:04+00:00

Leave A Comment