Reputation: 49
Hello I am trying to build an automation infrastructure I built an ObjectRepository where commands are implemented in selenium where I use ObjectTest and pass the function to TestOne.
The error is:
TestOne :: test_one - AttributeError: 'ObjectTest' object has no attribute 'driver'
class ObjectRepository:
def __init__(self, driver):
self.driver = driver
def click1(self, element):
return self.driver.find_element_by_xpath(element).click()
class ObjectTest:
search = (By.XPATH, "//a[contains(text(),'Gmail')]")
def click_gmail(self):
a = ObjectRepository(self.driver)
a.click1(*ObjectTest.search)
class TestOne(Base.Base):
def test_one(self):
one = ObjectTest()
one.click_gmail()
Upvotes: 0
Views: 3846
Reputation: 11
Change your code to this:
def __init__(self, driver=None):
if driver is None:
driver={}
else:
self.driver= driver
Upvotes: 1
Reputation: 33361
From the code in the question I can't see that
class ObjectRepository
is passed into class ObjectTest
.from selenium import webdriver
in class ObjectRepository
so as Python will "understand" what self.driver = driver
means
Upvotes: 1