Test Data Generation Using Faker


Feeding test data in automated test suite is an additional effort. However, having all the dummy test data in Excel Sheet, XML, and JSON increases maintenance effort a little bit. For example: Consider you have mentioned a phone number in Excel sheet instead of creating random phone number on fly. If you take copy of the test data sheet to execute on different environment, then you are duplicating the static phone number and it will increase the test data maintenance effort. Our suggestion is Never have your random/dummy data in test data file.

In this blog article, you will learn how to use test data generation in Python using Faker package. Nowadays, Selenium automation testing using Python is gaining more popularity. Python packages which are useful for test automation ease script development.

Installation

pip install Faker

Basic Usage

from faker import Faker
fake = Faker()

fake.name()
# 'Lucy Cechtelar'

fake.address()
# '426 Jordy Lodge
#  Cartwrightshire, SC 88120-6700'

fake.text()
# 'Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi
#  beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt
#  amet quidem. Iusto deleniti cum autem ad quia aperiam.
#  A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui
#  quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur
#  voluptatem sit aliquam. Dolores voluptatum est.
#  Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.
#  Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.
#  Et sint et. Ut ducimus quod nemo ab voluptatum.'


Leave a Reply

Your email address will not be published. Required fields are marked *