Ejemplo n.º 1
0
    def _touch_point_by_orientation(self, tuple_xy):
        """
        Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner
        of the device physical display

        Args:
            tuple_xy: image coordinates (x, y)

        Returns:

        """
        x, y = tuple_xy

        # use correct w and h due to now orientation
        # _size 只对应竖直时候长宽
        now_orientation = self.orientation

        if now_orientation in [PORTRAIT, PORTRAIT_UPSIDEDOWN]:
            width, height = self._size['width'], self._size["height"]
        else:
            height, width = self._size['width'], self._size["height"]

        # check if not get screensize when touching
        if not width or not height:
            # use snapshot to get current resuluton
            self.snapshot()

        x, y = XYTransformer.up_2_ori(
            (x, y),
            (width, height),
            now_orientation
        )
        return x, y
Ejemplo n.º 2
0
Archivo: ios.py Proyecto: yi-fy/Airtest
    def _touch_point_by_orientation(self, tuple_xy):
        """
        Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner
        of the device physical display

        Args:
            tuple_xy: image coordinates (x, y)

        Returns:

        """
        x, y = tuple_xy

        # 部分设备如ipad,在横屏+桌面的情况下,点击坐标依然需要按照竖屏坐标额外做一次旋转处理
        if self.is_pad and self.orientation != wda.PORTRAIT:
            if not self.home_interface():
                return x, y

            width = self.display_info["width"]
            height = self.display_info["height"]
            if self.orientation in [wda.LANDSCAPE, wda.LANDSCAPE_RIGHT]:
                width, height = height, width
            if x < 1 and y < 1:
                x = x * width
                y = y * height
            x, y = XYTransformer.up_2_ori(
                (x, y),
                (width, height),
                self.orientation
            )
        return x, y
Ejemplo n.º 3
0
Archivo: ios.py Proyecto: ksti/Airtest
    def _touch_point_by_orientation(self, tuple_xy):
        """
        Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner
        of the device physical display

        Args:
            tuple_xy: image coordinates (x, y)

        Returns:

        """
        x, y = tuple_xy

        # 1. 如果使用了2022.03.30之后发布的iOS-Tagent版本,则必须要进行竖屏坐标转换
        # 2. 如果使用了appium/WebDriverAgent>=4.1.4版本,直接使用原坐标即可,无需转换
        # 3. 如果使用了appium/WebDriverAgent<4.1.4版本,或低版本的iOS-Tagent,并且ipad下横屏点击异常,请改用airtest<=1.2.4
        if self.using_ios_tagent:
            width = self.display_info["width"]
            height = self.display_info["height"]
            if self.orientation in [wda.LANDSCAPE, wda.LANDSCAPE_RIGHT]:
                width, height = height, width
            if x < 1 and y < 1:
                x = x * width
                y = y * height
            x, y = XYTransformer.up_2_ori((x, y), (width, height),
                                          self.orientation)
        return x, y
Ejemplo n.º 4
0
def json_parser(node, screen_size, switch_flag=False, ori='PORTRAIT'):
    """

    :param node: node info {}
    :param screen_size: ios.windows_size()
    :param switch_flag: If it is an ipad , when on the desktop, all coordinates must be converted to vertical screen coordinates
    :param ori: wda ['PORTRAIT', 'LANDSCAPE',
                    'UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT',
                    'UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN']
    :return:
    """
    screen_w, screen_h = screen_size

    if "name" in node and node["name"]:
        name = node["name"]
    else:
        name = node["type"]

    data = {"name": name, "payload": {}}

    if six.PY2:
        for key in [x for x in node.keys() if x not in ['frame', 'children']]:
            data["payload"][key.encode("utf-8")] = node[key]
    else:
        for key in [x for x in node.keys() if x not in ['frame', 'children']]:
            data["payload"][key] = node[key]

    w = float(node["rect"]["width"])
    h = float(node["rect"]["height"])
    x = float(node["rect"]["x"])
    y = float(node["rect"]["y"])

    if switch_flag:
        x, y = XYTransformer.ori_2_up((x, y), (screen_w, screen_h), ori)
    if switch_flag and ori == 'LANDSCAPE':
        w, h = h, w
        data["payload"]["pos"] = [(x + w / 2) / screen_w,
                                  (y - h / 2) / screen_h]
    elif switch_flag and ori == 'UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT':
        w, h = h, w
        data["payload"]["pos"] = [(x - w / 2) / screen_w,
                                  (y + h / 2) / screen_h]
    elif switch_flag and ori == 'UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN':
        data["payload"]["pos"] = [(x - w / 2) / screen_w,
                                  (y - h / 2) / screen_h]
    else:
        data["payload"]["pos"] = [(x + w / 2) / screen_w,
                                  (y + h / 2) / screen_h]

    data["payload"]["name"] = name
    data["payload"]["size"] = [w / screen_w, h / screen_h]

    data["payload"]["zOrders"] = {
        "local": 0,
        "global": 0,
    }
    data["payload"]["anchorPoint"] = [0.5, 0.5]

    # TODO: w = 0 and h = 0 situation need to solve with
    # roll back set as True when finding a visible child
    if "visible" not in node:
        if (x >= 0 or x + w > 0) and (x < screen_w) and (
                y >= 0 or y + h > 0) and (y < screen_h):
            data["payload"]["visible"] = True
        elif w == 0 or h == 0:
            data["payload"]["visible"] = True
        else:
            data["payload"]["visible"] = False

    children_data = []
    if "children" in node:
        for child in node["children"]:
            child_data = json_parser(child,
                                     screen_size=screen_size,
                                     switch_flag=switch_flag,
                                     ori=ori)
            children_data.append(child_data)

    if children_data:
        data["children"] = children_data
        if data["payload"]["visible"] is False:
            for child_node in children_data:
                if child_node["payload"].get("visible") is True:
                    data["payload"]["visible"] = True
                    break

    return data