Exemple #1
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)
Exemple #2
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('没有预期结果')
Exemple #3
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
Exemple #4
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)
Exemple #5
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
Exemple #6
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