Exemple #1
0
class DependDentData:
    def __init__(self, case_id):
        self.opera_excel = OperationExcel()
        self.case_id = case_id
        self.data = GetData()

    def get_case_lines_data(self):
        rows_data = self.opera_excel.get_rows_data(self.case_id)
        return rows_data

    def run_dependdent(self):
        run_method = RunMethod()
        row = int(self.opera_excel.get_rows_num(self.case_id))
        request_data = self.data.get_data_for_json(row)
        cookie = self.data.is_cookie(row)
        method = self.data.get_request_method(row)
        url = self.data.get_url(row)
        res = run_method.run_main(method, url, request_data, cookie)
        return res

    #根据依赖的key去获取执行依赖测试case的响应,然后返回
    def get_data_for_key(self, row):
        depend_data = self.data.get_depend_key(row)
        response_data = self.run_dependdent()
        json_exe = parse(depend_data)
        madle = json_exe.find(response_data)
        return [math.value for math in madle][0]
Exemple #2
0
class Run_Test():
    def __init__(self):
        self.data = OperationExcel()

    @retry(stop_max_attempt_number=5)#请求失败重试5次
    def request_url(self,url):
        code = None
        re = requests.get(url, timeout=5)
        return re.status_code

    #监测url返回值,返回报错信息
    def get_url(self):
        error_url = []
        socket.socket = base_socket
        lines = self.data.get_lines()
        for i in range(1,lines):
            url = self.data.get_url_value(i)
            url_explain = self.data.get_url_explain(i)
            try:
                code = self.request_url(url)
            except (requests.exceptions.ConnectionError,requests.exceptions.ReadTimeout) as e:
                print('请求超时:',e)
                code = str(e)

            if code != 200:
                # 获取当前时间
                nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                error_news = str(i)+'--访问失败--:'+str(code)+' '+url+' '+nowTime +' 所属项目:'+url_explain
                error_url.append(error_news)
            else:
                nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                print(str(i)+'访问正常:%s '% code,url,nowTime,url_explain)
            time.sleep(0.1)
        print(error_url)
        return error_url
Exemple #3
0
 def __init__(self,file):
     self.file = file
     self.OperaExcel = OperationExcel(self.file)
Exemple #4
0
 def __init__(self):
     self.opera_excel = OperationExcel()
Exemple #5
0
class GetData:

    def __init__(self):
        self.opera_excel = OperationExcel()

    def get_case_lines(self):
        return int(self.opera_excel.get_lines())

    def get_is_run(self, row):
        flag = None
        col = int(data_config.get_run())
        run_model = self.opera_excel.get_cell_value(row, col)
        if run_model == 'yes':
            flag = True
        else:
            flag = False
        return flag

    #是否携带cookie
    def is_cookie(self, row):
        col = int(data_config.get_cookie())
        cookie = self.opera_excel.get_cell_value(row, col)
        if cookie != '':
            # return data_config.get_header_value()
            return cookie
        else:
            return None

    #请求方式
    def get_request_method(self,row):
        col = int(data_config.get_run_way())
        request_method = self.opera_excel.get_cell_value(row, col)
        return request_method

    #获取url
    def get_url(self, row):
        col = int(data_config.get_url())
        request_url = self.opera_excel.get_cell_value(row, col)
        return request_url

    #获取请求数据
    def get_request_data(self, row):
        col = int(data_config.get_data())
        request_data = self.opera_excel.get_cell_value(row, col)
        if request_data == '':
            return None
        return request_data

    #通过关键字获取json文件中的请求数据
    def get_data_for_json(self, row):
        opera_json = OperationJson()
        request_data = opera_json.get_data(self.get_request_data(row))
        return request_data

    #获取预期结果
    def get_expect_data(self, row):
        col = int(data_config.get_expect())
        expect = self.opera_excel.get_cell_value(row, col)
        if expect == '':
            return None
        return expect

    #通过mysql获取预期结果
    def get_expcet_data_from_mysql(self, row):
        op_mysql = Operation_MYSQL()
        sql = self.get_expect_data(row)
        res = op_mysql.search_one(sql).decode('unicode-escape')
        return res

    #写入case执行结果
    def write_result(self, row, value):
        col = int(data_config.get_result())
        self.opera_excel.write_value(row, col, value)

    # 获取依赖数据的key
    def get_depend_key(self, row):
        col = int(data_config.get_data_depend())
        depend_key = self.opera_excel.get_cell_value(row, col)
        if depend_key == "":
            return None
        else:
            return depend_key

    #判断是否有case依赖
    def is_depend(self, row):
        col = int(data_config.get_case_depend())
        depend_case_id = self.opera_excel.get_cell_value(row, col)
        if depend_case_id == "":
            return None
        else:
            return depend_case_id

    #获取数据依赖字段
    def get_depend_field(self, row):
        col = int(data_config.get_field_depend())
        data = self.opera_excel.get_cell_value(row, col)
        if data == "":
            return None
        else:
            return data
Exemple #6
0
 def __init__(self, case_id):
     self.opera_excel = OperationExcel()
     self.case_id = case_id
     self.data = GetData()
Exemple #7
0
 def __init__(self):
     self.data = OperationExcel()
Exemple #8
0
class GetData:
    def __init__(self, fileName=None, sheetName=None):
        self.opera_excel = OperationExcel(fileName, sheetName)

    #去获取excel行数,就是我们的case个数
    def get_case_lines(self):
        return self.opera_excel.get_lines()

    # 去获取用例ID号
    def get_case_id(self, row):
        col = int(data_config.get_id(self))
        case_id = self.opera_excel.get_cell_value(row, col)
        return case_id


    #获取是否执行
    # def get_is_run(self,row):
    #     flag = None
    #     col = int(data_config.get_run())
    #     run_model = self.opera_excel.get_cell_value(row,col)
    #     if run_model == 'yes':
    #         flag = True
    #     else:
    #         flag = False
    #     return flag

    #是否携带header
    def is_header(self, row):
        col = int(data_config.get_header(self))
        header = self.opera_excel.get_cell_value(row, col)
        if header != '':
            return header
        else:
            return None

    #获取请求方式
    def get_request_method(self, row):
        col = int(data_config.get_run_way(self))
        request_method = self.opera_excel.get_cell_value(row, col)
        return request_method

    #获取url
    def get_request_url(self, row):
        col = int(data_config.get_url(self))
        url = self.opera_excel.get_cell_value(row, col)
        return url

    #获取请求数据
    def get_request_data(self, row):
        col = int(data_config.get_data(self))
        data = self.opera_excel.get_cell_value(row, col)
        if data == '':
            return None
        return data

    #通过获取关键字拿到data数据
    def get_data_for_json(self,row):
        opera_json = OperetionJson()
        request_data = opera_json.get_data(self.get_request_data(row))
        return request_data

    #获取预期结果
    def get_expcet_data(self,row):
        col = int(data_config.get_expect(self))
        expect = self.opera_excel.get_cell_value(row, col)
        if expect == '':
            return None
        return expect

    #通过sql获取预期结果
    def get_expcet_data_for_mysql(self,row):
        op_mysql = OperationMysql()
        sql = self.get_expcet_data(row)
        res = op_mysql.search_one(sql)
        return res.decode('unicode-escape')

    def write_result(self, row, value):
        col = int(data_config.get_result(self))
        self.opera_excel.write_value(row, col, value)
        return(row, col, value)




    def write_response(self, row, value):
        col = int(data_config.get_response(self))
        self.opera_excel.write_value(row, col, value)
        return(row, col, value)
Exemple #9
0
 def __init__(self, fileName=None, sheetName=None):
     self.opera_excel = OperationExcel(fileName, sheetName)