Generate Sample Data
Constant random values
Every SAMPLE command generates a new randomized value. In the event where you want to use the same randomized value generated by the SAMPLE command in other places within the current test (eg. generating a randomized email to be used in multiple places in the same test case), we can assign a token to it.
Note: A token is a string value that you give and we would usually recommend assigning identifiable tokens.
// Example
// If in this test run, SAMPLE.email({}, "user1") generates `[email protected]` as the value,
// every command that uses SAMPLE.email({}, "user1") will have `[email protected]` as the value.
I.fill("Login", SAMPLE.email({}, "user1")) // "user1" is the token chosen by the developer
I.fill("Password", "simplepassword")
I.click("Log In")
I.see(SAMPLE.email({}, "user1")) // "user1" is the token chosen by the developer
List of commands
Command | Description |
---|---|
SAMPLE.id | Generates a random string useful for IDs and passwords |
SAMPLE.phone | Generates a random phone number |
SAMPLE.last | Generates a random last name |
SAMPLE.first | Generates a random first name |
SAMPLE.name | Generates a random full name |
SAMPLE.email | Generates a random email address |
SAMPLE.id
Generates a random string useful for IDs and password.
The base58 character set is used to generate the string. This avoids the use of similar characters like the capital letter "O" and the number "0" to avoid confusion when reading it.
Usage
SAMPLE.id(length, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
length | integer (optional) | Length of the string to generate |
token | String (optional) | A string acting as a seed to generate the last name. See examples of how it is used. |
Example
var password = SAMPLE.id(12)
I.fill("Password", password)
Generates a 12-character long random base58 string as the password to be used as input data for the "Password" field.
SAMPLE.phone
Generates a random phone number.
This command is based on ChanceJS library. It generates a random phone number or specific to a certain nationality.
Usage
SAMPLE.phone(map, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
map | JSON Map (optional) | takes in a JSON map that can contain token and nationality. Nationality supports only us , uk and fr . |
token | String (optional) | A string acting as a seed to generate the last name. See examples of how it is used. |
Example
let phone = SAMPLE.phone()
I.fill("Phone Number", phone)
Generates a random formatted phone number to be used as input data for the "Phone Number" field.
// One way of adding token
let abc = SAMPLE.phone({}, "Adam's phone")
let efg = SAMPLE.phone({}, "Adam's phone")
// Another way of using token
let one_phone = SAMPLE.phone({token: "Adam's phone"})
let two_phone = SAMPLE.phone({token: "Adam's phone"})
Every command in this example will generate the same phone number due to the token Adam's phone
.
SAMPLE.phone({
formatted: false, // true/false; to format the number such as (494) 927-2152
country: 'uk', // uk/us/fr; the phone number in the country
mobile: true // true/false; only applicable to `uk` and `fr`
})
Generates a random uk phone number that is not formatted.
SAMPLE.last
Generates a random last name.
This command is based on ChanceJS library. It generates a random last name or specific to a certain nationality.
Usage
SAMPLE.last(map, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
map | JSON Map (optional) | takes in a JSON map that can contain token and nationality. Nationality supports only us and it . |
token | String (optional) | A string acting as a seed to generate the last name. See examples of how it is used. |
Example
// This will generate a random last name
var last = SAMPLE.last()
I.fill("Last Name", last)
Generates a random last name as input data for the "Last Name" field.
// One way of adding token
let abc = SAMPLE.last({}, "random string")
let efg = SAMPLE.last({}, "random string")
// Another way of using token
let one_last = SAMPLE.last({token: "random string"})
let two_last = SAMPLE.last({token: "random string"})
Every command in this example will generate the same last name due to the token random string
.
let us_last = SAMPLE.last({nationality: "us"})
This will generate an us
nationality last name.
SAMPLE.first
Generates a random first name.
This command is based on ChanceJS library. It generates a random first name or specific to a certain nationality.
Usage
SAMPLE.first(map, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
map | JSON Map (optional) | takes in a JSON map that can contain token and nationality. Nationality supports only us and it . |
token | String (optional) | A string acting as a seed to generate the first name. See examples of how it is used. |
Example
// This will generate a random last name
var first = SAMPLE.first()
I.fill("First Name", first)
Generates a random first name as input data for the "First Name" field.
// One way of adding token
let abc = SAMPLE.first({}, "random string")
let efg = SAMPLE.first({}, "random string")
// Another way of using token
let one_first = SAMPLE.first({token: "random string"})
let two_first = SAMPLE.first({token: "random string"})
Every command in this example will generate the same first name due to the token random string
.
let us_first = SAMPLE.first({nationality: "us"})
This will generate an us nationality first name.
SAMPLE.name
Generates a random full name.
This command is based on ChanceJS library. It generates a random full name or specific to certain nationality and format of the full name.
Usage
SAMPLE.first(map, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
map | JSON Map (optional) | takes in a JSON map that can contain token and params in ChanceJS's name command. Nationality supports only en and it . |
token | String (optional) | A string acting as a seed to generate the first name. See examples of how it is used. |
Example
// This will generate a random last name
var name = SAMPLE.name()
I.fill("Full Name", name)
Generates a random full name as input data for the "Full Name" field.
// One way of adding token
let abc = SAMPLE.name({}, "random string")
let efg = SAMPLE.name({}, "random string")
// Another way of using token
let one_name = SAMPLE.name({token: "random string"})
let two_name = SAMPLE.name({token: "random string"})
Every command in this example will generate the same full name due to the token random string
.
let en_name = SAMPLE.first({nationality: "en"})
This will generate an en
nationality full name.
let full_configured_name = SAMPLE.name({
middle: true, // true/false; middle name
middle_initial: true, // true/false; shortform of the middle name
prefix: true, // true/false; salutations of the person
nationality: 'it', // en/it; nationality of the person
suffix: true, // true/false; information after the last name
gender: 'male', // female/male; gender of the name
token: "some random seed" // string; random seed string to generate the name
})
// e.g. Mrs. Margherita Eleonora Parigi Ph.D.
This will generate a random full name with specific settings. Note that middle
attribute will overwrite middle_initial
attribute.
SAMPLE.email
Generates a random email address.
This will generate a random email address. If there is no
domain
attribute attached to it, the email's domain will default toinboxkitten.com
.
Usage
SAMPLE.email(map, token)
Parameters
Parameter | Type | Remarks |
---|---|---|
map | JSON Map (optional) | takes in a JSON map that can contain a token, domain and length. |
token | String (optional) | A string acting as a seed to generate the first name. See examples of how it is used. |
Example
let email = SAMPLE.email()
I.fill("Email", email)
Generates a random email address with the inboxkitten.com
domain and used as input data for the "Email" field.
// One way of adding token
let abc = SAMPLE.email({}, "random string")
let efg = SAMPLE.email({}, "random string")
// Another way of using token
let one_name = SAMPLE.email({token: "random string"})
let two_name = SAMPLE.email({token: "random string"})
Every command in this example will generate the same email due to the token random string
.
let email = SAMPLE.email({
domain: "example.com", // domain of the email address
length: "6", // length of the username
token: "random string" // random seed string to generate the name
})
// e.g. [email protected]
This will generate a random email address with 6 character username of a domain example.com
.