import time
import unittest
import paramunittest
from chapter3.po_demo import SearchKW
# class Q(unittest.TestCase, SearchKW):
#
# def test_searh_kw(self):
# self.get()
# self.search_kw()
# assert self.element(self.searchInput).get_attribute('value') == 'hello'
# # time.sleep(5)
# self.driver.quit()
@paramunittest.parametrized(
{'keyWords': '111', 'expect': '111'},
{'keyWords': '222', 'expect': '222'}
)
class ParamTest(unittest.TestCase, SearchKW):
"""支持参数化测试样例"""
@classmethod
def setUpClass(cls) -> None:
print('*********************in setUpClass**********************************')
cls.cls_get()
def setParameters(self, keyWords, expect):
self.keyWords = keyWords
self.expect = expect
def test_search_kw(self):
# self.get()
self.search_kw(key_words=self.keyWords)
# assert self.element(self.searchInput).get_attribute('value') == self.expect
# self.assertEqual(self.element(self.searchInput).get_attribute('value'), self.expect)
time.sleep(3)
@classmethod
def tearDownClass(cls) -> None:
print('&&&&&&&&&&&&&&&&&&&&&&in tearDownClass&&&&&&&&&&&&&&&&&&&')
cls.driver.quit()
if __name__ == '__main__':
unittest.main()
1.第二次用参数化执行的时候报错,我猜是tearDownClass把session关闭导致,可是通过打印日志得知,setUpClass tearDownClass每个参数都会执行一次,为了执行第一个参数的tearDownClass会影响第二个参数的执行呢?请问老师该怎么改?
谢谢