【发布时间】:2021-11-30 02:49:16
【问题描述】:
我正在尝试为一个基本项目运行一些基本测试用例,但是尽管初始化了超类构造函数,但我还是得到了这个错误。下面是我的代码。
home.py
class home(Pages):
user = (By.NAME, "user-name")
utxt = "standard_user"
pwd = (By.ID, "password")
ptxt = "secret_sauce"
logbtn = (By.NAME, "login-button")
def __init__(self,driver):
self.driver=driver
super().__init__(self.driver)
def logg(self):
pg=Pages(self.driver)
pg.type(self.user,self.utxt)
pg.type(self.pwd,self.ptxt)
pg.click1(self.logbtn)`
GenricFun.py
class Pages:
def __init__(self,driver):
self.driver=driver
def click1(self,locator):
WebDriverWait(self.driver).until(e.visibility_of_element_located(locator)).click()
def type(self,locator,txt):
WebDriverWait(self.driver).until((e.visibility_of_element_located(locator))).send_keys(txt)`
Test_log.py
class Test_log(TestBase):
def test_log(self):
self.driver.get("https://www.saucedemo.com/")
L=home(self.driver)
L.logg()
test_log()中的driver来自fixtures方法(confest.py)
【问题讨论】:
-
您能否包含您遇到的异常的完整回溯?由于您的代码不是minimal reproducible example,因此我无法直接对其进行测试,因此我不确定我是否了解错误的确切来源。您的所有类都不需要
timeout参数,因此它可能是对库代码的调用之一,知道哪一个会有所帮助!关于你的类的主题,你在home.logg中做了一些非常奇怪的事情,你正在创建你的基类的另一个实例。您不需要这样做,只需在self上调用这些方法即可!你也根本不需要home.__init__。
标签: python python-3.x selenium-webdriver pytest