def setUp(self): #获取公共接口地址 self.base = Base() self.url = self.base.url() #当前测试接口地址 print('测试开始')
class view(unittest.TestCase): '''XXXX''' def setUp(self): #获取公共接口地址 self.base = Base() self.d = Webdriver() self.url = self.base.url() #当前测试接口地址 print('测试开始') def tearDown(self): print('测试结束') self.d.quit_browser() def test_01(self): ''' XXX ''' print('用例1', self.url) def test_02(self): ''' XXX ''' print('用例2', self.url) self.assertEqual('d', 1) def test_03(self): '''ui自动化''' d = self.d d.open_url(self.url) import time # time.sleep(1) d.type('x=>//*[@id="kw"]', 'python') # time.sleep(1) d.click('x=>//*[@id="su"]') time.sleep(1)
def Cases_report(self): ''' 生产测试报告并发送邮件 ''' #----------查看当前在sit还是uat------ venv = Base().venv() #----------指定测试用例文件----------- d = os.path.dirname(__file__) test_dir = d + '/cases/' #discover是递归匹配文件的,如果有子目录需要有__init__.py, discover = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py', top_level_dir=None) #-----------获取当前时间--------- now = time.strftime('%m-%d_%H_%M') #-----------生成路径------------ # filename = d + '/report/' + now + '_' + venv +'_report.html' filename = d + "/report/test_report.html" png = d + "/report/view.png" #-----------运行并生成报告文件--------- fp = open(filename, 'wb') runner = HTMLTestRunner( stream=fp, title=venv + '接口自动化测试报告', ) runner.run(discover) fp.close() # ----------截图预览------------------ Base().screenshot(filename, png) # ----------发邮件----------------- Base().send_email(filename, png, venv)
class git(unittest.TestCase): '''XXXX''' def setUp(self): #获取公共接口地址 self.base = Base() self.url = self.base.url() #当前测试接口地址 print('测试开始') def tearDown(self): print('测试结束') def test_01(self): ''' XXX ''' print('用例1', self.url) def test_02(self): ''' XXX ''' import time # time.sleep(5) print('用例2', self.url)
class home(unittest.TestCase): '''XXXX''' def setUp(self): #获取公共接口地址 self.base = Base() self.url = self.base.url() #当前测试接口地址 print('测试开始') def tearDown(self): print('测试结束') def test_01(self): ''' XXX ''' print('用例1', self.url) def test_02_get(self): ''' XXX ''' print('用例get') # self.assertEqual('d',1) url = "https://sit.zooming-data.com/helper-rest/miniapp/common/allCity" a = "eyJhbGciOiJIUzUxMiJ9.eyJyYW5kb21LZXkiOiIxZTdtcGciLCJzdWIiOiJjbGllbnRJZDp3eDZjNjQyM2M5ZWZiNDRjNzU6NjQ3IiwiZXhwIjoxNTUzNDk3MjQ5LCJpYXQiOjE1NTI4OTI0NDl9.EGbdTfLsseGgkzOsDF99Ueklgm9tnNodk_hzeMZ24qXSejNOwPT0_qO5BsvllvDiuVrEjDadDaNk-t06YZTJlw" headers = {'Authorization': a, 'appId': "wx6c6423c9efb44c75"} params = "" # get 请求 Request().get(url, headers, params) def test_03_post(self): '''post请求''' print('用例post') url = "https://sit.zooming-data.com/helper-rest/miniapp/linker/collection/insert" a = "eyJhbGciOiJIUzUxMiJ9.eyJyYW5kb21LZXkiOiIxZTdtcGciLCJzdWIiOiJjbGllbnRJZDp3eDZjNjQyM2M5ZWZiNDRjNzU6NjQ3IiwiZXhwIjoxNTUzNDk3MjQ5LCJpYXQiOjE1NTI4OTI0NDl9.EGbdTfLsseGgkzOsDF99Ueklgm9tnNodk_hzeMZ24qXSejNOwPT0_qO5BsvllvDiuVrEjDadDaNk-t06YZTJlw" headers = {'Authorization': a, 'appId': "wx6c6423c9efb44c75"} params = { "clientId": 647, "agentId": 4477, "linkerId": "1ed4925a79ca4ce5b697784579b994e5" } # post 请求 a = Request().post(url, headers, params) print(a.text) def test_04_post_json(self): print('用例post_json') url = "https://sit.zooming-data.com/helper-rest/miniapp/common/data/report" a = "eyJhbGciOiJIUzUxMiJ9.eyJyYW5kb21LZXkiOiIxZTdtcGciLCJzdWIiOiJjbGllbnRJZDp3eDZjNjQyM2M5ZWZiNDRjNzU6NjQ3IiwiZXhwIjoxNTUzNDk3MjQ5LCJpYXQiOjE1NTI4OTI0NDl9.EGbdTfLsseGgkzOsDF99Ueklgm9tnNodk_hzeMZ24qXSejNOwPT0_qO5BsvllvDiuVrEjDadDaNk-t06YZTJlw" headers = { 'Authorization': a, 'appId': "wx6c6423c9efb44c75", 'Content-Type': "application/json" } for i in (647, 667): now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') params = { "clientId": i, "clientName": "Qiukerosmf", "action": "", "agentId": 0, "city": "", "district": "", "houseId": "", "houseName": "", "houseType": "", "houseTypePriceAVG": 0, "houseTypePriceMax": 0, "houseTypePriceMin": 0, "houseTypeSizeMax": 0, "houseTypeSizeMin": 0, "userActionCode": "SYCSXZ", "userActionData": "", "userActionType": "viewHouse", "location": "", "longitude": 113.932945, "latitude": 22.52553, "articleId": 0, "articleTitle": "", "viewTime": now } # post 请求 a = Request().post_json(url, headers, params) print(a.text)