python中py文件中不能传参到基础类调用基础类方法
论文问答
1
照着别人敲的代码运行失败: 做一个简单的关键字驱动测试架构报错,想要在case.py文件传参数进基础类KeyDemo中报错 TypeError: KeyDemo() takes no arguments
基础类
from selenium import webdriver
# 创建指定的浏览器对象
def browser(type_):
try:
return getattr(webdriver, type_)()
except:
return webdriver.Chrome()
class KeyDemo:
# 构造函数
def __init__(self, type_):
self.driver = browser(type_)
def open(self, url):
self.driver.get(url)
case.py
from key_demo.key_worddemo import KeyDemo
wi = KeyDemo('Chrome')
wi.open("http://www.baidu.com")
运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\mihxy\PycharmProjects\key_demo\cases\case.py", line 7, in <module>
wi = KeyDemo('Chrome')
TypeError: KeyDemo() takes no arguments
Process finished with exit code 1
-
# 创建指定的浏览器对象 def browser(type_): try: return getattr(webdriver, type_)() except: return webdriver.Chrome() class KeyDemo: # 构造函数 def __init__(self, type_): self.driver = browser(type_) def open(self, url): self.driver.get(url) return self.driver wi = KeyDemo('Chrome') page=wi.open("http://www.baidu.com") print(page.page_source) page.close()
-
挺奇怪的~ 会不会是
from key_demo.key_worddemo import KeyDemo
这行代码的问题?
发表回复