I'm developing some tests using Pytest & Selenium. I've created a function that generates fake account data for the account creation. The following is into a page (catalogpage)
def fake_account(self, fname, lname, userid, pwd, cpwd):
self._type(self._fname, fname)
self._type(self._last_name, lname)
self._type(self._user_id, userid)
self._type(self._password, pwd)
self._type(self._password_confirm, cpwd)
The _type method from above is defined into my base page like this:
def _type(self, locator, input_text):
self._find(locator).send_keys(input_text)
I'm calling the method fake_account into multiple tests, into another page, like this:
class TestFakeAccounts():
@pytest.fixture()
def catalogpage(self, driver):
return catalogpage.CatalogPage(driver)
def test_account1(self, catalogpage):
catalogpage.fake_account(fake.name(), "Auth", fake.user_name(), "PassWord_123", "PassWord_123")
....
def test_account2(self, catalogpage):
catalogpage.fake_account(fake.name(), "Auth", fake.user_name(), "PassWord_123", "PassWord_123")
....
When I run the tests (using pytest in the tests folder), it will collect all my tests, but use the same generated fake data for the entire session (for all my tests). Is there a way of setting this or a pytest fixture so that it will generate new fake data for each test, during same session?
Later update (If anyone needs this): I was able to achieve what I wanted by adding "fake.random.seed()" into each test (not sure if it is the best way, but it works for me)
I was able to achieve what I wanted by adding "fake.random.seed()" into each test (not sure if it is the best way, but it works for me)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With