zoukankan      html  css  js  c++  java
  • 5.分离测试固件

     我们把测试固件分离到init.py,类名称为InitTest,代码如下:

    import unittest
    from selenium import webdriver
    class InitTest(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
            self.driver.maximize_window()
            self.driver.get("http://www.baidu.com")
            self.driver.implicitly_wait(30)
        def tearDown(self):
            self.driver.quit()
    
    
    if __name__ == '__main__':
        suite = unittest.TestLoader().loadTestsFromModule('test.py')
        unittest.TextTestRunner(verbosity=2).run(suite)

    测试类继承了InitTest,继承后,在测试类中直接编写要执行的测试用例,代码如下:、

    import unittest
    from init import InitTest
    
    class BaiduTest(InitTest):
        def test_baidu_news(self):
            self.driver.find_element_by_link_text('').click()
        def test_baidu_map(self):
            self.driver.find_element_by_link_text('').click()
    if __name__ == '__main__':
        unittest.main()

    首先要导入init模块中的InitTest类,测试类baidutest继承INITTEST类。这样执行测试类后,会先执行setup方法,在执行具体的测试用例,最后执行teardown方法。python的类继承的方式解决了在每个测试类中都需要编写测试固件的问题。

  • 相关阅读:
    hive on hbase
    django多表操作
    django单表操作
    django模板
    django路由初识
    python 相关模块安装 国内镜像地址
    django初识
    Python中属性和描述符的简单使用
    pip安装包(python安装gevent(win))
    jQuery 事件方法
  • 原文地址:https://www.cnblogs.com/Chamberlain/p/11397587.html
Copyright © 2011-2022 走看看