用例:模糊搜索
打开APP(未登录账户)进入首页-搜索点击热门关键字搜索检测搜索到的卡是否包含Excel表中所有数据一、 说明
数据源 数据驱动以 Read Column From Excel 方式实现,关于详情请查看个人博客数据驱动部分。滑屏问题 因为模糊搜索结果较多,一屏无法显示所有的结果,需要滑屏; 而不同型号的手机有不同的分辨率,关键字:swipe 有时无法精确定位; 手机型号选择,根据公司需求可以选择主流手机进行测试。二、关键字:APP_Get_All_Search_Courses
滑屏方式:
封装关键字:APP_Sliding_Screen_by_resolution RIDE关键字 swipe 有时因为分辨率不同,无法精确定位。所以,以屏幕分辨率封装关键字。RIDE关键字:swipe思路:
查找唯一 的 resource-id(这个需要和开发确定。如果没有唯一 的 resource-id,通过xpath实现);例如,需要定位 5 个控件,有些机型一个屏幕只能显示 4 个;通过 index 定位,先找到 4 个控件;再通过 swipe 滑动屏幕,查找结果全局参数:U_ANDROID_DEVICES_TYPE 区分不同机型;例如,华为手机 '%{U_ANDROID_DEVICES_TYPE}'=='HUAWEI'三、关键字:APP_Sliding_Screen_by_resolution
方案:先通过 Get Window Height & Get Window Width 获取屏幕高和宽,再通过百分比实现滑屏。
四、关键字:swipe_by_percent
库更新:Appiumlibrary (1.4.5) 最近 Appiumlibrary 发布新版本,已经封装了通过分辨率来滑动屏幕的关键字 swipe_by_percent,和 APP_Sliding_Screen_by_resolution 实现的原理一样。 源码:
def swipe_by_percent(self, start_x, start_y, end_x, end_y, duration=1000): """ Swipe from one percent of the screen to another percent, for an optional duration. Normal swipe fails to scale for different screen resolutions, this can be avoided using percent. Args: - start_x - x-percent at which to start - start_y - y-percent at which to start - end_x - x-percent distance from start_x at which to stop - end_y - y-percent distance from start_y at which to stop - duration - (optional) time to take the swipe, in ms. Usage: | Swipe By Percent | 90 | 50 | 10 | 50 | # Swipes screen from right to left. | _*NOTE: *_ This also considers swipe acts different between iOS and Android. New in AppiumLibrary 1.4.5 """ width = self.get_window_width() height = self.get_window_height() x_start = float(start_x) / 100 * width x_end = float(end_x) / 100 * width y_start = float(start_y) / 100 * height y_end = float(end_y) / 100 * height x_offset = x_end - x_start y_offset = y_end - y_start platform = self._get_platform() if platform == 'android': self.swipe(x_start, y_start, x_end, y_end, duration) else: self.swipe(x_start, y_start, x_offset, y_offset, duration)