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)
原文地址:https://www.cnblogs.com/Teachertao/p/11706458.html
时间: 2024-10-09 13:33:22