zoukankan      html  css  js  c++  java
  • unittest编写Web测试用例

    案例:百度搜索关键词:“unittest”

    test_baidu.py:

    from selenium import webdriver
    from time import sleep
    import unittest
    
    
    class TestBaidu(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.maximize_window()
            self.driver.implicitly_wait(10)
            self.driver.get("http://www.baidu.com")
    
        def test_baidu(self):
            driver = self.driver
            driver.find_element_by_id("kw").clear()
            driver.find_element_by_id("kw").send_keys("unittest")
            driver.find_element_by_id("su").click()
            sleep(2)
            title = driver.title
            self.assertEqual(title,"unittest_百度搜索")
    
        def tearDown(self):
            self.driver.quit()
    
    
    if __name__ == '__main__':
        unittest.main()

    执行测试用例

    runtest.py:

    import unittest
    
    test_dir = './test_case'
    discover = unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
    
    if __name__ == '__main__':
        runner = unittest.TextTestRunner()
        runner.run(discover)

    在本案例中,将unittest和Python的webdriver结合在一起,从而实现最简单的Web测试用例的执行

  • 相关阅读:
    Promise/Deferred
    理解RESTful架构
    XSS跨站脚本攻击
    crsf 跨站请求伪造
    街头生意
    什么是开光
    影响力
    linux上安装rar解压软件
    sip协议音视频性能测试
    解决关键SSL安全问题和漏洞
  • 原文地址:https://www.cnblogs.com/NancyRM/p/8385702.html
Copyright © 2011-2022 走看看