Print

Generate Test Data in Robot Framework Example One

To generate fake test data in Robot Framework, we can use Robot Framework Faker library. This library contains 147 keywords used for generating random test data. You can find all the keyword by visiting Robot Framework site. Installation is very easy using the pip command. 

 

pip install robotframework-faker

See the example One below (4 examples are introduced for the Robot Framework Faker library)

Print

Generate Test Data in Robot Framework Example Two

To generate fake test data in Robot Framework, we can use Robot Framework Faker library. This library contains 147 keywords used for generating random test data. You can find all the keyword by visiting Robot Framework site. Installation is very easy using the pip command. 

 

pip install robotframework-faker

See the example Two below (4 examples are introduced for the Robot Framework Faker library)

*** Settings ***
Library           FakerLibrary    locale=en_US

*** Test Cases ***
Generate Fake Data Example2
    [Documentation]    Robot Framework Faker allows users to generate random test data by using Faker's random test data generation keywords. Using Faker, users avoid using static test data for testing and improve the test to simulate real world data.
    [Tags]    Faker
    Comment    Generate    Date Time Between
    ${Date Time Between}    Date Time Between    start_date=1y    end_date=now
    Log    ${Date Time Between}
    Comment    Generate
    Comment    Generate    Date Time This Century
    ${Date Time This Century}    Date Time This Century
    Log    ${Date Time This Century}
    Comment    Generate    Date Time This Decade
    ${Date Time This Decade}    Date Time This Decade
    Log    ${Date Time This Decade}
    Comment    Generate    Date Time This Month
    ${Date Time This Month}    Date Time This Month
    Log    ${Date Time This Month}
    Comment    Generate    Date Time This Year
    ${Date Time This Year}    Date Time This Year
    Log    ${Date Time This Year}
    Comment    Generate    Day Of Month
    ${Day Of Month}    Day Of Month
    Log    ${Day Of Month}
    Comment    Generate    Day Of Week
    ${Day Of Week}    Day Of Week
    Log    ${Day Of Week}
    Comment    Generate    Domain Name
    ${Domain Name}    Domain Name
    Log    ${Domain Name}
    Comment    Generate    Domain Word
    ${Domain Word}    Domain Word
    Log    ${Domain Word}
    Comment    Generate    Email
    ${Email}    Email
    Log    ${Email}
    Comment    Generate    Firefox
    ${Firefox}    Firefox
    Log    ${Firefox}
    Comment    Generate    First Name
    ${First Name}    First Name
    Log    ${First Name}
    Comment    Generate    First Name Female
    ${First Name Female}    First Name Female
    Log    ${First Name Female}
    Comment    Generate    First Name Male
    ${First Name Male}    First Name Male
    Log    ${First Name Male}
    Comment    Generate    Free Email
    ${Free Email}    Free Email
    Log    ${Free Email}
    Comment    Generate    Free Email Domain
    ${Free Email Domain}    Free Email Domain
    Log    ${Free Email Domain}
    Comment    Generate    Geo Coordinate
    ${Geo Coordinate}    Geo Coordinate
    Log    ${Geo Coordinate}
    Comment    Generate    Hex Color
    ${Hex Color}    Hex Color
    Log    ${Hex Color}
    Comment    Generate    Init
    ${Init}    Init
    Log    ${Init}
    Comment    Generate    Internet Explorer
    ${Internet Explorer}    Internet Explorer
    Log    ${Internet Explorer}
    Comment    Generate    Ipv 4
    ${Ipv 4}    Ipv 4
    Log    ${Ipv 4}
    Comment    Generate    Ipv 6
    ${Ipv 6}    Ipv 6
    Log    ${Ipv 6}
    Comment    Generate    Iso 8601
    ${Iso 8601}    Iso 8601
    Log    ${Iso 8601}
    Comment    Generate    Job
    ${Job}    Job
    Log    ${Job}
    Comment    Generate    Language Code
    ${Language Code}    Language Code
    Log    ${Language Code}
    Comment    Generate    Last Name
    ${Last Name}    Last Name
    Log    ${Last Name}
    Comment    Generate    Latitude
    ${Latitude}    Latitude
    Log    ${Latitude}
    Comment    Replace all question mark occurences with a random letter
    ${Lexify}    Lexify    text=????
    Log    ${Lexify}
    Comment    Generate    Linux Platform Token
    ${Linux Platform Token}    Linux Platform Token
    Log    ${Linux Platform Token}
    Comment    Generate    Linux Processor
    ${Linux Processor}    Linux Processor
    Log    ${Linux Processor}
    Comment    Generate    Locale
    ${Locale}    Locale
    Log    ${Locale}
    Comment    Generate    Longitude
    ${Longitude}    Longitude
    Log    ${Longitude}
    Comment    Generate    Mac Platform Token
    ${Mac Platform Token}    Mac Platform Token
    Log    ${Mac Platform Token}

Click here to see the test result log file

Print

Generate Test Data in Robot Framework Example Three

To generate fake test data in Robot Framework, we can use Robot Framework Faker library. This library contains 147 keywords used for generating random test data. You can find all the keyword by visiting Robot Framework site. Installation is very easy using the pip command. 

 

pip install robotframework-faker

See the example Three below (4 examples are introduced for the Robot Framework Faker library)

*** Settings ***
Library           FakerLibrary    locale=en_US

*** Test Cases ***
Generate Fake Data Example3
    [Documentation]    Robot Framework Faker allows users to generate random test data by using Faker's random test data generation keywords. Using Faker, users avoid using static test data for testing and improve the test to simulate real world data.
    [Tags]    Faker
    Comment    Generate    Mac Processor
    ${Mac Processor}    Mac Processor
    Log    ${Mac Processor}
    Comment    Generate    Md 5
    ${Md 5}    Md 5
    Log    ${Md 5}
    Comment    Generate    Mime Type
    ${Mime Type}    Mime Type
    Log    ${Mime Type}
    Comment    Generate    Month
    ${Month}    Month
    Log    ${Month}
    Comment    Generate    Month Name
    ${Month Name}    Month Name
    Log    ${Month Name}
    Comment    Generate    Name
    ${Name}    Name
    Log    ${Name}
    Comment    Generate    Name Female
    ${Name Female}    Name Female
    Log    ${Name Female}
    Comment    Generate    Name Male
    ${Name Male}    Name Male
    Log    ${Name Male}
    Comment    Generate    Null Boolean
    ${Null Boolean}    Null Boolean
    Log    ${Null Boolean}
    Comment    Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number Replaces all exclamation mark ('!') occurrences with a random number from 0 to 9 or empty Replaces all at symbol ('@') occurrences with a random number from 1 to 9 or empty
    ${Numerify}    Numerify    text='1234##4%%1!!45@55'
    Log    ${Numerify}
    Comment    Generate    Opera
    ${Opera}    Opera
    Log    ${Opera}
    Comment    Generate a single paragraph    param nb_sentences around how many sentences the paragraph should contain :param variable_nb_sentences set to false if you want exactly $nbSentences returned, otherwise $nbSentences may vary by +/-40% with a minimum of 1 :return string
    ${Paragraph}    Paragraph    nb_sentences=3
    Log    ${Paragraph}
    Comment    Generate an array of paragraphs    param nb how many paragraphs to return :return array
    ${Paragraphs}    Paragraphs    nb=2
    Log    ${Paragraphs}
    Comment    Generate password according to the params
    ${Password}    Password    length=10    special_chars=True    digits=True    upper_case=True    lower_case=True
    Log    ${Password}
    Comment    Generate    Phone Number
    ${Phone Number}    Phone Number
    Log    ${Phone Number}
    Comment    Generate    Postcode
    ${Postcode}    Postcode
    Log    ${Postcode}
    Comment    Generate    Prefix
    ${Prefix}    Prefix
    Log    ${Prefix}
    Comment    Generate    Prefix Female
    ${Prefix Female}    Prefix Female
    Log    ${Prefix Female}
    Comment    Generate    Prefix Male
    ${Prefix Male}    Prefix Male
    Log    ${Prefix Male}
    Comment    Generate    Profile
    ${Profile}    Profile
    Log    ${Profile}
    Comment    Generate    Provider
    Comment    Generate    Pybool
    ${Pybool}    Pybool
    Log    ${Pybool}
    Comment    Generate    Pydecimal
    ${Pydecimal}    Pydecimal
    Log    ${Pydecimal}
    Comment    Generate    Pydict
    ${Pydict}    Pydict
    Log    ${Pydict}
    Comment    Generate    Pyfloat
    ${Pyfloat}    Pyfloat
    Log    ${Pyfloat}
    Comment    Generate    Pyint
    ${Pyint}    Pyint
    Log    ${Pyint}
    Comment    Generate    Pyiterable
    ${Pyiterable}    Pyiterable
    Log    ${Pyiterable}
    Comment    Generate    Pylist
    ${Pylist}    Pylist
    Log    ${Pylist}
    Comment    Generate    Pyset
    ${Pyset}    Pyset
    Log    ${Pyset}
    Comment    Generate    Pystr
    ${Pystr}    Pystr
    Log    ${Pystr}
    Comment    Generate    Pystruct
    ${Pystruct}    Pystruct
    Log    ${Pystruct}
    Comment    Generate    Pytuple
    ${Pytuple}    Pytuple    nb_elements=10
    Log    ${Pytuple}

Click here to see the test result log file

Print

Generate Test Data in Robot Framework Example Four

To generate fake test data in Robot Framework, we can use Robot Framework Faker library. This library contains 147 keywords used for generating random test data. You can find all the keyword by visiting Robot Framework site. Installation is very easy using the pip command. 

 

pip install robotframework-faker

See the example four below (4 examples are introduced for the Robot Framework Faker library)

*** Settings ***
Library           FakerLibrary    locale=en_US

*** Test Cases ***
Generate Fake Data Example4
    [Documentation]    Robot Framework Faker allows users to generate random test data by using Faker's random test data generation keywords. Using Faker, users avoid using static test data for testing and improve the test to simulate real world data.
    [Tags]    Faker
    Comment    Returns a random number between 1 and 9
    ${Random Digit}    Random Digit
    Log    ${Random Digit}
    Comment    Generate    Random Digit Not Null
    ${Random Digit Not Null}    Random Digit Not Null
    Log    ${Random Digit Not Null}
    Comment    Returns a random number between 1 and 9
    ${Random Digit Not Null Or Empty}    Random Digit Not Null Or Empty
    Log    ${Random Digit Not Null Or Empty}
    Comment    Generate    Random Digit Or Empty
    ${Random Digit Or Empty}    Random Digit Or Empty
    Log    ${Random Digit Or Empty}
    Comment    Returns a random element from a passed array
    ${Random Element}    Random Element    array=('a', 'b', 'b')
    Log    ${Random Element}
    Comment    Generate a random integer
    ${Random Int}    Random Int    min=0    max=9999
    Log    ${Random Int}
    Comment    Returns a random letter from a to z
    ${Random Letter}    Random Letter
    Log    ${Random Letter}
    Comment    Returns a random number with 0 to $digits digits
    ${Random Number}    Random Number    digits=5
    Log    ${Random Number}
    Comment    Returns a random value near to number
    ${Randomize Nb Elements}    Randomize Nb Elements    number=6
    Log    ${Randomize Nb Elements}
    Comment    Generate    Rgb Color
    ${Rgb Color}    Rgb Color
    Log    ${Rgb Color}
    Comment    Generate    Rgb Color List
    ${Rgb Color List}    Rgb Color List
    Log    ${Rgb Color List}
    Comment    Generate    Rgb Css Color
    ${Rgb Css Color}    Rgb Css Color
    Log    ${Rgb Css Color}
    Comment    Generate    Safari
    ${Safari}    Safari
    Log    ${Safari}
    Comment    Generate    Safe Color Name
    ${Safe Color Name}    Safe Color Name
    Log    ${Safe Color Name}
    Comment    Generate    Safe Email
    ${Safe Email}    Safe Email
    Log    ${Safe Email}
    Comment    Generate    Safe Hex Color
    ${Safe Hex Color}    Safe Hex Color
    Log    ${Safe Hex Color}
    Comment    Generate    Secondary Address
    ${Secondary Address}    Secondary Address
    Log    ${Secondary Address}
    Comment    Generate a random sentence    param nb_words around how many words the sentence should contain
    ${Sentence}    Sentence    nb_words=5
    Log    ${Sentence}
    Comment    Generate an array of sentences
    ${Sentences}    Sentences    nb=3
    Log    ${Sentences}
    Comment    Calculates the sha 1 hash of a given string
    ${Sha 1}    Sha 1    text='Selenium Master'
    Log    ${Sha 1}
    Comment    Calculates the sha 256 hash of a given string
    ${Sha 256}    Sha 256    text='Selenium Master'
    Log    ${Sha 256}
    Comment    Generate    Simple Profile
    ${Simple Profile}    Simple Profile
    Log    ${Simple Profile}
    Comment    Generate    Django algorithm
    ${Slug}    Slug
    Log    ${Slug}
    Comment    Generate    State
    ${State}    State
    Log    ${State}
    Comment    Generate    State Abbr
    ${State Abbr}    State Abbr
    Log    ${State Abbr}
    Comment    Generate    Street Address
    ${Street Address}    Street Address
    Log    ${Street Address}
    Comment    Generate    Street Name
    ${Street Name}    Street Name
    Log    ${Street Name}
    Comment    Generate    Street Suffix
    ${Street Suffix}    Street Suffix
    Log    ${Street Suffix}
    Comment    Generate    Suffix
    ${Suffix}    Suffix
    Log    ${Suffix}
    Comment    Generate    Suffix Female
    ${Suffix Female}    Suffix Female
    Log    ${Suffix Female}
    Comment    Generate    Suffix Male
    ${Suffix Male}    Suffix Male
    Log    ${Suffix Male}
    Comment    Generate a text string. Param max_nb_chars indicates maximum number of characters the text should contain
    ${Text}    Text    max_nb_chars=100
    Log    ${Text}
    Comment    Generate    Time
    ${Time}    Time    pattern=%H:%M:%S
    Log    ${Time}
    Comment    Generate    Timezone
    ${Timezone}    Timezone
    Log    ${Timezone}
    Comment    Generate    Tld
    ${Tld}    Tld
    Log    ${Tld}
    Comment    Generate    Unix Time
    ${Unix Time}    Unix Time
    Log    ${Unix Time}
    Comment    Generate    Uri
    ${Uri}    Uri
    Log    ${Uri}
    Comment    Generate    Uri Extension
    ${Uri Extension}    Uri Extension
    Log    ${Uri Extension}
    Comment    Generate    Uri Page
    ${Uri Page}    Uri Page
    Log    ${Uri Page}
    Comment    Generate    Uri Path
    ${Uri Path}    Uri Path
    Log    ${Uri Path}
    Comment    Generate    Url
    ${Url}    Url
    Log    ${Url}
    Comment    Generate    User Agent
    ${User Agent}    User Agent
    Log    ${User Agent}
    Comment    Generate    User Name
    ${User Name}    User Name
    Log    ${User Name}
    Comment    Generate    Windows Platform Token
    ${Windows Platform Token}    Windows Platform Token
    Log    ${Windows Platform Token}
    Comment    Generate    Word
    ${Word}    Word
    Log    ${Word}
    Comment    Generate an array of random words;    param nb indicates how many words to return
    ${Words}    Words    nb=5
    Log    ${Words}
    Comment    Generate    Year
    ${Year}    Year
    Log    ${Year}

Click here to see the test result log file

Print

Dictionary Should Contain Sub Dictionary Robot Framework

Dictionary Should Contain Sub Dictionary keyword is used to check if all items in dict1 are from dict2. The keyword will fail if there are differences between the keys and values. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Sub Dictionary Test
    Comment    Fails unless all items in dict2 are found from dict1
    ${dict2}=    Create Dictionary
    Set To Dictionary    ${dict2}    Foo1    Value1
    Set To Dictionary    ${dict2}    Foo2    Value2
    Log Dictionary    ${dict2}
    ${dict1}=    Create Dictionary
    Set To Dictionary    ${dict1}    Foo1    Value1
    Set To Dictionary    ${dict1}    Foo2    Value2
    Set To Dictionary    ${dict1}    Foo3    Value3
    Set To Dictionary    ${dict1}    Foo4    Value4
    Log Dictionary    ${dict1}
    Dictionary Should Contain Sub Dictionary    ${dict1}    ${dict2}

Run the script below. The test passed. 

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Sub Dictionary Test
20150426 08:33:25.678 :  INFO : ${dict2} = {}
20150426 08:33:25.678 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
20150426 08:33:25.678 :  INFO : ${dict1} = {}
20150426 08:33:25.678 :  INFO : 
Dictionary size is 4 and it contains following items:
Foo1: Value1
Foo2: Value2
Foo3: Value3
Foo4: Value4
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Sub Dictionary Test
Print

Dictionary Should Contain Value Robot Framework

Dictionary Should Contain Value keyword is used to check if a dictionary contains a value. If value is not found, the keyword Fail. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Value Test
    Comment    Fails if value is not found from dictionary
    ${MyDict}=    Create Dictionary    Foo1    Value1
    Set To Dictionary    ${MyDict}    Foo2    Value2
    Log Dictionary    ${MyDict}
    Dictionary Should Contain Value    ${MyDict}    Value2
    Comment    You can use keyword Dictionary Should Not Contain Value in similar ways

Run the script above. The test passed. 

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Value Test
20150426 08:26:50.078 :  INFO : ${MyDict} = {u'Foo1': u'Value1'}
20150426 08:26:50.078 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Value Test
Print

Dictionary Should Contain Key Robot Framework

Dictionary Should Contain Key keyword is used to verify if a given key is found in the dictionary. If not, the keyword will Fail. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Key Test
    Comment    Fails if key is not found from dictionary
    ${MyDict}=    Create Dictionary
    Set To Dictionary    ${MyDict}    A1    Value1
    Set To Dictionary    ${MyDict}    A2    Value2
    Log Dictionary    ${MyDict}
    Dictionary Should Contain Key    ${MyDict}    A1
    Comment    You can use Dictionary Should Not Contain Key in similar ways

Run the script above. The test passed. 

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Key Test
20150426 08:23:18.669 :  INFO : ${MyDict} = {}
20150426 08:23:18.669 :  INFO : 
Dictionary size is 2 and it contains following items:
A1: Value1
A2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Key Test
Print

Dictionary Should Contain Item Robot Framework

Dictionary Should Contain Item keyword is used to check if the dictionary contain an item of key/value pair. See the implementation below.

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Item Test
    Comment    An item of key/value must be found in a dictionary
    ${MyDict}=    Create Dictionary
    Set To Dictionary    ${MyDict}    Foo1    Value1
    Set To Dictionary    ${MyDict}    Foo2    Value2
    Log Dictionary    ${MyDict}
    Dictionary Should Contain Item    ${MyDict}    Foo1    Value1

Run the script above. The test passed because ${MyDict} contains the item Foo1/Value1

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Item Test
20150426 08:17:22.786 :  INFO : ${MyDict} = {}
20150426 08:17:22.786 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Item Test
Print

Dictionaries Should Be Equal Robot Framework

Dictionaries Should Be Equal keyword is used to compare dictionaries. If they are not equal, the keyword will Fail. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionaries Should Be Equal Test
    Comment    Fails if the given dictionaries are not equal.
    ${Dict1}=    Create Dictionary
    Set To Dictionary    ${Dict1}    Foo1    Value1
    Set To Dictionary    ${Dict1}    Foo2    Value2
    Log Dictionary    ${Dict1}
    ${Dict2}=    Create Dictionary
    Set To Dictionary    ${Dict2}    Foo1    Value1
    Set To Dictionary    ${Dict2}    Foo2    Value2
    Log Dictionary    ${Dict2}
    Dictionaries Should Be Equal    ${Dict1}    ${Dict2}

Run the test and observe the result. The test passed.

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionaries Should Be Equal Test
20150426 08:15:02.351 :  INFO : ${Dict1} = {}
20150426 08:15:02.351 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
20150426 08:15:02.351 :  INFO : ${Dict2} = {}
20150426 08:15:02.351 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionaries Should Be Equal Test
Print

Get Dictionary Items Robot Framework

Get Dictionary Items keyword returns the items of a given dictionary. See the example below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Get Dictionary Items Test
    Comment    Returns items of the given dictionary
    ${dict}=    Create Dictionary
    Set To Dictionary    ${dict}    Foo1    Value1
    Set To Dictionary    ${dict}    Foo2    Value2
    ${items}=    Get Dictionary Items    ${dict}
    Log List    ${items}
    List Should Contain Value    ${items}    Value1

Run the script and see the result

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Get Dictionary Items Test
20150424 00:16:16.962 :  INFO : ${dict} = {}
20150424 00:16:16.962 :  INFO : ${items} = [u'Foo1', u'Value1', u'Foo2', u'Value2']
20150424 00:16:16.962 :  INFO : 
List length is 4 and it contains following items:
0: Foo1
1: Value1
2: Foo2
3: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Get Dictionary Items Test