1

I have two pytest selenium fixtures:

  • wd - webdriver fixture (widely used for all webend tests)
  • wdwire - webdriverwire fixture (for request/response manipulating of webend)

Both work as they should, but I need to have a variable named like the fixture to get it to work. So it means two separate functions or renaming. I have lots of test and would like to reuse the same code, just changing the fixture and function parameter.

@pytest.mark.usefixtures("wdwire")
def test01_userportal_security(self, wdwire):
  """ using wdwire webdriver """
  url = tools.urls.urls['user-portal']['url']
  wdwire.get(url)
  :
@pytest.mark.usefixtures("wd")
def test01_userportal_security(self, wd):
  """ using standard webdriver """
  url = tools.urls.urls['user-portal']['url']
  wd.get(url)
  :

Any way to add a variable to remap wd/wdwire so they can use the same function with a parameter change?

Tried:

@pytest.mark.usefixtures("wdwire")
def test01_userportal_security(self, wd=wdwire):
  """ using wdwire webdriver """
  url = tools.urls.urls['user-portal']['url']
  wd.get(url)
  :

gives: NameError: name 'wd' is not defined

@pytest.mark.usefixtures("wdwire")
def test01_userportal_security(self, wd="wdwire"):
  """ using wdwire webdriver """
  url = tools.urls.urls['user-portal']['url']
  wd.get(url)
  :

gives: AttributeError: 'str' object has no attribute 'get'

MortenB
  • 2,749
  • 1
  • 31
  • 35
  • What do your fixtures look like? What if you had a 3rd fixture, for use in the test, that returns either the wdwire or wd, based on whatever your conditional is. – Jansen McEntee Aug 25 '22 at 17:48

0 Answers0