selenium学习--ddt数据驱动

# UnitTest
@ddt
# 测试用例类继承自unittest.TestCase
# 从TestCase类继承是告诉unittest模块这是一个测试用例的方法:
class TtUnit(unittest.TestCase):
    # 前置操作
    def setUp(self) -> None:
        self.driver = TestKeys('Chrome', 'https://www.baidu.com')

    # 后置操作
    def tearDown(self) -> None:
        time.sleep(10)
        self.driver.quit()

    @data(('id', 'kw', 'id', 'su', 'python'),
          ('id', 'kw', 'id', 'su', 'Java'))
    @unpack
    # 任务(必须以test开头,_n_可以设置任务执行的先后顺序)
    def test_1_python(self, locator_type, locator, locator_type1, locator_btn, text):
        self.driver.input_text(locator_type, locator, text, is_search=Keys.ENTER)
        self.driver.click_element(locator_type1, locator_btn)


if __name__ == '__main__':
    unittest.main()

@ddt 初始化数据驱动
@data 传递数据(元组对象)
@unpack 元组中的元素和参数进行匹配

猜你喜欢

转载自blog.csdn.net/hide_in_darkness/article/details/108414656
今日推荐