Exemplo n.º 1
0
class GetCaseData:
    def __init__(self):
        self.op = OperaExcel()

    def get_case_data(self):
        data = []
        row_num = self.op.get_rows_num()
        for i in range(row_num):
            data.append(self.op.get_row_value(i))
        return data
Exemplo n.º 2
0
class GetData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_case_lines(self):
        '''
		获取case的行数
		'''
        lines = self.opera_excel.get_lines()
        return lines

    def get_handle_step(self, row):
        '''
		获取操作步骤里面的操作方法名字
		'''
        method_name = self.opera_excel.get_cell(row, 3)
        return method_name

    def get_element_key(self, row):
        '''
		获取操作元素的key
		'''
        element_key = self.opera_excel.get_cell(row, 4)
        if element_key == '':
            return None
        return element_key

    def get_handle_value(self, row):
        '''
		获取操作元素的值
		'''
        handle_value = self.opera_excel.get_cell(row, 5)
        if handle_value == '':
            return None
        return handle_value

    def get_expect_element(self, row):
        '''
		获取预期结果元素element
		'''
        expect_element = self.opera_excel.get_cell(row, 6)
        if expect_element == '':
            return None
        return expect_element

    def get_is_run(self, row):
        is_run = self.opera_excel.get_cell(row, 8)
        if is_run == 'yes':
            return True
        else:
            return False

    def get_expect_handle(self, row):
        expect_step = self.opera_excel.get_cell(row, 7)
        if expect_step == "":
            return None
        return expect_step

    def write_value(self, row, value):
        self.opera_excel.write_value(row, value)
Exemplo n.º 3
0
class ConfigData:
    def __init__(self, filename=None):
        self.filename = filename
        self.op = OperaExcel(self.filename)

    def get_data_for_excel(self):
        num = self.op.row_count()
        #data = []
        # for i in num:
        #     data.append(self.op.row_data(i))
        data = [self.op.row_data(i) for i in range(num)]
        return data
Exemplo n.º 4
0
 def run_main(self):
     self.action_method = ActionMethod()
     self.handle_excel = OperaExcel()
     case_lines = self.handle_excel.get_lines()
     for i in range(1, case_lines):
         is_run = self.handle_excel.get_cell(i, 2)
         if is_run == "yes":
             method = self.handle_excel.get_cell(i, 3)
             print(method)
             handle_value = self.handle_excel.get_cell(i, 4)
             send_value = self.handle_excel.get_cell(i, 5)
             self.run_method(method, handle_value, send_value)
Exemplo n.º 5
0
class GetData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_case_lines(self):
        lines = self.opera_excel.get_lines()
        return lines

    def get_handle_step(self, row):
        handle_step = self.opera_excel.get_cell(row, 3)
        return handle_step

    def get_element_key(self, row):
        element_key = self.opera_excel.get_cell(row, 4)
        return element_key

    def get_handle_element(self, row):
        handle_element = self.opera_excel.get_cell(row, 5)
        return handle_element

    def get_except_element(self, row):
        print("hello")
        except_element = self.opera_excel.get_cell(row, 6)
        return except_element

    def write_value(self, row, value):
        self.opera_excel.write_value(row, value)
Exemplo n.º 6
0
class MyTestCase:
    def run_main(self):
        self.action_method = ActionMethod()
        self.handle_excel = OperaExcel()
        case_lines = self.handle_excel.get_lines()
        for i in range(1, case_lines):
            is_run = self.handle_excel.get_cell(i, 2)
            if is_run == "yes":
                method = self.handle_excel.get_cell(i, 3)
                print(method)
                handle_value = self.handle_excel.get_cell(i, 4)
                send_value = self.handle_excel.get_cell(i, 5)
                self.run_method(method, handle_value, send_value)

    #python中的反射,通过字符串找class中的方法
    def run_method(self, method, handle_value, send_value):
        action_function = getattr(self.action_method, method)
        action_function(handle_value, send_value)
class GenerateTestCase:

    def __init__(self):
        self.excel=OperaExcel()

    #生成单个测试用例
    def create_single_case(self,sheet_name,information):
        demo=Template('''
    def test_${case_id}_${case_name}(self):
        """${case_description}"""
        url='${url}'
        data=$data
        res=self.s.${method}(url=url,data=data)
        expect ='${expect}'
        logger().info('url:'+'${url}')
        logger().info('data:'+"${data}")
        logger().info('data:'+"${expect}")
        result=res.text
        self.assertIn(expect,result)
        logger().info('result:'+result)
        ''')

        #获取参数
        try:
            if information['data'] == '':
                information['data'] = "None"
            else:
                _data = information['data'].split('.')
                _type=_data.lower()
                if _type=='json':
                    information['data']=OperaJson(sheet_name).get_json_data(information['data'])
                elif _type=='db':
                    sql=OperaJson(sheet_name).get_json_data(information['data'])
                    information['data']=OperaMysql().get_all_db_data(sql)

        except Exception:
            information['data']="获取"+sheet_name+"中"+information['data']+"参数失败"

        string=demo.safe_substitute(information)
        return string

    #生成测试用例集合
    def create_sheet_case(self,sheet_name):
        string=''
        #获取单个sheet中的所有接口数据
        sheet_list=self.excel.get_sheet_data(sheet_name)
        for  data in  sheet_list:
            #循环生成case并拼接为一个字符串
            case=self.create_single_case(sheet_name,data)
            string=string+case
        return string
Exemplo n.º 8
0
class GetData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_excel_lines(self):
        rows = self.opera_excel.get_total_rows()
        return rows

    def get_page_element(self,row):
        #获取页面元素
        page_element = self.opera_excel.get_value(row,3)
        return page_element

    def get_handle_step(self,row):
        #获取操作步骤
        handle_step = self.opera_excel.get_value(row,4)
        return handle_step

    def get_handle_value(self,row):
        #获取操作值
        handle_value = self.opera_excel.get_value(row,5)
        return handle_value

    def get_expected_results(self,row):
        #获取预期结果
        expected_results = self.opera_excel.get_value(row,6)
        return expected_results

    def get_actual_results(self,row):
        #获取实际结果
        actual_results = self.opera_excel.get_value(row,7)
        return actual_results

    def get_isrun(self,row):
        #获取是否执行该用例
        isrun = self.opera_excel.get_value(row,9)
        if isrun == None or isrun =='Y':
            return True
        else:
            return False
Exemplo n.º 9
0
class GetData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_case_lines(self):
        """获取case行数"""
        lines = self.opera_excel.get_lines()
        return lines

    def get_handle_step(self, row):
        """获取操作步骤里面的操作方法"""
        method_name = self.opera_excel.get_cell(row, 3)
        return method_name

    def get_element_key(self, row):
        """获取操作元素的key"""
        element_key = self.opera_excel.get_cell(row, 4)
        if element_key == '':
            return None
        return element_key

    def get_handle_value(self, row):
        """获取操作值"""
        handle_value = self.opera_excel.get_cell(row, 5)
        if handle_value == '':
            return None
        return handle_value

    def get_expect_element(self, row):
        """获取预期结果元素"""
        expect_element = self.opera_excel.get_cell(row, 6)
        if expect_element == '':
            return None
        return expect_element

    def get_is_run(self, row):
        """是否执行"""
        is_run = self.opera_excel.get_cell(row, 8)
        if is_run == 'yes':
            return True
        else:
            return False
Exemplo n.º 10
0
class TestCase:
    def __init__(self):
        self.handle_excel = OperaExcel()
        self.action_method = ActionMethod()
        
    def run_main(self):
        
        case_lines = self.handle_excel.get_lines()
        for i in range(1, case_lines):
            is_run = self.handle_excel.get_cell(i, 2)
            if is_run == "yes":
                case_num = self.handle_excel.get_cell(i, 0)
                print(f"开始测试: {case_num}")
                method = self.handle_excel.get_cell(i, 3)
                handle_value = self.handle_excel.get_cell(i, 4)
                send_value = self.handle_excel.get_cell(i, 5)
                # print(method, handle_value, send_value)
                if send_value == '':
                    if handle_value == '':
                        self.run_method(method)
                    else:
                        self.run_method(method, handle_value)
                else:
                    self.run_method(method, handle_value, send_value)

    def run_method(self, method, handle_value=None, send_value=None):
        """反射机制"""
        # print(method, handle_value, send_value)
        action_function = getattr(self.action_method, method)
        if send_value is None:
            if handle_value is None:
                action_function()
            else:
                action_function(handle_value)
        else:
            action_function(handle_value, send_value)
Exemplo n.º 11
0
class GetCaseExcelData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_case_lines(self):
        """
        获取case的行数
        :return:
        """
        return self.opera_excel.max_row

    def get_handle_step(self, row):
        """
        获取case表中 操作步骤一列中的 操作方法名称
        :param row:
        :return:
        """
        method_name = self.opera_excel.get_value(row, 4)
        return method_name

    def get_handle_element(self, row):
        """
        获取case表中 操作元素一列中的 元素名称
        :param row:
        :return:
        """
        element = self.opera_excel.get_value(row, 5)
        if element == '':
            element = None
        return element

    def get_handle_value(self, row):
        """
        获取case表中 操作值一列中的 操作值
        :param row:
        :return:
        """
        value = self.opera_excel.get_value(row, 6)
        if value == '':
            value = None
        return value

    def get_expect_step(self, row):
        """
        获取case表中 预期结果操作步骤一列中的 操作方法名称
        :param row:
        :return:
        """
        method_name = self.opera_excel.get_value(row, 7)
        if method_name == '':
            method_name = None
        return method_name

    def get_expect_element(self, row):
        """
        获取case表中 预期结果操作步骤一列中的 操作方法名称
        :param row:
        :return:
        """
        element = self.opera_excel.get_value(row, 8)
        if element == '':
            element = None
        return element

    def get_is_run(self, row):
        """
        获取case表中 是否运行一列中的 yes/no
        :param row:
        :return:
        """
        is_run = self.opera_excel.get_value(row, 10)
        if is_run == 'yes':
            return True
        else:
            return False

    def write_result(self, row, value):
        """
        将结果会写到case表中 实际运行结果一列
        :param row:
        :return:
        """
        self.opera_excel.write_excel(row, 9, value)
Exemplo n.º 12
0
 def __init__(self):
     self.op = OperaExcel()
Exemplo n.º 13
0
 def __init__(self, filename=None):
     self.filename = filename
     self.op = OperaExcel(self.filename)
Exemplo n.º 14
0
 def run_main(self):
     user = UserLog()
     log = user.get_log()
     log.debug('debug-test')
     #log.info('keyword_case')
     self.action_method = actionMethod()
     handle_excel = OperaExcel(
         'C:/Users/xx/Desktop/SeleniumPython2/config/keyword.xls', 0)
     case_lines = handle_excel.get_lines()
     if case_lines:
         for i in range(1, case_lines):
             #is_run是否执行
             is_run = handle_excel.get_cell(i, 3)
             if is_run == 'yes':
                 #method:执行方法;send_value:输入的数据;handle_value:操作元素
                 method = handle_excel.get_cell(i, 4)
                 send_value = handle_excel.get_cell(i, 5)
                 handle_element = handle_excel.get_cell(i, 6)
                 except_result_method = handle_excel.get_cell(i, 7)
                 except_result = handle_excel.get_cell(i, 8)
                 self.run_method(method, handle_element, send_value)
                 if except_result != '':
                     #将预期结果值根据=划分成list
                     except_value = self.get_except_result_value(
                         except_result)
                     if except_value[0] == 'text':
                         result = self.run_method(except_result_method,
                                                  handle_element, '')
                         if except_value[1] in result:
                             handle_excel.write_value(i, 'pass')
                         else:
                             handle_excel.write_value(i, 'fail')
                     elif except_value[0] == 'element':
                         result = self.run_method(except_result_method,
                                                  except_value[1], '')
                         if result != 'error':
                             handle_excel.write_value(i, 'pass')
                         else:
                             handle_excel.write_value(i, 'fail')
                     else:
                         print('没有else')
                 else:
                     print('没有预期结果')
Exemplo n.º 15
0
 def __init__(self, i):
     self.driver = BaseDriver().android_driver(i)
     self.get_by_local = GetByLocal(self.driver)
     self.opera_excel = OperaExcel()
     self.width = self.get_window_size()[0]
     self.height = self.get_window_size()[1]
Exemplo n.º 16
0
class ActionMethod:
    def __init__(self, i):
        self.driver = BaseDriver().android_driver(i)
        self.get_by_local = GetByLocal(self.driver)
        self.opera_excel = OperaExcel()
        self.width = self.get_window_size()[0]
        self.height = self.get_window_size()[1]

    def input(self, *args):
        element = self.get_by_local.get_element(args[0])
        if not element:
            return args[0], "element not found"
        element.send_keys(args[1])

    def on_click(self, *args):
        print(args)
        element = self.get_by_local.get_element(args[0])
        if not element:
            return args[0], "element not found"
        element.click()

    def sleep_time(self, *args):
        time.sleep(args[0])

    def get_window_size(self):
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        return width, height

    def swipe_up(self, *args):

        start_x, end_x = self.width / 2, self.width / 2
        start_y, end_y = self.height * 9 / 10, self.height[1] / 10
        self.driver.swipe(start_x, start_y, end_x, end_y)

    def swipe_down(self, *args):
        start_x, end_x = self.width / 2
        start_y, end_y = self.height / 10, self.height * 9 / 10
        self.driver.swipe(start_x, start_y, end_x, end_y)

    def swipe_left(self, *args):
        start_x, end_x = self.width * 9 / 10, self.width / 10
        start_y, end_y = self.height / 2, self.height / 2
        self.driver.swipe(start_x, start_y, end_x, end_y)

    def swipe_right(self, *args):
        start_x, end_x = self.width / 10, self.width * 9 / 10
        start_y, end_y = self.height / 2, self.height / 2
        self.driver.swipe(start_x, start_y, end_x, end_y)

    def get_toast_element(self, *args):
        time.sleep(2)
        toast_element = ("xpath", "//*[contains(@text, " + args[0] + ")]")
        return WebDriverWait(self.driver, 10, 0.1).until(
            EC.presence_of_element_located(toast_element))

    def get_excel_lines(self, *args):
        lines = self.opera_excel.get_lines()
        return lines

    def get_element(self, *args):
        element = self.get_by_local.get_element(args[0])
        return element
Exemplo n.º 17
0
 def __init__(self):
     self.handle_excel = OperaExcel()
     self.action_method = ActionMethod()
Exemplo n.º 18
0
class ConfigData:
    def __init__(self,filename="../config/case_key.xls"):
        self.op = OperaExcel(filename)

    def get_case_id(self,row):
        value = self.op.get_value(row,0)
        if value == '':
            return None
        else:
            return value

    def get_case_name(self,row):
        value = self.op.get_value(row,1)
        if value == '':
            return None
        else:
            return value

    def get_opera_desc(self,row):
        value = self.op.get_value(row,2)
        if value == '':
            return None
        else:
            return value

    def get_opera_method(self,row):
        value = self.op.get_value(row,3)
        if value == '':
            return None
        else:
            return value

    def get_opera_element_key(self,row):
        value = self.op.get_value(row,4)
        if value == '':
            return None
        else:
            return value


    def get_opera_data(self,row):
        value = self.op.get_value(row,5)
        if value == '':
            return None
        else:
            return value

    def get_expect_element(self,row):
        value = self.op.get_value(row,6)
        if value == '':
            return None
        else:
            return value

    def get_expect_method(self,row):
        value = self.op.get_value(row, 7)
        if value == '':
            return None
        else:
            return value

    def get_expect_result(self,row):
        value = self.op.get_value(row,8)
        if value == '':
            return None
        else:
            return value

    def write_real_result(self,row,value):
        self.op.write_value(row,9,value)

    def get_lines(self):
        return self.op.get_rows_num()

    def get_is_run(self,row):
        value = self.op.get_value(row, 10)
        if value == '':
            return None
        else:
            return value
Exemplo n.º 19
0
 def __init__(self,filename="../config/case_key.xls"):
     self.op = OperaExcel(filename)
Exemplo n.º 20
0
 def __init__(self):
     self.opera_excel = OperaExcel()
Exemplo n.º 21
0
class GetData:
    def __init__(self):
        self.opera_excel = OperaExcel()

    def get_case_lines(self):
        """
        获取行号,在opera_excel已经有相应的方法,但为了后续简洁  不需要在导入其他的包,创立此方法
        :return:
        """
        lines = self.opera_excel.get_lines()
        return lines

    def get_handle_step(self, row):
        """
        获取操作步骤里面的方法名字
        传入行号,获取预期,调用opera_excel.get_cell(),将列写死
        :param row:
        :return:
        """
        method_name = self.opera_excel.get_cell(row, 3)
        if method_name is None:
            return None
        return method_name

    def get_element_key(self, row):
        """
        获取操作元素
        :param row:
        :return:
        """
        element_key = self.opera_excel.get_cell(row, 4)
        if element_key is None:
            return None
        return element_key

    def get_handle_value(self, row):
        """
        获取操作元素值
        :param row:
        :return:
        """
        handle_value = self.opera_excel.get_cell(row, 5)
        if handle_value is None:
            return None
        return handle_value

    def get_expect_element(self, row):
        """
        获取预期结果
        :param row:
        :return:
        """
        expect_element = self.opera_excel.get_cell(row, 6)
        if expect_element == '':
            return None
        return expect_element

    def get_expect_handle_step(self, row):
        expect_handle_step = self.opera_excel.get_cell(row, 7)
        if expect_handle_step is None:
            return None
        return expect_handle_step

    def is_run(self, row):
        """
        获取是否执行
        :param row:
        :return:
        """
        is_run = self.opera_excel.get_cell(row, 8)
        if is_run == 'yes':
            return True
        else:
            return False