import unittest,time
from selenium import webdriver
class TestClass(unittest.TestCase):
@classmethod # 装饰器@classmethod,标识为类方法
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.base_url = "http://www.baidu.com"
cls.driver.fullscreen_window()
print("我只执行1次")
def setUp(self):
self.driver.get(self.base_url)
print("每个case我都执行")
@classmethod
def tearDownClass(cls):
cls.driver.quit()
print("bye!")
def tearDown(self):
time.sleep(2)
print("这个case结束了")
def test_case(self):
time.sleep(3)
search_input = self.driver.find_element_by_id("kw")
search_input.send_keys("case1")
search_input.submit()
def test_case2(self):
search_input = self.driver.find_element_by_id("kw")
search_input.send_keys("case2")
search_input.submit()
if __name__ == '__main__':
unittest.main()