UIautomator2 滑动屏幕 及保存图片的操作

1.保存图片 

img=phone.screenshot() #屏幕截图,
t=time.time()
imgName='imgName'+datetime.datetime.now ().strftime ('%Y%m%d%H%M%S')+ str ( round ( (t - int ( t )) * 1000 ) )+'.png' #截图可以单独保存为别的名字的文件
stringPath='D:\CYY\HSFAPP\\'+imgName
#img.save('filename.png')#图片保存在当前项目的文件夹下边
img.save(stringPath)#保存文件到指定的文件夹下边

def cap_screen( self,filepath:str,filename:str ):
pic_name=filepath+filename+datetime.now().strftime("%Y%m%d%H%M%S").jpg
self.d.screenshot(pic_name)
return pic_name


2. 上下左右滑动屏幕 ,其中percentage为向指定方向滑动百分之多少,为float型数据
phone.swipe_ext('left',0.8) #direction left ,right ,up ,down ,percentage is float 0.01 to 0.999

3. 从指定的屏幕的点1 滑动到屏幕的点2
# point={'sx':0.529,'sy':0.700,'ex':0.559,'ey':0.273,'duration':0.3}
# phone.drag(point['sx'],point['sy'],point['ex'],point['ey'],point['duration'])
posted on 2020-08-10 21:42  ClareBaby01  阅读(4313)  评论(0编辑  收藏  举报