Random Data Generation - dn0000001/test-automation GitHub Wiki

NOTE: This is based on an older version of datainstaller. Some of generators have switched the parameters.

The class datainstiller.data.DataGenerator is responsible for random data generation. There are the following generaters (Name - Alias):

  • AddressGenerator - ADDRESS
  • AlphaNumericGenerator - ALPHANUMERIC
  • CustomListGenerator - CUSTOM_LIST
  • DateGenerator - DATE
  • HumanNameGenerator - HUMAN_NAMES
  • WordGenerator - WORD
  • NumberGenerator - NUMBER
  • File2ListGenerator - FILE2LIST

#Examples:

<user-profile-do>
  <aliases>
    <!-- Any Sex Name -->
    <firstName>$[HUMAN_NAMES('{A}','null')]</firstName>
    <!-- Surname -->
    <lastName>$[HUMAN_NAMES('{S}','null')]</lastName>
    <!-- Number between 200 inclusive and 999 exclusive with format "000" -->
    <areaCode>$[NUMBER('000','200,999')]</areaCode>
    <!-- Address format of street number + ' ' + street name + ' ' + city + ' ' + province code + ' ' + country -->
    <address>$[ADDRESS('{#} {S}, {T} {K}, {C}','null')]</address>
    <!-- 3 words, first word starts with uppercase 2nd and 3rd words are start with lowercase -->
    <tagLine>$[WORD('|A| {b} {c}','null')]</tagLine>
    <!-- Date from 2016/01/01 inclusive to 2016/12/31 exclusive in format dd MMM yyyy -->
    <date1>$[DATE('dd MMM yyyy','2016/01/01|2016/12/31|yyyy/MM/dd')]</date1>
    <!-- Pick aaa or bbb or ccc -->
    <custom1>$[CUSTOM_LIST('null', 'aaa, bbb, ccc')]</custom1>
    </aliases>
    ...
</user-profile-do>

Patterns for Generators:

Note: Generators can only be defined in the alias node.

AddressGenerator - ADDRESS

{C} - country
{#} - street number
{S} - street name
{T} - city
{P} - province name
{K} - province code
{O} - postal code

Example:
$[ADDRESS('{#} {S}, {T} {K}, {C}','null')]

AlphaNumericGenerator - ALPHANUMERIC

(a)..(z) - lower-case letter
(A)..(Z) - upper-case letter
[a]..[Z] - digit between 0-9
|a|..|z| - lower-case letter or number
|A|..|Z| - upper-case letter or number
{a}..{Z} - any-case letter or number
Note: Same symbol represents same letter Ex: '(a)(b){a}[z][Z][z]' - 'drd101' or 'xwx828'

Example:
$[ALPHANUMERIC('{a}{b}{c}{d}{e}', 'null')]

CustomListGenerator - CUSTOM_LIST

$[CUSTOM_LIST('null', '{item1}, {item2}, {itemN}')]
Note: Items are separated by a comma

Example:
$[CUSTOM_LIST('null', 'aaa, bbb, ccc')]

DateGenerator - DATE

$[DATE('{date_return_format}','{from_date_inclusive}|{to_date_exclusive}|{date_input_format}')]
Note: For date format patterns see SimpleDateFormat

Example:
$[DATE('dd MMM yyyy','2016/01/01|2016/12/31|yyyy/MM/dd')]

HumanNameGenerator - HUMAN_NAMES

{F} - Female Name
{M} - Male Name
{A} - Any Sex Name
{S} - Surname

Example:
$[HUMAN_NAMES('{S}','null')]

WordGenerator - WORD

{A}-{Z} or {a}-{z}: Replaced by random English word, if tag contains upper-case letter word will be in upper-case and if tag contains lower-case letter word will be in lower-case
[A]-[z]: Replaced by random English word, with random letter casing
|A|-|z|: Replaced by capitalized random English word
{A:0-9}-{Z:0-9} or {a:0-9}-{z:0-9}: Replaced by number (1-9) of upper-case or lower-case characters from the start of random English word, if number is 0 then replaced word will have random number between 1 to 9 of characters.
[A:0-9]-[Z:0-9] - Replaced by number (1-9) of random letter casing characters from the end of random English word, if number is 0 then replaced word will have random number between 1 to 9 of characters

Additional rules:
Same tag in pattern will be replaced by the same word
Ex: {A},{A} - 'SLEEP,SLEEP', {c:3}{c:3} - 'tortor', [B:2][B:2] - 'POPO'
[A] and {A} are not replaced by the same word

Example:
$[WORD('|A| {b} {c}','null')]

NumberGenerator - NUMBER

$[NUMBER('{format}','{min inclusive},{max exclusive}')]
Note: For format patterns see DecimalFormat

Example:
$[NUMBER('000','200,999')]

File2ListGenerator - FILE2LIST

$[FILE2LIST('null', '{text_file}')]
Note: This generator should not really be used. The file must be a text file and it will return a random line from the file.

⚠️ **GitHub.com Fallback** ⚠️