zoukankan      html  css  js  c++  java
  • unittest框架学习笔记一之testcase

    # coding=utf-8
    案例一: 2 ''' 3 Created on 2017-7-22 4 @author: Jennifer 5 Project:登录百度测试用例 6 ''' 7 from selenium import webdriver 8 import unittest, time 9 10 class BaiduTest(unittest.TestCase): 11 def setUp(self): 12 self.driver = webdriver.Chrome() 13 self.driver.implicitly_wait(30) #隐性等待时间为30秒 14 self.base_url = "https://www.baidu.com" 15 16 def test_baidu(self): 17 driver = self.driver 18 driver.get(self.base_url + "/") 19 driver.find_element_by_id("kw").clear() 20 driver.find_element_by_id("kw").send_keys("unittest") 21 driver.find_element_by_id("su").click() 22 time.sleep(3) 23 title=driver.title 24 self.assertEqual(title, u"unittest_百度搜索") 25 26 def tearDown(self): 27 self.driver.quit() 28 29 if __name__ == "__main__": 30 unittest.main()

    案例二:
    # coding=utf-8
    '''
    Created on 2017-7-22
    @author: Jennifer
    Project:使用有道翻译测试用例
    '''
    from selenium import webdriver
    import unittest, time
    
    class YoudaoTest(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(30) #隐性等待时间为30秒
            self.base_url = "http://www.youdao.com"
        
        def test_youdao(self):
            driver = self.driver
            driver.get(self.base_url + "/")
            driver.find_element_by_id("translateContent").clear()
            driver.find_element_by_id("translateContent").send_keys(u"你好")
            driver.find_element_by_id("translateContent").submit()
            time.sleep(3)
            page_source=driver.page_source
            self.assertIn( "hello",page_source) 
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == "__main__":
        unittest.main()
  • 相关阅读:
    聚类算法
    shell编程之运算符
    linux shell编程子bash变量
    java SSM框架单元测试最佳实战代码
    在maven项目中使用Junit进行单元测试(一)
    JMeter之Http协议接口性能测试
    TestNG学习笔记新的
    单元测试最佳实战项目代码下载
    单元测试中使用mock最好不要使用easymock而应该使用powermock
    springboot 读写excel
  • 原文地址:https://www.cnblogs.com/star12111/p/8669174.html
Copyright © 2011-2022 走看看