Ejemplo n.º 1
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
Ejemplo n.º 2
0
class ActionMethod:
    def __init__(self):
        self.driver = BaseDriver().android_driver(0)
        self.get_by_local = GetByLocal(self.driver)

    def input(self, section, key, value):
        """元素输入"""
        element = self.get_by_local.get_element(section, key)
        if element == None:
            return str(section) + " or " + str(key) + "元素未找到❗❗❗️"
        element.send_keys(value)

    def on_click(self, section, key):
        """元素点击"""
        element = self.get_by_local.get_element(section, key)
        if element == None:
            return str(section) + " or " + str(key) + "元素未找到❗❗❗️"
        element.click()

    def sleep_time(self, value):
        """等待时长"""
        time.sleep(value)

    def get_size(self):
        """获取屏幕宽和高"""
        size = self.driver.get_window_size(
        )  # 返回字典{'height': 2560, 'width': 1440}
        height = size['height']  # y
        width = size['width']  # x
        return width, height  # 返回元祖(1440, 2560)

    def swipe_left(self):
        """向左滑动"""
        x1 = self.get_size()[0] / 10 * 9
        y1 = self.get_size()[1] / 2
        x = self.get_size()[0] / 10
        self.driver.swipe(x1, y1, x, y1)

    def swipe_right(self):
        """向右滑动"""
        x1 = self.get_size()[0] / 10
        y1 = self.get_size()[1] / 2
        x = self.get_size()[0] / 10 * 9
        self.driver.swipe(x1, y1, x, y1)

    def swipe_up(self):
        """向上滑动"""
        x1 = self.get_size()[0] / 2
        y1 = self.get_size()[1] / 10 * 9
        y = self.get_size()[1] / 10
        self.driver.swipe(x1, y1, x1, y)

    def swipe_down(self):
        """向下滑动"""
        x1 = self.get_size()[0] / 2
        y1 = self.get_size()[1] / 10
        y = self.get_size()[1] / 10 * 9
        self.driver.swipe(x1, y1, x1, y)

    def swipe_on(self, direction):
        """滑动封装"""
        if direction == 'up':
            self.swipe_up()
        elif direction == 'down':
            self.swipe_down()
        elif direction == 'left':
            self.swipe_left()
        else:
            self.swipe_right()