• 【Airtest】Airtest中swipe方法兼容不同分辨率的解决方法


    使用Airtest中swipe方法由于不同分辨率的手机上滑动的坐标位置不同,所以想要兼容所有的手机,仅仅靠固定坐标就会出现问题

    想要兼容所有的手机,可以按照如下思路进行

    1、首先获取手机的分辨率,可以使用Airtest中的poco模块的get_screen_size()方法

    poco.get_screen_size()

    此时获取到了手机的分辨率,可以看出屏幕宽等于900,长度等于1600

    2、将屏幕的宽度和长度分别赋值为x和y,注意屏幕左上角的坐标为(0,0),所以左下角的坐标为(0,1600),右上角的坐标为(900,0),右下角的坐标为(900,1600)

    xy = poco.get_screen_size()
    x = xy[0]
    y = xy[1]

    3、按照屏幕的比例进行滑动,我想要从屏幕的右侧向左侧滑动,就可以按照如下方法进行,从(0.9*x,0.5*y)的坐标移动到(0.1*x,0.5y)的坐标,也就是从(810,800)的坐标移动到(90,800)的坐标

    swipe((0.9*x,0.5*y),(0.1*x,0.5*y),duration=1)

    4、完整代码运行

    # -*- encoding=utf8 -*-
    __author__ = "fengruishou"
    
    from airtest.core.api import *
    
    
    from poco.drivers.android.uiautomation import AndroidUiautomationPoco
    poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
    
    auto_setup(__file__)
    
    print(poco.get_screen_size())
    xy = poco.get_screen_size()
    x = xy[0]
    y = xy[1]
    swipe((0.9*x,0.5*y),(0.1*x,0.5*y),duration=1)

     

  • 相关阅读:
    PAT顶级 1024 Currency Exchange Centers (35分)(最小生成树)
    Codeforces 1282B2 K for the Price of One (Hard Version)
    1023 Have Fun with Numbers (20)
    1005 Spell It Right (20)
    1092 To Buy or Not to Buy (20)
    1118 Birds in Forest (25)
    1130 Infix Expression (25)
    1085 Perfect Sequence (25)
    1109 Group Photo (25)
    1073 Scientific Notation (20)
  • 原文地址:https://www.cnblogs.com/ffrs/p/11746175.html
Copyright © 2020-2023  润新知