gallly gallly - 10 months ago 53
Python Question

Random data for test automation in python

I am using unittest and selenium to automate my browser testing.

How would I go about making a test which I can run multiple times, where a user creates a ticket. The ticket has to has a title name, each time I run the test I want the title name to be random.

I would like the format: "Test ticket, 1 | Test ticket, 2..."


The faker module offers some functionality to populate several different types of data:

import faker
f = faker.Faker()

In [11]: f.            f.full_address    f.phonenumber     f.zip_code         f.last_name       f.state           f.lorem           f.street_address
f.first_name            f.username

In [11]:
Out[11]: u'Treyview'


If you are going to test randomly, I recommend randomly generating a seed (and logging it), that way you can recreate any failing tests. What you don't want is tests which fail but it's unclear why (i.e. if testing again, with different random values, passes).