def test_case(init_api):  #传入测试数据整体
    global result
    method = init_api[0]['Method']
    url = init_api[0]['Url']
    param = eval(init_api[0]['Params'])  # params 本身是一个字符串
    expected_result = eval(init_api[0]['ExpectedResult'])  # 本身也是一个字符串
    # 发起测试
    init_api[2].info('正在执行{}模块第{}条用例:{}'.format(init_api[0]['Module'],
                                                init_api[0]['CaseId'],
                                                init_api[0]['Title']))
    init_api[2].info('参数是{}'.format(param))
    #    实例化请求
    res = HttpRequest()
    resp = res.http_request(method, url, param, cookies=None)
    print('实际结果是{}'.format(resp.json()))
    #  对比
    try:
        assert expected_result == resp.json()
        result = 'pass'
        init_api[2].info('该条用例通过')
    except Exception as e:
        result = 'failed'
        init_api[2].info('该条用例失败,{}'.format(e))
        raise e

    MyLog().info('本条用例结束')
Beispiel #2
0
class RunCase(unittest.TestCase):
    def setUp(self):
        self.do_exl=DoExcel(project_path.case_path,'Register')    # 准备测试数据
        self.my_log=MyLog()
    # 登录注册
    @pytest.mark.moke_two
    @data(*register_data)   # 加*解包,相当于遍历test_data传入函数,与加unpack的区别是:加入了unpack后,date里有几个参数,下面的函数就要传入几个变量
    def test_case(self,case):
        global result   #声明全局变量
        method=case['Method']
        url=case['Url']
        param=eval(case['Params'])
        # print(param)

        expected=eval(case['ExpectedResult'])
        #发起测试
        # print('-------正在测试{}模块里面第{}条测试用例:{}'.format(case['Module'],case['CaseId'],case['Title']))
        self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'],case['CaseId'],case['Title']))
        self.my_log.info('参数是:{}'.format(param))
        res=HttpRequest()  #实例化
        resp=res.http_request(method,url,param,cookies=None)
        print('实际结果:{}'.format(resp.json()))#http发送请求拿到的实际返回值
        #对比结果
        try:
            self.assertEqual(expected,resp.json())
            result='pass'
            self.my_log.info('该条测试用例通过')
            # print('该条测试用例通过')
        except  AssertionError as e:
            result='failed'
            self.my_log.error('该条测试用例不通过:'.format(e))
Beispiel #3
0
class RunCase(unittest.TestCase):
    def setUp(self):
        self.do_exl = DoExcel(case_path,'Login')
        self.my_log = MyLog()
    @data(*login_data_new)  #测试数据
    def test_case(self,case): #传入测试数据整体
        global result
        method = case['Method']
        url = case['Url']
        param = eval(case['Params'])    # params 本身是一个字符串
        expected_result = eval(case['ExpectedResult'])  # 本身也是一个字符串
    # 发起测试
        self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'], case['CaseId'], case['Title']))
        self.my_log.info('参数是{}'.format(param))
    #     实例化请求
        res = HttpRequest()
        resp = res.http_request(method,url,param,cookies=None)
        print('实际结果是{}'.format(resp.json()))
    #   对比
        try:
            self.assertEqual(expected_result,resp.json())
            result = 'pass'
            self.my_log.info('该条用例通过')
        except Exception as e:
            result = 'failed'
            self.my_log.info('该条用例失败,{}'.format(e))
            raise e
        finally:
            final_result = result
            # 写会实际结果与是否通过
            self.do_exl.write_back(case['CaseId']+1,8,resp.text)    # TODO:注意是写回text,不能写回json
            self.do_exl.write_back(case['CaseId']+1,9,final_result)
            self.my_log.info('写入数据完毕')
        self.my_log.info('本条用例结束')



    def tearDown(self):
        pass
Beispiel #4
0
class RunCase(unittest.TestCase):
    def setUp(self):
        self.do_exl = DoExcel(project_path.case_path, 'Withdraw')  # 准备测试数据
        self.my_log = MyLog()

    @data(
        *withdraw_data
    )  # 加*解包,相当于遍历test_data传入函数,与加unpack的区别是:加入了unpack后,date里有几个参数,下面的函数就要传入几个变量
    def test_case2(self, case_2):
        global result1
        # url_login='******'
        # param_login={'mobilephone':'18688775656','pwd':'123456'}
        # method_login='******'
        # # 获取到登录的cookies
        # cookies=HttpRequest().http_request(method_login,url_login,param_login,cookies=None).cookies
        url = case_2['Url']
        param = eval(case_2['Params'])
        method = case_2['Method']
        expected = eval(case_2['ExpectedResult'])

        # if case_2['Params'].find('normal_phone') != -1:
        #     param['mobilephone']=getattr(GetData,'normal_phone')

        # 调用正则函数替换mobilephone,pwd:
        param = eval(get_data.replace(case_2['Params']))
        # print(param)

        self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case_2['Module'],
                                                    case_2['CaseId'],
                                                    case_2['Title']))
        self.my_log.info('参数是:{}'.format(param))

        resp = HttpRequest().http_request(
            method, url, param, cookies=getattr(GetData,
                                                'cookies'))  #根据反射取值cookies
        print('实际结果是:{}'.format(resp.json()))  #发起请求的实际结果
        if resp.cookies:  #为真,即存在cookies
            setattr(GetData, 'cookies', resp.cookies)  #根据反射重新赋值cookies

        # 对比结果
        try:
            self.assertEqual(expected['code'], resp.json()['code'])  #对比code
            result1 = 'pass'
            self.my_log.info('该条测试用例通过')
        except AssertionError as e:
            self.my_log.error('该条测试用例不通过:{}'.format(e))
            result1 = 'failed'
Beispiel #5
0
class RunCase(unittest.TestCase):
    def setUp(self):
        self.do_exl = DoExcel(project_path.case_path, 'Login')  # 准备测试数据
        self.my_log = MyLog()

    # 登录注册
    @pytest.mark.moke
    @data(
        *login_data
    )  # 加*解包,相当于遍历test_data传入函数,与加unpack的区别是:加入了unpack后,date里有几个参数,下面的函数就要传入几个变量
    def test_case(self, case):
        global result  #声明全局变量
        method = case['Method']
        url = case['Url']
        param = eval(case['Params'])
        # print(param)
        expected = eval(case['ExpectedResult'])
        # # 查找替换mobilephone
        # if case['Params'].find('normal_phone') != -1:
        #     param['mobilephone']=getattr(GetData,'normal_phone')
        # # print(param)

        # 调用正则函数替换mobilephone,pwd:TODO:只替换Params
        param = eval(get_data.replace(case['Params']))

        #发起测试
        # print('-------正在测试{}模块里面第{}条测试用例:{}'.format(case['Module'],case['CaseId'],case['Title']))
        self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'],
                                                    case['CaseId'],
                                                    case['Title']))
        self.my_log.info('参数是:{}'.format(param))
        res = HttpRequest()  #实例化
        resp = res.http_request(method, url, param, cookies=None)
        print('实际结果:{}'.format(resp.json()))  #http发送请求拿到的实际返回值
        #对比结果
        try:
            self.assertEqual(expected, resp.json())
            result = 'pass'
            self.my_log.info('该条测试用例通过')
            # print('该条测试用例通过')
        except AssertionError as e:
            result = 'failed'
            self.my_log.error('该条测试用例不通过:'.format(e))
Beispiel #6
0
 def setUp(self):
     self.do_exl=DoExcel(project_path.case_path,'Register')    # 准备测试数据
     self.my_log=MyLog()
Beispiel #7
0
 def setUp(self):
     self.do_exl = DoExcel(case_path,'Login')
     self.my_log = MyLog()
Beispiel #8
0
 def setUp(self):
     self.do_exl = DoExcel(project_path.case_path, 'Withdraw')  # 准备测试数据
     self.my_log = MyLog()