import unittest,time
from selenium import webdriver
class testLogin(unittest.TestCase):
def setUpClass(cls) -> None:
cls.driver = webdriver.Chrome()
cls.driver.maximize_window()
cls.driver.implicitly_wait(10)
cls.driver.get('https://www.baidu.com/')
def tearDownClass(cls) -> None:
cls.driver.quit()
def setUp(self) -> None:
self.driver.refresh()
def tearDown(self) -> None:
pass
def test_usernameNull(self):
#用户名为空
login_operation(self.driver,'','123456')
time.sleep(0.5)
解决方法:文章来源:https://www.toymoban.com/news/detail-533060.html
分别在 setUpClass(cls) 和 tearDownClass(cls) 前面加 @classmethod文章来源地址https://www.toymoban.com/news/detail-533060.html
import unittest,time
from selenium import webdriver
class testLogin(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.driver = webdriver.Chrome()
cls.driver.maximize_window()
cls.driver.implicitly_wait(10)
cls.driver.get('https://www.baidu.com/')
@classmethod
def tearDownClass(cls) -> None:
cls.driver.quit()
def setUp(self) -> None:
self.driver.refresh()
def tearDown(self) -> None:
pass
def test_usernameNull(self):
#用户名为空
login_operation(self.driver,'','123456')
time.sleep(0.5)
assertUserNameNull(self.driver)
到了这里,关于TypeError: setUpClass() missing 1 required positional argument: ‘cls‘怎么解决?的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!