Python ddt数据驱动
import unittest<br />from time import sleep<br /><br />import ddt<br /># 导入ddt模块<br />from selenium import webdriver<br /><br /><br />@ddt.ddt<br /># 声明使用ddt<br />class MyTestCase(unittest.TestCase):<br /><br /> def setUp(self):<br /> self.driver = webdriver.Firefox()<br /> self.base_url = "https://www.baidu.com/"<br /> self.driver.get(self.base_url)<br /> self.driver.maximize_window()<br /> sleep(2)<br /><br /> @ddt.data(["中国", "中国_百度百科"],<br /> ["美国", "美国_百度百科"],<br /> ["英国", "英国_百度百科"])<br /> # 测试数据<br /><br /> @ddt.unpack<br /> # 对测试数据进行解包并传递<br /> def test_something(self, searchTerm, searchResult):<br /> driver = self.driver<br /> driver.find_element_by_xpath(".//*[@id='kw']").send_keys(searchTerm)<br /> driver.find_element_by_xpath(".//*[@id='su']").click()<br /> sleep(2)<br /> responseText = driver.find_element_by_xpath(".//*[@id='1']/h3/a").text<br /> self.assertEqual(responseText, searchResult)<br /><br /> def tearDown(self):<br /> self.driver.close()<br /> self.driver.quit()<br /><br />if __name__ == '__main__':<br /> unittest.main()
相关推荐
abdstime 2020-07-29
追迷梦境 2020-06-13
AnndyR 2020-05-28
shengge0 2020-05-08
deadgrape 2020-03-06
JakobHu 2020-01-06
typhoonpython 2019-11-05
wklken的笔记 2019-10-19
wordmhg 2019-10-19
liuxiaohua 2018-03-14
Pythonandme 2019-02-22
BitTigerio 2018-03-01