Beispiel #1
0
def excel_data():
    case_data = []
    read_excel = ReadExcel("case_data.xlsx")
    values = read_excel.row_value()
    for i in range(values.__len__()):
        case_data.append(values[i])
    return case_data
Beispiel #2
0
    def test_http(self, test_data):

        # print('/*开始->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        UserLog().info('/*开始->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        # if test_data['data'].find("${name}") != -1:
        #     wb = openpyxl.load_workbook(test_data_path)
        #     sheet=wb['init']
        #     name = str(sheet.cell(2,1).value)
        #     test_data['data']=test_data['data'].replace('${name}',name)
        #     sheet.cell(2,1).value += 1
        #     wb.save(test_data_path)
        # else:
        #     test_data['data']=test_data['data']

        r = HttpRequest().http_request(test_data['url'], eval(test_data["header"]), eval(test_data['data']), test_data['method'], getattr(GetData,'Cookie'))
        # print('/*结束->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        UserLog().info('/*结束->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        if r.cookies:
            setattr(GetData, 'Cookie', r.cookies)
        ReadExcel().writ_back(test_data_path, test_data['sheet_name'], int(test_data['ID'])+1, 'res', str(r.json()))
        # try:
        #     if r.json()['retcode']==test_data['exp']:
        #         ReadExcel().writ_back(test_data_path, 'addteacher', int(test_data['ID'])+1, 'testresult', 'Pass')
        #     else:
        #         ReadExcel().writ_back(test_data_path, 'addteacher', int(test_data['ID'])+1, 'testresult', 'Fail')
        # except Exception as e:
        #     print(e)
        #     raise e
        try:
            self.assertEqual(r.json()['retcode'], test_data['exp'])
            testresult = 'Pass'
        except Exception as e:
            testresult = 'Fail'
            print(e)
            raise e
        finally:
            ReadExcel().writ_back(test_data_path, test_data['sheet_name'], int(test_data['ID']) + 1, 'testresult', testresult)
Beispiel #3
0
 def test_api(self, case_data):
     res = HttpRequest.http_request(case_data['url'],
                                    eval(case_data['data']),
                                    case_data['method'])
     try:
         self.assertEqual(str(case_data['expected']), res.json()['code'])
         self.TestResult = 'PASS'
     except Exception as e:
         self.TestResult = 'Failed'
         print('执行用例出错:{0}'.format(e))
         raise e
     finally:
         ReadExcel(data_file,
                   'login').write_back_data(case_data['case'] + 1,
                                            self.TestResult,
                                            str(res.json()))
Beispiel #4
0
def run(test_data):

    for item in test_data:
        print('正在测试的用例是{0}'.format(item['title']))
        res = HttpRequest().http_request(item['url'],eval(item['data']),item['method'],cookie=getattr(GetCookie,'COOKIE'))
        if res.cookies:
            setattr(GetCookie,'COOKIE',res.cookies)
        print('请求的结果是{0}'.format(res.json()))
        try:
            assert str(item['expected']) == res.json()['code']
            TestResult = 'pass'
        except Exception as e:
            TestResult = 'failed'
            print('接口返回的数据为{}'.format(e))
            raise e
        finally:
            ReadExcel(data_file,'recharge').write_back_data(item['case']+1,TestResult,str(res.json()))
Beispiel #5
0
"""
@version: 1.0
@author: chenj
@file: runner_cater.py
@time: 2019/5/19 15:07
"""

import unittest
from runner import HTMLTestRunnerNew
from test_case.test_cater_set.test_government_cater import test_government_cater
import os, json
from tools.read_excel import ReadExcel
suite = unittest.TestSuite()

excel_dir = "test_data\\add_user.xls"
read_excel = ReadExcel(excel_dir)
test_data = read_excel.row_value()

for item in test_data:
    if item[1] == "test_get_by_idCard":
        pass
        # suite.addTest(test_government_cater("test_get_by_idCard", param=item[3], excepted=item[4]))
    elif item[1] == "test_add_user":
        suite.addTest(test_government_cater("test_add_user", param=json.loads(item[3]), excepted=item[4]))

root_path = os.path.dirname(os.path.abspath(".."))
file = open(os.path.join(root_path, "reports\\test_result.html"), "wb+")
runner = HTMLTestRunnerNew.HTMLTestRunner(stream=file)
runner.run(suite)
Beispiel #6
0
Datei: run.py Projekt: 9cc/c9
from tools.read_excel import ReadExcel
from tools.requests01 import DoRequest


data = ReadExcel('testcases\\接口测试用例模板.xlsx', 'Sheet1')
testcases = data.read_data()
for testcase in testcases:
    url = testcase[1]
    casename = testcase[3]
    method = testcase[5]
    data = eval(testcase[7])
    http_status_code = testcase[8]
    expect_res = testcase[9]


go = DoRequest(url, data=data)
respone = go.requests_post()
print(respone.status_code)
try:
    assert respone.status_code == http_status_code
    print('通过')
except:
    print('失败')
Beispiel #7
0
#     for item in test_data:
#         print('正在测试的用例是{0}'.format(item['title']))
#         res = HttpRequest().http_request(item['url'],eval(item['data']),item['method'],cookie=COOKIE)
#         if res.cookies:
#             COOKIE = res.cookies
#         print('请求的结果是{0}'.format(res.json()))
#         ReadExcel(data_file,'recharge').write_back_data(item['case']+1,str(res.json()))

#方法二:cookie使用反射!
data_file = os.path.join(data_dir,'test_data.xlsx')

def run(test_data):

    for item in test_data:
        print('正在测试的用例是{0}'.format(item['title']))
        res = HttpRequest().http_request(item['url'],eval(item['data']),item['method'],cookie=getattr(GetCookie,'COOKIE'))
        if res.cookies:
            setattr(GetCookie,'COOKIE',res.cookies)
        print('请求的结果是{0}'.format(res.json()))
        try:
            assert str(item['expected']) == res.json()['code']
            TestResult = 'pass'
        except Exception as e:
            TestResult = 'failed'
            print('接口返回的数据为{}'.format(e))
            raise e
        finally:
            ReadExcel(data_file,'recharge').write_back_data(item['case']+1,TestResult,str(res.json()))

test_data = ReadExcel(data_file,'recharge').get_data()
run(test_data)
Beispiel #8
0
# -*- coding:utf-8 -*-
#Author: homoo
#Data: 2020/2/24
#File: test_request.py

import unittest
import openpyxl
from ddt import ddt,data
from tools.read_excel import ReadExcel
from api_test.http_request import HttpRequest
from tools.file_path import *
from tools.get_data import GetData
from tools.user_log import *

test_data = ReadExcel().read_excel()

@ddt
class TestHttp(unittest.TestCase):

    def setUp(self):
        # print('==========开始测试==========')
        UserLog().info('==========开始测试==========')

    @data(*test_data)
    def test_http(self, test_data):

        # print('/*开始->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        UserLog().info('/*开始->ID:{0},标题:{1}*/'.format(test_data['ID'],test_data['title']))
        # if test_data['data'].find("${name}") != -1:
        #     wb = openpyxl.load_workbook(test_data_path)
        #     sheet=wb['init']
Beispiel #9
0
#!/usr/bin/python
#-*- coding:utf-8 -*-
#@Author:zhuxiujie
import unittest, os
from ddt import ddt, data
from tools.http_request import HttpRequest
from tools.project_path import data_dir
from tools.read_excel import ReadExcel

data_file = os.path.join(data_dir, 'test_data.xlsx')
test_data = ReadExcel(data_file, 'login').get_data()


@ddt
class TestLogin(unittest.TestCase):
    def setUp(self):
        pass

    @data(*test_data)
    def test_api(self, case_data):
        res = HttpRequest.http_request(case_data['url'],
                                       eval(case_data['data']),
                                       case_data['method'])
        try:
            self.assertEqual(str(case_data['expected']), res.json()['code'])
            self.TestResult = 'PASS'
        except Exception as e:
            self.TestResult = 'Failed'
            print('执行用例出错:{0}'.format(e))
            raise e
        finally: