python之数据驱动ddt操作(方法四)
from ddt import ddt,data,unpackfrom selenium import webdriverfrom selenium.webdriver.common.by import Byimport time,unittest
"""测试类前加修饰@ddt.ddtcase前加修饰@ddt.data() 相同的测试用例@ddt.unpack 分解data的参数"""
@ddtclass BaiduSearch(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.driver = webdriver.Chrome() cls.driver.maximize_window() cls.driver.implicitly_wait(10) cls.driver.get(‘http://www.baidu.com‘) @classmethod def tearDownClass(cls) -> None: cls.driver.quit() @data([‘selenium‘,‘selenium_百度搜索‘], [‘python‘,‘python_百度搜索‘], [‘appium‘,‘appium_百度搜索‘]) @unpack def test_search_001(self,a,b): self.driver.find_element(By.ID,‘kw‘).send_keys(a) time.sleep(1) self.assertIn(a,b) @data({‘search‘:‘python‘,‘assertText‘:‘python_百度搜索‘}) @unpack def test_search_002(self,search,assertText): self.driver.find_element(By.ID,‘kw‘).send_keys(search) time.sleep(1) self.assertIn(search,assertText)if __name__ == ‘__main__‘: unittest.main(verbosity=2)
相关推荐
夜斗不是神 2020-11-17
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16