def __init__(self): '''初始化设备''' self.device = connect_device(self.main_phone) auto_setup(__file__, logdir=False, devices=self.main_phone) self.poco = UnityPoco() self.setting() self.start_app()
def head(): start() poco = UnityPoco() poco("btn_setting").click() print("点击设置") if poco("btn_head").exists(): poco("btn_head").click() print("头像") else: print("没有头像") for i in range(35, 37): print(i) if i >= 21: print("up") x, y = poco(texture="team_20").get_position() dir = [0, -0.5] poco.swipe([x, y], direction=dir) poco("Batch_bg").child("img_head_bg")[i].click() if i < 36: poco("btn_head").click() print("切换%s号头像test成功" % i) else: print(i) poco("Batch_bg").child("img_head_bg")[i].click() poco("btn_head").click() print("切换%s号头像test成功" % i) print("测试完成") return poco("img_icon")
def test_city_diqu_day_share(self): '分享测试' poco = UnityPoco() if poco("text").get_text() == '分享再领一次': poco("btn_identify").click() poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) if poco("android.widget.LinearLayout").offspring( "com.tencent.mm:id/jx").exists(): print('分享跳转微信正常--测试通过') poco("com.tencent.mm:id/kb").click() poco("android:id/content").offspring( "com.tencent.mm:id/az_").click() poco = UnityPoco() poco("btn_identify").click() poco("img_close").click() elif poco("android:id/text1").get_text() == '登录微信': print('分享跳转微信正常--测试通过') poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) poco("com.tencent.mm:id/kb").click() poco = UnityPoco() poco("text").click() poco("img_close").click() else: print('分享跳转微信不正常--测试不通过') assert (poco("android:id/text1").get_text() == '登录微信') else: print('弹出分享失败--测试不通过') assert (poco("img_green_side"))
def setUp(self): stop_app("com.gameholic.drawsomethingbyspider") clear_app("com.gameholic.drawsomethingbyspider") wake() home() start_app("com.gameholic.drawsomethingbyspider") sleep(7) self.poco = UnityPoco() print("make level test start")
def check_app(self): '''检查app''' list_app = self.device.list_app() if self.main_package not in list_app: print('安装包体中') self.device.install_app(self.package_path, self.main_package) start_app(self.main_package) time.sleep(10) self.poco = UnityPoco() else: print('包体已安装') start_app(self.main_package) time.sleep(10) self.poco = UnityPoco()
def test_1assert(self): try: # os.system(r"start D:\yeshen\Nox\bin\Nox_1") # 启动夜神模拟器 os.system(r"start C:\Users\Admin\Desktop\start_2.bat") time.sleep(5) except: print("夜神模拟器已启动") devs = connect_device( "Android://127.0.0.1:5037/127.0.0.1:62025?cap_method=JAVACAP&&ori_method=ADBORI&&touch_method=ADBTOUCH" ) # 连接夜神模拟器 time.sleep(10) start_app( 'com.kaixinyule.kaixingame', activity=None ) # 启动待测app # 获取包名 aapt dump badging test.apk 查看端口 netstat -ano time.sleep(15) from poco.drivers.unity3d import UnityPoco # 导入并初始化U3d poco = UnityPoco() # 测试当前页面微信登录UI控件是否存在 invisible_obj = poco('_Button_WeixinLogon', type='Button') Pr.print(invisible_obj.exists()) if invisible_obj.exists() == True: Pr.print("*******************", "成功启动模拟器,APP") else: Pr.print("*******************", "启动模拟器失败,APP")
def setUp(self): self.poco = UnityPoco() print("Checking for change...") AvatarHead = Template(self.R('res/img/default-avatar.jpg'), rgb=True, threshold=0.9) AvatarMenu = Template(self.R('res/img/default.jpg'), rgb=True, threshold=0.9) if not exists(AvatarMenu) or not exists(AvatarHead): try: self.poco("ColorToggle").click() except InvalidOperationException: nav_bar = self.poco("SalonNavbarMobile(Clone)") print("Scrolling nav bar...") nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8])) nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8])) nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8])) self.poco("ColorToggle").click() finally: self.poco("SkinToggle").click() self.colorToggleScrollUp() self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[ 2].child("Background").click() self.poco("HairToggle").click() self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[ 5].child("Background").click()
def poco(request): """相当于setup""" get_logger("airtest").setLevel(SD.AIRTEST_LOG_LEVEL) _log_name = __name__.split('.')[0] init_logging(name=_log_name, level=SD.TESTCASE_LOG_LEVEL) plat = SD.PLAT if plat.lower().find('pc_editor') >= 0: app_path = SD.APP_PATH_PC_EDITOR elif plat.lower().find('win') >= 0: app_path = SD.APP_PATH_WIN else: app_path = SD.APP_PATH_ANDROID sleep(random.choice(range(1, 8)) * 1) SD().save_dev_status() if SD.WORKER_ID: LOGGING.info(SD.SERIALNO) with allure.step('当前设备:{}'.format(SD.SERIALNO)): pass dev = init_app(plat=plat, package_name=SD.PACKAGE_NAME, app_path=app_path, sleep_time=SD.SLEEP_TIME, serialno=SD.SERIALNO) poco = UnityPoco(addr=("localhost", SD.POCO_PORT)) # 初始化poco request.cls.poco = poco yield request.cls.poco # yield语句后面相当于teardown allure_snap() if plat.lower().find('android') >= 0: stop_app(SD.PACKAGE_NAME) # 整个测试session结束后,关闭app SD().clean_dev_status() elif plat.lower().find('pc') >= 0: Windows().stop_app(dev.stop_app.process) # PC平台是结束进程
def poco(request): """相当于setup""" logger.info('===conftest poco===') logger.debug(f'设置logger(airtest.*)的level为{SD.AIRTEST_LOG_LEVEL}') get_logger("airtest").setLevel(SD.AIRTEST_LOG_LEVEL) random_time = random.choice(range(1, 5)) * 1 + random.choice(range(10)) * 0.1 logger.debug(f'random_time={random_time}') sleep(random_time) dev = init_app() logger.debug('初始化poco') poco = UnityPoco(addr=("localhost", SD.POCO_PORT)) request.cls.poco = poco yield request.cls.poco logger.info('===teardown===') logger.debug('结束前截图') allure_snap() if SD.PLAT == 'android': logger.debug('整个测试session结束后,关闭app') stop_app(SD.PACKAGE_NAME) if SD.USE_ATX_SERVER2: atx_server2 = AtxServer2() ret = atx_server2.release_device(SD.UDID) elif SD.PLAT.find('pc') >= 0: pid = dev.stop_app.process logger.debug(f'PC平台是结束进程,进程id:{pid}') Windows().stop_app(pid)
def test2(self): stop_app('com.tencent.TsumTsumAndroid') sleep(3.0) start_app('com.tencent.TsumTsumAndroid') wait( Template( r"D:\\workspace\\UITest_TsumTsum\\Case\\photo\\tpl1568629745795.png", record_pos=(-0.01, 0.91), resolution=(720, 1496))) poco = UnityPoco() sleep(1.0) poco("btn_start_level").click() sleep(2.0) poco( absoluteName= "UI Root/ChapterPopupPanel/ChapterContainer/list_chapter/scrollView/table/0002/btn_content/chapter_1/tex_chapter" ).click() sleep(1.0) poco("level_2").click() sleep(1.0) poco("btn_start").click() resolution = G.DEVICE.get_current_resolution() old = time.time() while True: pos1 = random.uniform(0, resolution[0]) pos2 = random.uniform(400, resolution[1] - 400) pos3 = random.uniform(0, resolution[0]) pos4 = random.uniform(400, resolution[1] - 400) G.DEVICE.swipe((pos1, pos2), (pos3, pos4)) new = time.time() if (new - old) > 65.0: break
def test_Horse(devices): """ 1.进入主界面 2.点击坐骑按钮 3.依次点击坐骑图标,查看坐骑模型是否正常 """ dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) comparepoMenuExists("SysEHorse", poco) # 调用函数查看主界面坐骑按钮是否可点击 poco("NewBtn").child("BtnBg").click() # 打开坐骑列表 petgrid = poco("Grid").child() # 获取目前所有坐骑数量 swipe((486, 170), (486, 889), 4) for i in range(len(petgrid)): if i == 22: swipe((486, 889), (486, 170), 6) swipe((486, 889), (486, 170), 4) # 滑动界面确保未出现在界面内的坐骑可以点击到 time.sleep(2) item = "item" + str(i) time.sleep(2) poco("Grid").offspring(item).click() # 点击坐骑icon if poco("vehicle_crazydugswing_red").exists(): #判断坐骑模型是否存在 petname = poco("PetName").offspring("Name").get_text() # 获得当前坐骑的名称 print(f"{petname}坐骑模型显示正常") poco("NewBtn").child("BtnBg").click() # 打开坐骑列表 time.sleep(1) return poco("Btnhave").get_name() # 返回值
def test_SysLive(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) poco("SysG_Live").click() poco("SpectateDlg(Clone)").offspring("1").child("Bg").click() print("观战窗口打开正常!") return "1"
def test_SysDance(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) test_ShortCutIcon("SysCDance", poco) poco("SysCDance").click() print("打开跳舞正常") return "1"
def setUpClass(cls): from airtest.core.api import connect_device connect_device('Android:///') cls.poco = UnityPoco() action_tracker = ActionTracker(cls.poco) cls.register_addon(action_tracker)
def test_4userInfo(self): global GAMEID from poco.drivers.unity3d import UnityPoco # 导入并初始化U3d poco = UnityPoco() # Test_2Login.GAMEID = poco("_Text_Level").get_text() GAMEID = poco("_Text_Level").get_text() # GameID(游戏ID) Pr.print(GAMEID) Test_2Login.GAMEID = GAMEID Pr.print(Test_2Login.GAMEID) # mysql.conn # 调用初始化连接数据库方法 # mysql.test_query1() # Pr.print(mysql.QUERYRESULTS) # if int(Test_2Login.GAMEID) == int(mysql.QUERYRESULTS): # Pr.print("93行,数据库GameID验证成功") name = poco("_Text_Name").get_text() # 昵称 Pr.print(name) happyBean = poco("_Text_Score").get_text() # 开心豆 Pr.print(happyBean) redEnvelopes = poco("_Text_Meili").get_text() # 红包券 Pr.print(redEnvelopes) Pr.print("*******************", "个人信息获取成功!")
def init_poco(): connect_device('Android:///192.168.40.38:5555?cap_method=javacap&touch_method=adb') start_app("com.zoxun.kawxhj.hjbf") time.sleep(7) poco = UnityPoco() time.sleep(7) return poco
def selected(): Gameplay.start() poco = UnityPoco() print("每日抽奖test") poco("btn_welfare").click() # 点击福利按钮 poco(text="每日抽奖").click() for i in range(1, 13): itme = poco("txt_item%s" % i).get_text() num = poco("txt_num%s" % i).get_text() print("第%s栏位奖励为:" % i + itme + " " + num) if poco("txt_lottery_free").exists(): free = poco("txt_lottery_free").get_text() times = poco("txt_lottery_left_times").get_text() print("当前拥有" + free + "次数,剩余次数" + times) poco("btn_lottery").click() time.sleep(20) if poco("UIPanelLotteryDouble").child("img_bg").exists(): # 广告收益 poco("UIPanelLotteryDouble").child("img_bg").child( "btn_close").child("Image").click() # 直接关闭 amount = poco("txt_amount").get_text() print("获得奖励" + amount) poco(texture="btn_close").click() # 关闭奖励弹窗 times1 = poco("txt_lottery_left_times").get_text() print("点击" + free + ",剩余次数" + times1) else: print("当前没有免费抽奖次数") return poco("txt_title").get_text()
def setUp(self): self.poco = UnityPoco() self.poco("quick_menu_button").click() self.poco("build").click() time.sleep(3) self.poco("BuildNewQuirkButton").click() time.sleep(10)
def test_01_of_103(self): u'''用例test_01_of_103的操作步骤''' # 每个函数里分别实例poco,否则容易出现pocoserver无限重启的情况 print("我是TC102的test_01_of_103方法") poco = UnityPoco() t = 1 self.assertEquals(1, t)
def test_SysChange(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) test_ShortCutIcon("SysFChange", poco) poco("SysFChange").click() print("变身功能正常") return "1"
def test_SysHorseRide(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) test_ShortCutIcon("SysEHorseRide", poco) poco("SysEHorseRide").click() print("骑乘功能正常") return "1"
def test_1novice(self): from poco.drivers.unity3d import UnityPoco # 导入并初始化U3d poco = UnityPoco() try: exists(Template(r"NoviceRedEnvelope.png")) poco("Image (5)").click() Pr.print("领取新手礼包") poco("_Button_Back").click() Pr.print("关闭新手礼包页面") except: # if Test_Mysql.test_query1().row[-1] == 0: # 查询数据库,查询新用户字段是否为0 Pr.print("该用户不是新注册用户") Button_QianDao = poco('_Button_QianDao', type='Button') # print(Button_QianDao.exists()) # => False. This UI is not visible to user. if Button_QianDao.exists() == True: poco("_Button_Close").click() # 签到弹窗 Pr.print("关闭签到弹窗") else: Pr.print("无签到弹窗") Button_MeKnow = poco("_Button_MeKnow").attr('texture') if Button_MeKnow == "anniu_zhidaole": poco("_Button_Close").click() # 红包场活动弹窗 Pr.print("关闭红包场活动弹窗") else: Pr.print("无红包场活动弹窗") # try: # poco("_Button_Back").click() # 母亲节礼包(活动礼包)弹窗 # Pr.print("关闭母亲节礼包(活动礼包)弹窗") # except: # Pr.print("无母亲节礼包(活动礼包)弹窗") # try: # libao = poco('_Text_Tips').get_text() # libao1 = "每日礼包每种面额只能购买一次" # self.assertEqual(libao, libao1) # poco("_Button_Back").click() # 关闭每日礼包弹窗 # Pr.print("关闭每日礼包弹窗") # except: # Pr.print("无每日礼包弹窗") Button_Tips = poco('_Button_Tips', type='Button') # print(Button_QianDao.exists()) # => False. This UI is not visible to user. if Button_Tips.exists() == True: poco("_Button_Back").click() # 每日礼包弹窗 Pr.print("关闭每日礼包弹窗") else: Pr.print("无每日礼包弹窗") facaijin = poco('_Text_Tips (1) ').get_text() facaijin1 = "开心豆少于1000才可以领取发财金" self.assertEqual(facaijin, facaijin1) try: poco("_Button_Exit").click() Pr.print("关闭发财金弹窗") except: Pr.print("该用户开心豆加银行开心豆大于1000")
def test_02_of_102(self): u'''用例test_02_of_102的操作步骤''' #每个函数里分别实例poco,否则容易出现pocoserver无限重启的情况 print("我是TC102的test_02_of_102方法") poco = UnityPoco() Screencap.GetScreen(time.time(), devices, "test_02_of_102的描述") t = 1 self.assertEquals(2, t)
def test_Chapter_Nine(devices): """ 主线第九章 :return:Complete_Map()参数表示移动多少次可以到达指定章节 """ dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) Complete_Map(1, poco) return poco("Duck").get_name()
def start_war_report(): poco = UnityPoco() poco.agent.command = Command(poco.agent.c) autoRunMap = AutoBattlePerf(poco.agent.command) autoRunMap.initModel() autoRunMap.playReport(warID="27e1407c4d796607cec958141d4fa88a_1", playID=385015877, wartype=1)
def allowFileAccess(self): # snapshot('../../res/img/selfie/allow_save.jpg') self.poco = AndroidUiautomationPoco(screenshot_each_action=False) self.poco("com.android.packageinstaller:id/permission_allow_button").click() # snapshot('../../res/img/selfie/saved.jpg') assert_exists(Template(self.R('res/img/selfie/saved.jpg')), "Picture saved screen not found on screen") self.poco = UnityPoco()
def test_SysAuction(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) poco("SysCAuction").click() poco("AuctionDlg(Clone)").offspring("Sell").child("SelectedTextLabel").click() poco("AuctionDlg(Clone)").offspring("GuildAuc").child("SelectedTextLabel").click() print("交易所打开成功!") return "1"
def test_city_diqu(self): '弹出7天签到界面测试' poco = UnityPoco() if poco(text="第7天").exists(): print('每日有礼--测试通过') else: print('每日有礼--测试失败') assert (poco(text="第7天"))
def test_sysPromote(devices): # 提升 dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) if poco("SysAAFPromote").exists(): poco("SysAAFPromote").click() print("提升按钮点击正常") else: print("暂时没有可提升项目") return "1"
def test_SysActivity(devices): dev = connect_device("android:///" + devices) poco = UnityPoco(device=dev) if poco("SysAActivity").exists(): poco("SysAActivity").click() print("日常打开正常") else: print("未达到开放等级") return "1"