def test_homeguesslist(self): self.homeguesslist = home_guess_list() get_log().info('获取猜你喜欢--->status_code:{}, 请求时长:{}'.format(self.homeguesslist[1], self.homeguesslist[0])) try: self.assertEquals(self.homeguesslist[1], 200, '请求失败') self.assertLess(self.homeguesslist[0], read_config(), '请求超时,实际请求时长%s毫秒' % self.homeguesslist[0]) except AssertionError: raise AssertionError
def test_task(self): self.get_task = get_task() get_log().info('获取底部菜单接口--->status_code:{}, 请求时长:{}'.format(self.get_task[1], self.get_task[0])) try: self.assertEquals(self.get_task[1], 200, '请求失败') self.assertLess(self.get_task[0], read_config(), '请求超时,实际请求时长%s毫秒' % self.get_task[0]) except AssertionError: raise AssertionError
def test_excel_login(self): rows = ReadExcel().get_rows() # 获取表单的所有行 # print(rows) for i in range(rows): data = ReadExcel().get_row_value(i + 2) # 获取每一行的数据,返回的是list # print(data) if data[0] != None: self.login = my_login(data[0], data[1]) # 获取具体单元格的数据入参 # get_log().info("账号:{} 密码:{}".format(data[0], data[1])) get_log().info('登录接口请求结果%s' % self.login) self.assertEqual(self.login, data[2]) else: break
def send_email(file_new): msg = MIMEMultipart() # 发送邮箱服务器 smtpsever = 'smtp.qq.com' # 发送邮箱用户 登录使用 user = '******' password = '******' # 发送用户 sender = '*****@*****.**' # 接收用户 receiver = '*****@*****.**' # 发送主题 subject = 'API_Test_Report' # 编写HTML 类型的邮件正文 msg['Subject'] = Header(subject, 'utf-8') txt = MIMEText('这是API自动化测试报告,请使用浏览器打开附件并点击详情查看测试结果\n如有问题请及时联系', 'plain', 'utf-8') msg.attach(txt) msg['From'] = _format_addr(u'李闹<%s>' % user) msg['to'] = _format_addr(receiver) # 发送附件 sendfile = open(file_new, 'rb').read() # 获取报告 text_att = MIMEText(sendfile, 'html', 'uft-8') # 添加附件 text_att["Content-Type"] = 'application/octet-stream' # 附件类型 text_att.add_header('Content-Disposition', 'attachment', filename='test_result.html') msg.attach(text_att) # 直接发送邮件(smtplib模块 基本使用格式) smtp = smtplib.SMTP() smtp.connect(smtpsever) smtp.login(user, password) smtp.sendmail(sender, receiver.split(','), msg.as_string()) get_log().info('邮件发送成功') smtp.quit()
def test_bcy(self): self.get = get(url, header) self.assertEqual(self.get, 200, self.get) get_log().info('bcy请求的结果%s' % self.get)
def test_ddt_excel_login(self, data): user, password, except_code = data # ddt中要把数据和参数对应起来 这里的data [test,123456,200] self.login = my_login(user, password) # 获取具体单元格的数据入参 get_log().info("账号:{} 密码:{}".format(user, password)) get_log().info('登录接口请求结果%s' % self.login) self.assertEqual(self.login, except_code, "与预期结果不一致,用例失败")
def test_baidu(self): self.get = get(url, header, timeout=0.5) self.assertEqual(self.get, 200, self.get) get_log().info('百度_请求成功')
def test_jianshu(self): self.get = get(url, header) self.assertEqual(self.get, 200, self.get) get_log().info('简书请求的结果%s' % self.get)
def test_login(self, A, B): self.login = login(A, B) get_log().info('登录接口请求结果%s' % self.login) self.assertEquals(self.login, 200, '与预期不符合用例失败')