我是新来的蟒蛇,硒。我在执行过程中遇到以下错误。我已经使用Python 3.5.0缺少1个必需的posional参数
如何在这个问题中使用参数? 有没有其他方法?
错误:
C:\>python test.py
Enter your username: dg
Enter your password: bn
Address: rty
Traceback (most recent call last):
File "test.py", line 5, in <module>
class TryTestCase(unittest.TestCase):
File "test.py", line 24, in TryTestCase
test_something(username, password, target)
TypeError: test_something() missing 1 required positional argument: 'target'
代码:
import unittest
from selenium import webdriver
class TryTestCase(unittest.TestCase):
username = input('Enter your username: ')
password = input('Enter your password: ')
target = input('Address: ')
def setUpClass(self):
self.driver = webdriver.Firefox()
self.driver.get('https://abcd.com/')
self.driver.implicitly_wait(5)
def test_something(self, username, password, target):
self.driver.find_element_by_xpath("xyz").send_keys(username)
self.driver.find_element_by_xpath("xyz").send_keys(password)
self.driver.find_element_by_xpath("xyz").send_keys(target)
self.driver.implicitly_wait(1)
def tearDownClass(self):
self.driver.close()
test_something(username, password, target)
if __name__ == '__main__':
unittest.main()
您不必单独运行测试方法。测试运动员将为您做到这一点。只需运行Python文件。 –
显然,你尝试调用你的方法(出于某种原因在你的类定义中,为什么?!)'test_something()'包含4个参数,只有3个参数。尝试删除此方法调用 - 'unittest'应该自己调用它 – Andersson
Thnx @Andersson – kaniska