概述
1 #-*- coding: utf-8 -*-
2
3 importatx4 importos5 from PIL importImage6 importpytest7 importallure8 from allure_commons.types importAttachmentType9 from logzero importlogger10 from uiautomator2 importUiObjectNotFoundError11 #from base.chromedrvier import ChromeDriver
12 from atx.ext.chromedriver importChromeDriver13
14
15 ISMAC = 1
16 TIMEOUT = 10
17 @allure.step("{0}")18 defconnect_phone(devices):19 globalpackage_name,main_activity20 #devices = "D6JNOV5PCANFAURW"
21 logger.info("连接:" +devices)22 package_name = 'com.netease.cloudmusic'#网易云音乐APP的包名
23 main_activity = ".activity.LoadingActivity" #网易云音乐的activity
24 d = atx.connect(devices)#手机的devices name
25 d.start_app(package_name, main_activity)#启动网易云音乐app
26 returnd27
28 @allure.step("{1}")29 def click_text(atx_conn, action_m, text, timeout=TIMEOUT):30 """
31 点击安卓原生的控件32 :param atx_conn:atx实例33 :param action_m:执行的行为描述34 :param text:需要查找的按钮的文本35 :param timeout:等待36 :return:37 """
38
39 logger.info(action_m)40 atx_conn(text=text).click(timeout=timeout)41 report_jietu(atx_conn,action_m)#截图
42
43 @allure.step("{1}")44 def click_id(atx_conn, action_m, id, timeout=TIMEOUT):45 """
46
47 :param atx_conn: 连接实例48 :param action_m: 操作描述49 :param id: resureid50 :param timeout: 超时时间51 :return:52 """
53 logger.info(action_m)54 atx_conn(resourceId = id).click(timeout=timeout)55 report_jietu(atx_conn,action_m)#截图
56
57 defreport_jietu(atx_conn,action_m):58 """
59 截图60 :param atx_conn:atx实例61 :param action_m:action_m,被用作图片名称62 :return:63 """
64 image = screenshot(atx_conn,action_m)#截图
65 with open(image,"rb") as f :66 file =f.read()67 allure.attach(action_m,file,allure.attach_type.PNG)#截图附件
68
69 defscreenshot(atx_conn,url):70 """
71 截图72 :param atx_conn:atx实例73 :param url:url,被用作图片名称74 :return:75 """
76
77 path =os.path.abspath(os.path.dirname(os.getcwd()))78 ifISMAC:79 path = path + "/report/image/%s.png" %(url)80 else:81 path = path + "\report\image\%s.png" %(url)82 imgname =path83 atx_conn.screenshot(imgname)84 img(imgname)85 returnimgname86
87 defimg(image):88 """
89 对图片进行压缩,覆盖原图进行保存90 :param image: 图片路径91 :return:92 """
93
94 im =Image.open(image)95 #获得图像尺寸
96 w, h =im.size97 #print('原图尺寸: %sx%s' % (w, h))
98 #缩放到25%:
99 im.thumbnail((w // 4, h // 4))100 #把缩放后的图像用jpeg格式保存:
101 im.save(image)102
103
104
105 @allure.feature('网易云音乐')106 classTest_misuc(object):107 @allure.story('进入每日推荐,点击播放第一首歌曲')108 def test_meirituijian(self):#进入每日推荐,点击播放第一首歌曲
109 d = connect_phone("D6JNOV5PCANFAURW")#连接手机,启动云音乐
110 click_text(d,"点击每日推荐","每日推荐")#点击每日推荐
111 click_text(d,"点击播放全部","播放全部")#点击播放全部
112 click_id(d,"点击暂停播放按钮","com.netease.cloudmusic:id/tr")#点击暂停播放按钮
113 d.stop_app(package_name) #关闭云音乐
114
115 @allure.story('进入我喜欢的音乐,将第一首歌分享给好友')116 def test_share(self):#分享歌曲给好友
117 d = connect_phone("D6JNOV5PCANFAURW")#连接手机,启动云音乐
118 click_text(d,"点击我的","我的")119 click_text(d,"点击我喜欢的音乐","我喜欢的音乐")120 click_id(d,"点击更多","com.netease.cloudmusic:id/a")121 click_text(d,"点击分享","分享")122 click_text(d,"点击分享微信好友","微信好友")123 #driver = ChromeDriver(d).driver() #启动selenium 如果是webview页面的话,需要启动selenium,然后根据selenium的定位方式查找元素
124 click_text(d,"分享给唯安格","唯安格")125 click_text(d,"点击分享","分享")126 click_text(d,"点击返回网易云音乐","返回网易云音乐")127 d.stop_app(package_name)128
129
130
131
132 if __name__ == '__main__':133 a =Test_misuc()134 a.test_meirituijian()135 a.test_share()
最后
以上就是标致紫菜为你收集整理的axt测试软件,atx测试框架实现手机应用UI自动化测试的全部内容,希望文章能够帮你解决axt测试软件,atx测试框架实现手机应用UI自动化测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复