‘’’ Created on 2019年10月13日
@author: lingh ‘’’ ‘’’ Created on 2019年10月10日
@author: lingh ‘’’ import unittest from selenium import webdriver from time import sleep from parameterized import parameterized class TestBaidu(unittest.TestCase): @classmethod def setUp(self): self.driver=webdriver.Chrome() self.base_url=“https://www.baidu.com” @classmethod def tearDown(self): self.driver.quit() def baidu_search(self,search_key): self.driver.find_element_by_id(“kw”).send_keys(search_key) self.driver.find_element_by_id(“su”).click() sleep(2) def test_search_01(self): dr=self.driver dr.get(self.base_url) search_key=“unittest” self.baidu_search(search_key) title=dr.title self.assertEquals(title,search_key+"_百度搜索") def test_search_02(self): dr=self.driver dr.get(self.base_url) search_key=“selenium” self.baidu_search(search_key) title=dr.title self.assertEquals(title,search_key+"_百度搜索") def test_search_03(self): dr=self.driver dr.get(self.base_url) search_key=“key” self.baidu_search(search_key) title=dr.title self.assertEquals(title,search_key+"_百度搜索") if name==‘main’: unittest.main()
注意: 1.封装点击搜索方法