在编写iOSUI自动化测试过程中,由于公司app使用flutter开发页面无法通过元素来定位,只能通过坐标来点击,再配合图片对比校验来实现。使用坐标点击就带来一个问题我们通常能看到一个机型的绝对坐标无法在其它iPhone设备上运行,所以考虑将appium中的tap()函数封装一下,实现输入一个坐标值可以在任何iOS设备上执行。代码如下
def my_tap(self, abs_width, abs_height):
‘’’
abs_width:绝对宽度坐标
abs_height:绝对高度坐标
根据绝对坐标算出相对坐标,兼容其它机型,
iphone x 之前的机型宽高比为:9:16 = 0.5625
iPhone x 之后的机型宽高比为:9:19.5 约等于0.46
根据宽高比来适配
‘’’
left = self.driver.get_window_size()[‘width’]
height = self.driver.get_window_size()[‘height’]
num = “%.2f” % (left / height) # 取小数点前两位
if num == ‘0.46’: # iPhonex及以上的设备
relative_width_x = abs_width / 375 # 相对宽度
relative_height_x = abs_height / 812 # 相对高度
actual_width_x = self.driver.get_window_size()[‘width’] # 实际设备的宽度
actual_height_x = self.driver.get_window_size()[‘height’] # 实际设备的高度
self.driver.tap([(relative_width_x * actual_width_x, relative_height_x * actual_height_x)], 100)
elif left / height == 0.5625: # iPhonex及以下的设备
relative_width = abs_width / 414
appium iOS tap()函数封装
最新推荐文章于 2023-08-04 13:30:49 发布