1、正常引入unittest套件Demo,次案例继承第三讲案例
from ddt import ddt, file_data from base.login_base import keyDemo import unittest @ddt class CassDemo(unittest.TestCase): @file_data('../data/search.yaml') def test_01(self, input, click): kd = keyDemo('Chrome') kd.open('https://www.baidu.com') kd.input(**input) kd.click(**click) kd.quite() if __name__ == '__main__': unittest.main()
2、(多组不同数据进行执行)yaml文件书写格式文章源自玩技e族-https://www.playezu.com/26235.html
- url: https://www.baidu.com input: name: id value: kw txt: 玩技e族 click: name: id value: su - url: https://www.jd.com input: name: id value: key txt: 玩技e族 click: name: xpath value: //button[@class="button"]
3、同样的业务流程输入不同的数据文章源自玩技e族-https://www.playezu.com/26235.html
from ddt import ddt, file_data from base.login_base import keyDemo import unittest @ddt class CassDemo(unittest.TestCase): @file_data('../data/search.yaml') def test_01(self, url, input, click): kd = keyDemo('Chrome') kd.open(url) kd.input(**input) kd.click(**click) kd.sleep(3) kd.quite() if __name__ == '__main__': unittest.main()
3、继续优化冗余代码,将共有部分继续优化文章源自玩技e族-https://www.playezu.com/26235.html
from ddt import ddt, file_data from base.login_base import keyDemo from time import sleep import unittest @ddt class CassDemo(unittest.TestCase): def setUp(self, ) -> None: self.kd = keyDemo('Chrome') self.kd.maxwindow() def tearDown(self) -> None: self.kd.quite() @file_data('../data/search.yaml') def test_01(self, url, input, click): # self.kd = keyDemo('Chrome') self.kd.open(url) self.kd.input(**input) self.kd.click(**click) sleep(3) # self.kd.quite() if __name__ == '__main__': unittest.main()文章源自玩技e族-https://www.playezu.com/26235.html文章源自玩技e族-https://www.playezu.com/26235.html
评论