import datetime from appium import webdriver from time import sleep from appium.webdriver.common.touch_action import TouchAction desired_caps={ "platformName":"Android", #平台名字 "platformVersion":"7.1.2", #设备版本号 : adb shell getprop ro.build.version.release "deviceName":"127.0.0.1:62025", #设备名 : adb devices "appPackage":"com.mobivans.onestrokecharge", # app包名 "appActivity":"com.mobivans.onestrokecharge.activitys.MainActivity", # 主启动页 "udid":"127.0.0.1:62025", # 设备编号 "unicodeKeyboard":True, # 支持中文 "deviceReadyTimeout":20000 # 20s } class Yibijizhang: def __init__(self): self.awb=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps) sleep(0.5) #在一笔记账,账本页面滑动切换月份 # noinspection PyUnresolvedReferences def huadong(self): #向下滑动,y由小变大 self.awb.swipe(200, 00, 200, 700) #self.awb.swipe(start_x=200,start_y=200,end_x=200,end_y=700) sleep(1) self.awb.swipe(200, 200, 200, 700) sleep(1) self.awb.swipe(200, 200, 200, 700) sleep(1) self.awb.swipe(200, 200, 200, 700) # 在一笔记账,账本页面点击月份,选择切换年份和月份 #练习:账单页面点击月份打开日历 日历上对年份滑动操作 def yidong(self): self.awb.find_element("id",'com.mobivans.onestrokecharge:id/account_ll_datePick').click() #定位点击月份选择按钮 sleep(1) #定位日历表元素 el_rili=self.awb.find_element("xpath", "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.NumberPicker[1]") sleep(1) #滑动选择年份 TouchAction(self.awb).press(el_rili,20,20).wait(500).move_to(el_rili,20,100).release().perform() def demo(self,year,month): self.awb.find_element("id", 'com.mobivans.onestrokecharge:id/account_ll_datePick').click() # 定位点击月份选择按钮 sleep(1) # 定位日历表年份元素 el_rili = self.awb.find_element("xpath", "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.NumberPicker[1]") sleep(2) #操作选择年份 cur_year=datetime.date.today().year print(cur_year) if cur_year>year: ynum=cur_year-year for i in range(ynum): # 向下滑动选择年份 TouchAction(self.awb).press(el_rili, 20, 20).wait(500).move_to(el_rili, 20, 100).release().perform() elif cur_year<year: ynum=year-cur_year for i in range(ynum): # 向上滑动选择年份 TouchAction(self.awb).press(el_rili, 20, 100).wait(500).move_to(el_rili, 20, 20).release().perform() else: pass sleep(1) # 定位日历表月份元素 el_rili = self.awb.find_element("xpath", "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.NumberPicker[2]") sleep(1) #操作选择月份 cur_month = datetime.date.today().month print(cur_month) if cur_month > month: mnum = cur_month - month for i in range(mnum): # 向下滑动选择月份 TouchAction(self.awb).press(el_rili, 20, 20).wait(500).move_to(el_rili, 20, 100).release().perform() elif cur_month < month: mnum = month - cur_month for i in range(mnum): # 向上滑动选择月份 TouchAction(self.awb).press(el_rili, 20, 100).wait(500).move_to(el_rili, 20, 20).release().perform() else: pass #模拟手指点击报表按钮 def tap_demo(self): el_tap=self.awb.find_element("id","com.mobivans.onestrokecharge:id/mybtn_charts") TouchAction(self.awb).tap(el_tap).release().perform() #长按删除账单 def longpress(self,name,debit): #添加一笔支出账单 self.awb.find_element("id", "com.mobivans.onestrokecharge:id/main_write1").click() # 点击记一笔按钮 sleep(0.5) self.awb.find_element("xpath", f"//*[@text='{name}']").click() # 点击日常按钮 sleep(0.5) for i in debit: self.awb.find_element("xpath", f"//*[@text='{i}']").click() # 点击键盘按钮输入数字 sleep(0.5) self.awb.find_element("id", "com.mobivans.onestrokecharge:id/keyb_btn_finish").click() # 点击完成按钮 sleep(0.5) try: self.awb.find_element("id", "com.mobivans.onestrokecharge:id/guide_img_close").click() # 点击取消登录弹窗 except: pass sleep(1) #定位对应的帐单元素 el_zhangdan=self.awb.find_element("xpath","//*[@resource-id='com.mobivans.onestrokecharge:id/account_item_txt_remark']") #长按账单元素,然后释放执行 TouchAction(self.awb).long_press(el_zhangdan).release().perform() #点击删除确定按钮 self.awb.find_element("id","com.mobivans.onestrokecharge:id/alert_tv_ok").click() if __name__ == '__main__': jizhang=Yibijizhang() # jizhang.huadong() # jizhang.yidong() # jizhang.demo(year=2019,month=9) jizhang.tap_demo() # jizhang.longpress(name="日常",debit="100")
python之APP自动化测试, 页面滑动操作
最新推荐文章于 2024-07-27 12:20:46 发布