import datetime import xlrd from appium import webdriver from time import sleep from appium.webdriver.common.touch_action import TouchAction from xlrd import xldate_as_datetime 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.shark.jizhang", # app包名 "appActivity":"com.shark.jizhang.module.main.MainActivity", # 主启动页 "udid":"127.0.0.1:62025", # 设备编号 "unicodeKeyboard":True, # 支持中文 "deviceReadyTimeout":20000 # 20s } list_jizhang_zhichu=[] #读取Excel中的支出项 list_jizhang_shouru=[] #读取Excel中的收入项 #读取Excel中的数据项 class Jizhang: #读取Excel中的支出项 def zhichu(self): # 1.打开Excel文件,工作表 wb = xlrd.open_workbook(r'C:\Users\aoxiang.liu\Desktop\鲨鱼记账测试数据.xls') # 2.获取到sheet表 sheet = wb.sheet_by_name("支出") # sheet表名获取 # 3.读取sheet中全部的内容,共有多少行,多少列(用索引定位) for n in range(1, sheet.nrows): lst_zhichu=[] for r in range(0, sheet.ncols): # 表格的数据类型 # ctype: 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error ctype=sheet.cell(n, r).ctype cell=sheet.cell_value(n,r) #如果是字符串直接输出 if ctype==1: cell=cell #如果是数值类型直接输出 elif ctype==2: cell=int(cell) #如果是日期类型,转成datetime对象 elif ctype==3: cell=xldate_as_datetime(cell, 0).strftime('%Y/%m/%d') lst_zhichu.append(cell) list_jizhang_zhichu.append(lst_zhichu) print(f"支出项数据为:{list_jizhang_zhichu}") sleep(1) #读取Excel中的收入项 def shouru(self): # 1.打开Excel文件,工作表 wb = xlrd.open_workbook(r'C:\Users\aoxiang.liu\Desktop\鲨鱼记账测试数据.xls') # 2.获取到sheet表 sheet = wb.sheet_by_name("收入") # sheet表名获取 # 3.读取sheet中全部的内容,共有多少行,多少列(用索引定位) for n in range(1, sheet.nrows): lst_shouru=[] for r in range(0, sheet.ncols): # 表格的数据类型 # ctype: 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error ctype=sheet.cell(n, r).ctype cell=sheet.cell_value(n,r) #如果是字符串直接输出 if ctype==1: cell=cell #如果是数值类型直接输出 elif ctype==2: cell=int(cell) #如果是日期类型,转成datetime对象 elif ctype==3: cell=xldate_as_datetime(cell, 0).strftime('%Y/%m/%d') lst_shouru.append(cell) list_jizhang_shouru.append(lst_shouru) print(f"收入项数据为:{list_jizhang_shouru}") sleep(1) class Shark_jizhang(): #建立APP软件对象,用appium打开应用软件 def __init__(self): self.awb = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) sleep(1) # 用例1:记账模块系统默认的所有支出和收入项类别 # 标题:系统默认的所有支出和收入项类别符合需求数量 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:无 # 期望结果:系统默认的所有支出项(34个)和收入项(6个)类别符合需求数量 def general(self): print("记账模块支出项".center(60, "=")) # 输出记账模块中系统默认的所有支出类别项,包括设置按钮 self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) list_zhichutype1= set() # 定义空列表存放输出所有的支出类别项 zhichutype=self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") #定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 800, 300, 500) #在支出页面向下滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype=list(list_zhichutype1) print(f"系统默认的所有支出类别项为:{list_zhichutype}") # ==============================断言=================================== # 期望结果:系统默认显示的支出项数量符合34个需求 if len(list_zhichutype)==34: print("系统默认显示的支出项数量符合需求,测试通过") else: print("系统默认显示的支出项数量和需求不一致,测试不通过") sleep(1) self.awb.find_element("xpath","//*[@text='收入']").click() #点击收入按钮 sleep(1) print("记账模块收入项".center(60,"=")) #======================================================================================= # 输出记账模块中系统默认的所有收入类别项,包括设置按钮 list_shourutype = [] #定义空列表存放输出所有的收入类别项 shourutype=self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") #定位收入项位置元素 for i in range(len(shourutype)): list_shourutype.append(shourutype[i].text) # 循环输出收入类别项 print(f"系统默认的所有收入类别项为:{list_shourutype}") sleep(2) # ==============================断言=================================== # 期望结果:系统默认显示的收入项数量符合6个需求 if len(list_shourutype) == 6: print("系统默认显示的收入项数量符合需求,测试通过") else: print("系统默认显示的收入项数量和需求不一致,测试不通过") sleep(1) # 用例2:记一笔支出项 # 标题:支出项记账成功 # 前置条件:打开登录鲨鱼页面 # 测试数据:鲨鱼记账测试数据.xls # 期望结果:记账成功后,跳转账本页面,显示的支出记账记录与填写的信息一致 def zhichu_one(self): print("记一笔支出项".center(60, "=")) self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", f"//*[@text='{list_jizhang_zhichu[0][0]}']").click() # 点击餐饮按钮 sleep(1) try: self.awb.find_element("xpath","//*[@text='知道了']").click() #点击知道了 except: pass sleep(1) for i in str(list_jizhang_zhichu[0][1]): self.awb.find_element("xpath", f"//*[@text='{i}']").click() # 点击键盘按钮输入数字 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/date").click() # 点击键盘今天按钮 sleep(1) # ================================================================================================== # 定位日历表年份元素 cur_year = datetime.date.today().year el_rili =self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[1]") # 定位年份选中框的元素 if cur_year>int(list_jizhang_zhichu[0][2].split('/')[0]): num=cur_year-int(list_jizhang_zhichu[0][2].split('/')[0]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_year<int(list_jizhang_zhichu[0][2].split('/')[0]): num =int(list_jizhang_zhichu[0][2].split('/')[0])-cur_year for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表月份元素 cur_month = datetime.date.today().month el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[2]") # 定位月份选中框的元素 if cur_month > int(list_jizhang_zhichu[0][2].split('/')[1]): num = cur_month - int(list_jizhang_zhichu[0][2].split('/')[1]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_month < int(list_jizhang_zhichu[0][2].split('/')[1]): num = int(list_jizhang_zhichu[0][2].split('/')[1]) - cur_month for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表日份元素 cur_day = datetime.date.today().day el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[3]") # 定位日份选中框的元素 if cur_day> int(list_jizhang_zhichu[0][2].split('/')[2]): num = cur_day - int(list_jizhang_zhichu[0][2].split('/')[2]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_day < int(list_jizhang_zhichu[0][2].split('/')[2]): num = int(list_jizhang_zhichu[0][2].split('/')[2]) - cur_day for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass self.awb.find_element("id", "com.shark.jizhang:id/dialog_dashboard_date_accept").click() # 点击日历窗中的确定按钮 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass sleep(1) list_zcmx=[] #存放取出来的支出明细的详细 # 定位明细页面上的支出账单项目名 zcname = self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.TextView").text sleep(1) print(zcname) list_zcmx.append(zcname) # 定位明细页面上的支出账单金额 zcmoney = self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.TextView").text sleep(1) print(-int(zcmoney)) list_zcmx.append(-int(zcmoney)) # 定位明细页面上的账单时间 zcyear = self.awb.find_element("id", "com.shark.jizhang:id/dataSelectorYear").text # 获取年份 sleep(1) print(zcyear) # 获取月份和日份 zcmonth = self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.TextView").text sleep(1) print(zcmonth) zctime=zcyear[:-1] + "/" + zcmonth.split(" ")[0].replace("月", "/")[:-1] print(zctime) list_zcmx.append(zctime) print(list_zcmx) # ==============================断言=================================== # 期望结果:记一笔支出记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 print(f"明细页面显示实际账单记录:{list_zcmx}") print(f"明细页面显示预期账单记录:{list_jizhang_zhichu[0]}") if list_jizhang_zhichu[0] == list_zcmx: print("记一笔支出记账成功后,显示的记账记录与填写的信息一致,测试通过") else: print("记一笔支出记账成功后,显示的记账记录与填写的信息不一致,测试不通过") sleep(1) # 用例3:连续记多笔支出项 # 标题:多笔支出项记账成功 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:鲨鱼记账测试数据.xls # 期望结果:记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 def zhichu_many(self): print("记多笔支出项".center(60, "=")) #循环录入列表中的支出项 for jz_zhichu in list_jizhang_zhichu: self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", f"//*[@text='{jz_zhichu[0]}']").click() # 点击餐饮按钮 sleep(1) try: self.awb.find_element("xpath", "//*[@text='知道了']").click() # 点击知道了 except: pass sleep(1) for i in str(jz_zhichu[1]): self.awb.find_element("xpath", f"//*[@text='{i}']").click() # 点击键盘按钮输入数字 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/date").click() # 点击键盘今天按钮 sleep(1) # ================================================================================================== # 定位日历表年份元素 cur_year = datetime.date.today().year el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[1]") # 定位年份选中框的元素 if cur_year > int(jz_zhichu[2].split('/')[0]): num = cur_year - int(jz_zhichu[2].split('/')[0]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_year < int(jz_zhichu[2].split('/')[0]): num = int(jz_zhichu[2].split('/')[0]) - cur_year for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表月份元素 cur_month = datetime.date.today().month el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[2]") # 定位月份选中框的元素 if cur_month > int(jz_zhichu[2].split('/')[1]): num = cur_month - int(jz_zhichu[2].split('/')[1]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_month < int(jz_zhichu[2].split('/')[1]): num = int(jz_zhichu[2].split('/')[1]) - cur_month for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表日份元素 cur_day = datetime.date.today().day el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[3]") # 定位日份选中框的元素 if cur_day > int(jz_zhichu[2].split('/')[2]): num = cur_day - int(jz_zhichu[2].split('/')[2]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_day < int(jz_zhichu[2].split('/')[2]): num = int(jz_zhichu[2].split('/')[2]) - cur_day for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass self.awb.find_element("id", "com.shark.jizhang:id/dialog_dashboard_date_accept").click() # 点击日历窗中的确定按钮 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass sleep(1) #定位明细页面上的支出账单项目名 list_zcname=[] zcname=self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/itemText']") sleep(1) for name in zcname: list_zcname.append(name.text) print(list_zcname) # 定位明细页面上的支出账单金额 list_zcmoney=[] zcmoney=self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/account']") sleep(1) for money in zcmoney: list_zcmoney.append(-int(money.text)) print(list_zcmoney) list_many=[] # 存在循环取出来的支出明细的详细 for i in range(len(list_zcname)): list_many.append([list_zcname[i],list_zcmoney[i]]) list_many.reverse() print(list_many) list_zhichu_many =[] # 存从Excel中循环取出来的支出明细的名称和金额 for j in range(len(list_jizhang_zhichu)): list_zhichu_many.append([list_jizhang_zhichu[j][0],list_jizhang_zhichu[j][1]]) print(list_zhichu_many) # ==============================断言=================================== # 期望结果:连续多笔支出记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 print(f"明细页面显示实际账单记录:{list_many}") print(f"明细页面显示预期账单记录:{list_zhichu_many}") if list_zhichu_many==list_many: print("连续多笔支出记账成功后,显示的记账记录与填写的信息一致,测试通过") else: print("连续多笔支出记账成功后,显示的记账记录与填写的信息不一致,测试不通过") sleep(1) # 用例4:记账页面每个支出项是否可以正常点击记账 # 标题:记账页面每个支出项可以正常点击记账 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:支出金额全部设定50,日期全部设置为默认 # 期望结果:支出页面每个支出项可以正常点击记账 def zhichu_all(self): print("用例4:每个支出项均可记账".center(60, "=")) # 输出记账模块中系统默认的所有支出类别项,包括设置按钮 self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) list_zhichutype1 = set() # 定义空列表存放输出所有的支出类别项 zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype = list(list_zhichutype1) list_zhichutype.remove("设置") print(f"系统默认的所有支出类别项为:{list_zhichutype}") self.awb.find_element("id","com.shark.jizhang:id/cancelBtn").click() #点击取消按钮 sleep(1) j=1 for i in range(0,(len(list_zhichutype))): self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) try: self.awb.find_element("xpath", f"//*[@text='{list_zhichutype[i]}']").click() # 点击类别文本按钮 except: if list_zhichutype[i]=="快递": self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 self.awb.find_element("xpath", f"//*[@text='{list_zhichutype[i]}']").click() # 点击类别文本按钮 sleep(1) try: self.awb.find_element("xpath", "//*[@text='知道了']").click() # 点击知道了 except: pass sleep(1) for n in str(j): if n=="0": self.awb.find_element("id","com.shark.jizhang:id/zero").click() # 点击键盘按钮输入金额数字0 elif n=="1": self.awb.find_element("id","com.shark.jizhang:id/one").click() # 点击键盘按钮输入金额数字1 elif n=="2": self.awb.find_element("id","com.shark.jizhang:id/two").click() # 点击键盘按钮输入金额数字2 elif n=="3": self.awb.find_element("id","com.shark.jizhang:id/third").click() # 点击键盘按钮输入金额数字3 elif n=="4": self.awb.find_element("id","com.shark.jizhang:id/four").click() # 点击键盘按钮输入金额数字4 elif n=="5": self.awb.find_element("id","com.shark.jizhang:id/five").click() # 点击键盘按钮输入金额数字5 elif n=="6": self.awb.find_element("id","com.shark.jizhang:id/six").click() # 点击键盘按钮输入金额数字6 elif n=="7": self.awb.find_element("id","com.shark.jizhang:id/seven").click() # 点击键盘按钮输入金额数字7 elif n=="8": self.awb.find_element("id","com.shark.jizhang:id/eight").click() # 点击键盘按钮输入金额数字8 elif n=="9": self.awb.find_element("id","com.shark.jizhang:id/nine").click() # 点击键盘按钮输入金额数字9 elif n==".": self.awb.find_element("id","com.shark.jizhang:id/point").click() # 点击键盘按钮输入金额数字. else: pass sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass sleep(1) j=j+1 #==============================断言===================================== #预期结果:支出页面每个支出项可以正常点击记账 list_zcname=set() #将滑动取出来的页面支出名字都存在集合中,会自动去重,得到录入的全部支出项名称 list_zcmoney=set() #将滑动取出来的页面支出金额都存在集合中,会自动去重,得到录入的全部支出项金额 while True: # 定位明细页面上的支出账单项目名 存放进定义的集合中 zcname=self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/itemText']") sleep(1) for name in zcname: list_zcname.add(name.text) sleep(1) # 定位明细页面上的支出账单金额 存放进定义的集合中 zcmoney=self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/account']") sleep(1) for money in zcmoney: list_zcmoney.add(-int(money.text)) sleep(1) self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(0.5) if 1 in list_zcmoney: #往上滑动页面,直到第一次录入的支出项金额出现为止,终止滑动 break else: pass list_zcn=list(list_zcname) #将名称集合转变为列表 print(f"明细页面的所有支出项目名称:{list_zcn}") list_zcm=list(list_zcmoney) #将金额集合转变为列表 print(f"明细页面的所有支出项目金额:{list_zcm}") if len(list_zcn)==len(list_zhichutype) and len(list_zcm)==len(list_zhichutype): print("支出页面每个支出项可以正常点击记账,测试通过") else: print("支出页面每个支出项不可以正常点击记账,测试不通过") sleep(1) # 用例5:记账支出页面设置是否可以删除默认支出项 # 标题:记账支出页面设置可以删除默认支出项 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:删除某一支出项 # 期望结果:记账支出页面设置可以删除默认支出项 def zhichu_set_del(self): print("支出页面设置删除项".center(60, "=")) self.awb.find_element('id', 'com.shark.jizhang:id/settingTab').click() # 点击我的按钮 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/loginAvatar').click() # 点击登录头像 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/moreLogin').click() # 点击更多登录方式 sleep(1) # 点击手机登录 self.awb.find_element('id', 'com.shark.jizhang:id/phoneLogin').click() # 输入手机号 self.awb.find_element('xpath', '//*[@text="请输入手机号"]').send_keys("13697347601") # 输入密码 self.awb.find_element('xpath', '//*[@text="请输入密码"]').send_keys("123456") sleep(3) # 点击登录按钮 self.awb.find_element('id', 'com.shark.jizhang:id/login').click() sleep(1) print("你已经登录成功,请继续操作") # 输出记账模块中系统默认的所有支出类别项,移除设置按钮 self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) list_zhichutype1 = set() # 定义空列表存放输出所有的支出类别项 zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype = list(list_zhichutype1) list_zhichutype.remove("设置") print(f"系统默认的所有支出类别项为:{list_zhichutype}") sleep(1) try: self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) except: self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(2) self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) # 点击删除类别 try: self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]").click() self.awb.find_element("xpath", "//*[@text='是']").click() except: self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]").click() sleep(1) self.awb.find_element("xpath", "//android.widget.ImageButton[@content-desc='转到上一层级']").click() # 点击返回按钮 sleep(1) # 输出删除后记账模块中系统默认的所有支出类别项,移除设置按钮 list_zhichutype2= set() # 定义空列表存放输出所有的支出类别项 zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype2.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 500, 300, 800) # 在支出页面向下滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype2.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype1=list(list_zhichutype2) list_zhichutype1.remove("设置") print(f"删除后系统默认的所有支出类别项为:{list_zhichutype1}") sleep(1) # ==============================断言===================================== # 预期结果:记账支出页面设置可以删除默认收入项 if len(list_zhichutype1) == len(list_zhichutype) - 1: print("记账支出页面设置可以删除默认收入项,测试通过") else: print("记账支出页面设置不可以删除默认收入项,测试不通过") sleep(1) # 用例6:记账支出页面设置是否可以自定义添加支出项 # 标题:记账支出页面设置可以自定义添加支出项 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:麻将/选择娱乐图标 # 期望结果:记账支出页面设置可以自定义添加支出项 def zhichu_set_add(self): print("支出页面设置添加自定义项".center(60, "=")) self.awb.find_element('id', 'com.shark.jizhang:id/settingTab').click() # 点击我的按钮 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/loginAvatar').click() # 点击登录头像 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/moreLogin').click() # 点击更多登录方式 sleep(1) # 点击手机登录 self.awb.find_element('id', 'com.shark.jizhang:id/phoneLogin').click() # 输入手机号 self.awb.find_element('xpath', '//*[@text="请输入手机号"]').send_keys("13697347601") # 输入密码 self.awb.find_element('xpath', '//*[@text="请输入密码"]').send_keys("123456") sleep(3) # 点击登录按钮 self.awb.find_element('id', 'com.shark.jizhang:id/login').click() sleep(1) print("你已经登录成功,请继续操作") # 输出记账模块中系统默认的所有支出类别项,移除设置按钮 self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) list_zhichutype1 = set() # 定义空列表存放输出所有的支出类别项 zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype1.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype = list(list_zhichutype1) list_zhichutype.remove("设置") print(f"系统默认的所有支出类别项为:{list_zhichutype}") sleep(1) try: self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) except: self.awb.swipe(300, 800, 300, 500) # 在支出页面向上滑动页面 sleep(2) self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) self.awb.find_element("id","com.shark.jizhang:id/addText").click() #点击添加类别按钮 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/categoryNameEdit").send_keys("麻将") sleep(1) #点击选择图标 self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.GridView/android.widget.LinearLayout[1]/android.widget.ImageView").click() # while True: # try: # self.awb.find_element("xpath", "//*[@text='收入']") # break # except: # self.awb.swipe(300, 800, 300, 300) # 向上滑动页面 # sleep(2) self.awb.find_element("id", "com.shark.jizhang:id/rightTitleBtn").click() # 点击完成按钮 sleep(1) self.awb.find_element("xpath", "//android.widget.ImageButton[@content-desc='转到上一层级']").click() # 点击返回按钮 sleep(1) # 输出添加后记账模块中系统默认的所有支出类别项,移除设置按钮 list_zhichutype2 = set() # 定义空列表存放输出所有的支出类别项 zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype2.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) self.awb.swipe(300, 500, 300, 800) # 在支出页面向下滑动页面 sleep(2) zhichutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位支出项位置元素 for i in range(len(zhichutype)): list_zhichutype2.add(zhichutype[i].text) # 循环输出支出类别项 sleep(2) list_zhichutype1 = list(list_zhichutype2) list_zhichutype1.remove("设置") print(f"添加后系统默认的所有支出类别项为:{list_zhichutype1}") sleep(1) # ==============================断言===================================== # 预期结果:记账支出页面设置可以添加自定义收入项 if len(list_zhichutype1) == len(list_zhichutype) + 1: print("记账支出页面设置可以添加自定义收入项,测试通过") else: print("记账支出页面设置不可以添加自定义收入项,测试不通过") sleep(1) # 用例7:记一笔收入项 # 标题:收入项记账成功 # 前置条件:打开登录鲨鱼页面 # 测试数据:鲨鱼记账测试数据.xls # 期望结果:记账成功后,跳转账本页面,显示的收入记账记录与填写的信息一致 def shouru_one(self): print("记一笔收入项".center(60, "=")) self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", "//*[@text='收入']").click() # 点击收入按钮 sleep(1) self.awb.find_element("xpath", f"//*[@text='{list_jizhang_shouru[0][0]}']").click() # 点击类别按钮 sleep(1) try: self.awb.find_element("xpath", "//*[@text='知道了']").click() # 点击知道了 except: pass for i in str(list_jizhang_shouru[0][1]): self.awb.find_element("xpath", f"//*[@text='{i}']").click() # 点击键盘按钮输入数字 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/date").click() # 点击键盘今天按钮 sleep(1) # ================================================================================================== # 定位日历表年份元素 cur_year = datetime.date.today().year el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[1]") # 定位年份选中框的元素 if cur_year > int(list_jizhang_shouru[0][2].split('/')[0]): num = cur_year - int(list_jizhang_shouru[0][2].split('/')[0]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_year < int(list_jizhang_shouru[0][2].split('/')[0]): num = int(list_jizhang_shouru[0][2].split('/')[0]) - cur_year for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表月份元素 cur_month = datetime.date.today().month el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[2]") # 定位月份选中框的元素 if cur_month > int(list_jizhang_shouru[0][2].split('/')[1]): num = cur_month - int(list_jizhang_shouru[0][2].split('/')[1]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_month < int(list_jizhang_shouru[0][2].split('/')[1]): num = int(list_jizhang_shouru[0][2].split('/')[1]) - cur_month for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass # ================================================================================================== # 定位日历表日份元素 cur_day = datetime.date.today().day el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[3]") # 定位日份选中框的元素 if cur_day > int(list_jizhang_shouru[0][2].split('/')[2]): num = cur_day - int(list_jizhang_shouru[0][2].split('/')[2]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_day < int(list_jizhang_shouru[0][2].split('/')[2]): num = int(list_jizhang_shouru[0][2].split('/')[2]) - cur_day for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass self.awb.find_element("id", "com.shark.jizhang:id/dialog_dashboard_date_accept").click() # 点击日历窗中的确定按钮 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass list_srmx=[] #存在取出来的支出明细的详细 # 定位明细页面上的收入账单项名 srname = self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.TextView").text sleep(1) print(srname) list_srmx.append(srname) # 定位明细页面上的支出账单金额 srmoney = self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.TextView").text sleep(1) print(srmoney) list_srmx.append(int(srmoney)) # 定位明细页面上的账单时间 sryear = self.awb.find_element("id", "com.shark.jizhang:id/dataSelectorYear").text # 获取年份 sleep(1) # 获取月份和日份 srmonth=self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.TextView").text sleep(1) srtime=sryear[:-1] + "/" + srmonth.split(" ")[0].replace("月", "/")[:-1] print(srtime) list_srmx.append(srtime) print(list_srmx) # ==============================断言=================================== # 期望结果:连续多笔支出记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 print(f"明细页面显示实际账单记录:{list_srmx}") print(f"明细页面显示预期账单记录:{list_jizhang_shouru[0]}") if list_jizhang_shouru[0]==list_srmx: print("记一笔收入记账成功后,显示的记账记录与填写的信息一致,测试通过") else: print("记一笔收入记账成功后,显示的记账记录与填写的信息不一致,测试不通过") sleep(1) # 用例8:连续记多笔收入项 # 标题:多笔收入项记账成功 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:鲨鱼记账测试数据.xls # 期望结果:记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 def shouru_many(self): print("记多笔收入项".center(60, "=")) # 循环录入列表中的收入项 for jz_shouru in list_jizhang_shouru: self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath","//*[@text='收入']").click() #点击收入按钮 sleep(1) self.awb.find_element("xpath", f"//*[@text='{jz_shouru[0]}']").click() # 点击类别按钮 sleep(1) try: self.awb.find_element("xpath", "//*[@text='知道了']").click() # 点击知道了 except: pass for i in str(jz_shouru[1]): self.awb.find_element("xpath", f"//*[@text='{i}']").click() # 点击键盘按钮输入数字 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/date").click() # 点击键盘今天按钮 sleep(1) # ================================================================================================== # 定位日历表年份元素 cur_year = datetime.date.today().year el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[1]") # 定位年份选中框的元素 if cur_year > int(jz_shouru[2].split('/')[0]): num = cur_year - int(jz_shouru[2].split('/')[0]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_year < int(jz_shouru[2].split('/')[0]): num = int(jz_shouru[2].split('/')[0]) - cur_year for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass sleep(1) # ================================================================================================== # 定位日历表月份元素 cur_month = datetime.date.today().month el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[2]") # 定位月份选中框的元素 if cur_month > int(jz_shouru[2].split('/')[1]): num = cur_month - int(jz_shouru[2].split('/')[1]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_month < int(jz_shouru[2].split('/')[1]): num = int(jz_shouru[2].split('/')[1]) - cur_month for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass sleep(1) # ================================================================================================== # 定位日历表日份元素 cur_day = datetime.date.today().day el_rili = self.awb.find_element("xpath","//*[@resource-id='android:id/pickers']/android.widget.NumberPicker[3]") # 定位日份选中框的元素 if cur_day > int(jz_shouru[2].split('/')[2]): num = cur_day - int(jz_shouru[2].split('/')[2]) for i in range(num): TouchAction(self.awb).press(el_rili, 50, 50).wait(500).move_to(el_rili, 50,120).release().perform() # 滑动日历表年份条 sleep(1) elif cur_day < int(jz_shouru[2].split('/')[2]): num = int(jz_shouru[2].split('/')[2]) - cur_day for i in range(num): TouchAction(self.awb).press(el_rili, 50, 120).wait(500).move_to(el_rili, 50,50).release().perform() # 滑动日历表年份条 sleep(1) else: pass sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/dialog_dashboard_date_accept").click() # 点击日历窗中的确定按钮 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass sleep(1) # 定位明细页面上的收入账单项目名 list_name = [] srname=self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/itemText']") sleep(1) for name in srname: list_name.append(name.text) print(list_name) # 定位明细页面上的收入账单金额 list_money = [] srmoney=self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/account']") for money in srmoney: list_money.append(money.text) print(list_money) list_many = [] # 存在循环取出来的收入明细的详细 for i in range(len(list_name)): list_many.append([list_name[i],int(list_money[i])]) list_many.reverse() print(list_many) list_shouru_many= [] # 存在Excel循环取出来的收入明细的名称和金额 for j in range(len(list_jizhang_shouru)): list_shouru_many.append([list_jizhang_shouru[j][0],list_jizhang_shouru[j][1]]) print(list_shouru_many) # ==============================断言=================================== # 期望结果:连续多笔收入记账成功后,跳转明细页面,显示的记账记录与填写的信息一致 print(f"明细页面显示实际账单记录:{list_many}") print(f"明细页面显示预期账单记录:{list_shouru_many}") if list_jizhang_shouru == list_many: print("连续多笔收入记账成功后,显示的记账记录与填写的信息一致,测试通过") else: print("连续多笔收入记账成功后,显示的记账记录与填写的信息不一致,测试不通过") sleep(1) # 用例9:记账页面每个收入项是否可以正常点击记账 # 标题:记账页面每个收入项可以正常点击记账 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:收入金额全部设定50,日期全部设置为默认 # 期望结果:收入页面每个收入项可以正常点击记账 def shouru_all(self): print("每个收入项均可记账".center(60, "=")) self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", "//*[@text='收入']").click() # 点击收入按钮 sleep(1) # 输出记账模块中系统默认的所有收入类别项,去除设置按钮 list_shourutype = [] # 定义空列表存放输出所有的收入类别项 shourutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位收入项位置元素 for i in range(len(shourutype)): list_shourutype.append(shourutype[i].text) # 循环输出收入类别项 sleep(2) list_shourutype.remove("设置") #删除设置按钮 print(f"系统默认所有收入类别项为:{list_shourutype}") self.awb.find_element("id", "com.shark.jizhang:id/cancelBtn").click() # 点击取消按钮 sleep(1) for i in range(len(list_shourutype)): self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", "//*[@text='收入']").click() # 点击收入按钮 sleep(1) self.awb.find_element("xpath", f"//*[@text='{list_jizhang_shouru[i][0]}']").click() # 点击类别文本按钮 sleep(1) try: self.awb.find_element("xpath", "//*[@text='知道了']").click() # 点击知道了 except: pass self.awb.find_element("xpath", f"//*[@text='5']").click() # 点击键盘按钮输入数字5 self.awb.find_element("xpath", f"//*[@text='0']").click() # 点击键盘按钮输入数字0 sleep(1) self.awb.find_element("id", "com.shark.jizhang:id/done").click() # 点击完成按钮 sleep(1) try: self.awb.find_element('xpath', '//*[@text="不喜欢"]').click() # 处理弹框,点击不喜欢 except: pass sleep(1) # ==============================断言===================================== # 预期结果:收入页面每个收入项可以正常点击记账 # 定位明细页面上的收入账单项目名 srname=self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/itemText']") sleep(1) # 定位明细页面上的收入账单金额 srmoney = self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/account']") sleep(1) if len(srname) == len(list_shourutype) and len(srmoney) == len(list_shourutype): print("收入页面每个收入项可以正常点击记账,测试通过") else: print("收入页面每个收入项不可以正常点击记账,测试不通过") sleep(1) # 用例10:记账收入页面设置是否可以删除默认收入项 # 标题:记账收入页面设置可以删除默认收入项 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:删除工资收入项 # 期望结果:记账收入页面设置可以删除默认收入项 def shouru_set_del(self): print("收入页面设置删除项".center(60, "=")) self.awb.find_element('id', 'com.shark.jizhang:id/settingTab').click() # 点击我的按钮 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/loginAvatar').click() # 点击登录头像 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/moreLogin').click() # 点击更多登录方式 sleep(1) # 点击手机登录 self.awb.find_element('id', 'com.shark.jizhang:id/phoneLogin').click() # 输入手机号 self.awb.find_element('xpath', '//*[@text="请输入手机号"]').send_keys("13697347601") # 输入密码 self.awb.find_element('xpath', '//*[@text="请输入密码"]').send_keys("123456") sleep(3) # 点击登录按钮 self.awb.find_element('id', 'com.shark.jizhang:id/login').click() sleep(1) print("你已经登录成功,请继续操作") self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", "//*[@text='收入']").click() # 点击收入按钮 sleep(1) # 输出记账模块中系统默认的所有收入类别项,去除设置按钮 list_shourutype = [] # 定义空列表存放输出所有的收入类别项 shourutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位收入项位置元素 for i in range(len(shourutype)): list_shourutype.append(shourutype[i].text) # 循环输出收入类别项 sleep(2) list_shourutype.remove("设置") # 删除设置按钮 print(f"系统默认所有收入类别项为:{list_shourutype}") sleep(1) self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) #点击删除类别 try: self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]").click() self.awb.find_element("xpath", "//*[@text='是']").click() except: self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView[1]").click() sleep(1) self.awb.find_element("xpath","//android.widget.ImageButton[@content-desc='转到上一层级']").click() #点击返回按钮 sleep(1) # 输出操作删除后记账模块中系统默认的所有收入类别项,去除设置按钮 list_shourutype1= [] # 定义空列表存放输出所有的收入类别项 shourutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位收入项位置元素 sleep(1) for i in range(len(shourutype)): list_shourutype1.append(shourutype[i].text) # 循环输出收入类别项 sleep(2) list_shourutype1.remove("设置") # 删除设置按钮 print(f"删除后系统默认所有收入类别项为:{list_shourutype1}") # ==============================断言===================================== # 预期结果:记账收入页面设置可以删除默认收入项 if len(list_shourutype1)==len(list_shourutype)-1: print("记账收入页面设置可以删除默认收入项,测试通过") else: print("记账收入页面设置不可以删除默认收入项,测试不通过") sleep(1) # 用例11:记账收入页面设置是否可以自定义添加收入项 # 标题:记账收入页面设置可以自定义添加收入项 # 前置条件:打开登录鲨鱼记账页面 # 测试数据:课酬/选择收入图标 # 期望结果:记账收入页面设置可以自定义添加收入项 def shouru_set_add(self): print("收入页面设置添加自定义项".center(60, "=")) self.awb.find_element('id', 'com.shark.jizhang:id/settingTab').click() # 点击我的按钮 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/loginAvatar').click() # 点击登录头像 sleep(1) self.awb.find_element('id', 'com.shark.jizhang:id/moreLogin').click() # 点击更多登录方式 sleep(1) # 点击手机登录 self.awb.find_element('id', 'com.shark.jizhang:id/phoneLogin').click() # 输入手机号 self.awb.find_element('xpath', '//*[@text="请输入手机号"]').send_keys("13697347601") # 输入密码 self.awb.find_element('xpath', '//*[@text="请输入密码"]').send_keys("123456") sleep(3) # 点击登录按钮 self.awb.find_element('id', 'com.shark.jizhang:id/login').click() sleep(1) print("你已经登录成功,请继续操作") self.awb.find_element("id", "com.shark.jizhang:id/addTabFloat").click() # 点击记账按钮 sleep(1) self.awb.find_element("xpath", "//*[@text='收入']").click() # 点击收入按钮 sleep(1) # 输出记账模块中系统默认的所有收入类别项,去除设置按钮 list_shourutype = [] # 定义空列表存放输出所有的收入类别项 shourutype = self.awb.find_elements("xpath", "//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位收入项位置元素 for i in range(len(shourutype)): list_shourutype.append(shourutype[i].text) # 循环输出收入类别项 sleep(2) list_shourutype.remove("设置") # 删除设置按钮 print(f"系统默认所有收入类别项为:{list_shourutype}") sleep(1) self.awb.find_element("xpath", "//*[@text='设置']").click() # 点击设置按钮 sleep(1) self.awb.find_element("id","com.shark.jizhang:id/addText").click() #点击添加类别 sleep(1) self.awb.find_element("id","com.shark.jizhang:id/categoryNameEdit").send_keys("课酬") sleep(2) #点击图标 self.awb.find_element("xpath","/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.GridView/android.widget.LinearLayout[1]/android.widget.ImageView").click() sleep(1) # while True: # try: # self.awb.find_element("xpath","//*[@text='收入']") # break # except: # self.awb.swipe(300,800,300,300) #向上滑动页面 # sleep(2) self.awb.find_element("id","com.shark.jizhang:id/rightTitleBtn").click() #点击完成按钮 sleep(1) self.awb.find_element("xpath", "//android.widget.ImageButton[@content-desc='转到上一层级']").click() # 点击返回按钮 sleep(1) # 输出操作添加后记账模块中系统默认的所有收入类别项,去除设置按钮 list_shourutype1 = [] # 定义空列表存放输出所有的收入类别项 shourutype = self.awb.find_elements("xpath","//*[@resource-id='com.shark.jizhang:id/categoryGridListView']/android.widget.LinearLayout/android.widget.TextView") # 定位收入项位置元素 sleep(1) for i in range(len(shourutype)): list_shourutype1.append(shourutype[i].text) # 循环输出收入类别项 sleep(2) list_shourutype1.remove("设置") # 删除设置按钮 print(f"添加后系统默认所有收入类别项为:{list_shourutype1}") # ==============================断言===================================== # 预期结果:记账收入页面设置可以添加自定义收入项 if len(list_shourutype1) == len(list_shourutype)+1: print("记账收入页面设置可以添加自定义收入项,测试通过") else: print("记账收入页面设置不可以添加自定义收入项,测试不通过") sleep(1) if __name__ == '__main__': jizhang = Jizhang() jizhang.zhichu() #正常跑通 jizhang.shouru() #正常跑通 shark=Shark_jizhang() # shark.general() #正常跑通 # shark.zhichu_one() #正常跑通 # shark.zhichu_many() #正常跑通 shark.zhichu_all() #正常跑通 # shark.zhichu_set_del() #正常跑通 # shark.zhichu_set_add() #正常跑通 # # shark.shouru_one() #正常跑通 # shark.shouru_many() #正常跑通 # shark.shouru_all() #正常跑通 # shark.shouru_set_del() #正常跑通 # shark.shouru_set_add() #正常跑通
python之APP自动化测试脚本实操-----鲨鱼记账
最新推荐文章于 2024-06-24 21:04:29 发布