def catch_picture(self): from airtest.core.api import snapshot import datetime, os filename = "./Result/picture/" + datetime.datetime.now().strftime( "%Y%m%d-%H%H%S") + ".png" msg = "崩溃" snapshot(filename=filename, msg=msg, quality=ST.SNAPSHOT_QUALITY)
def on_pre_action(self, action, proxy, args): try: from airtest.core.api import snapshot except ImportError: # 兼容旧airtest from airtest.core.main import snapshot snapshot(msg=unicode(proxy))
def getScreen(self, width): filename = 'poco-screenshot.png' screen_dir = os.path.join(Settings.LOG_DIR, Settings.SCREEN_DIR) if not os.path.exists(screen_dir): os.makedirs(screen_dir) filepath = os.path.join(screen_dir, filename) snapshot(filename) return base64.b64encode(open(filepath, 'rb').read()), 'png'
def on_pre_action(self, action, ui, args): if self.screenshot_each_action: # airteset log用 from airtest.core.api import snapshot msg = repr(ui) if not isinstance(msg, six.text_type): msg = msg.decode('utf-8') snapshot(msg=msg)
def wrapper(*args,**kwargs): try: f(*args,**kwargs) except: tb = traceback.format_exc() log("Final Error", tb) raise finally: try: snapshot(msg="Final Snapshot") except: log("无最终截图")
def snapshot(self, filename=None, msg=''): """ 截图 :param filename: 文件名称,可以为空 默认是使用时间作为文件的名字 :param msg: 截图注释 :return: """ try: snapshot(filename=filename, msg=msg) except Exception as e: print(e) traceback.print_exc()
def test_tutorial_8(dev, poco): out('Tutorial_8 test started...') f_ret = False t0 = time.time(); state = find_current_state(poco) if state == State.MAP: f_ret = run_test(dev, poco) out('Tutorial_8 test time: ' + str(time.time() - t0)) if not f_ret: out('last snapshot') snapshot() return f_ret
def test_daily_rewards(dev, poco): out('Daily Rewards test started...') f_ret = False t0 = time.time() state = find_current_state(poco) if state == State.MAP: f_ret = run_test_daily_rewards(dev, poco) out('Daily Rewards test time: ' + str(time.time() - t0)) if not f_ret: out('last snapshot') snapshot() return f_ret
def testMakeLv(self): self.permissionClick() self.autoUpdate() self.login("wn10001", "z123456") self.waitLogin() sleep(5) #进入制作关卡 self.enterMakelevel() #查看帮助 self.lookHelp() #退出关卡 self.exitMylevel() #再次进入制作关卡 self.enterMakelevel() #内网可以测试滑动我的关卡 self.swipeMylevel() #添加关卡 self.addLevel() #关闭免责声明 self.closeDisclaimer() self.addLevel() #同意免责声明 self.agreeDisclaimer() #测试切换标签 self.switchLebel() #关闭制作关卡 self.closeMakeLevel() self.addLevel() self.agreeDisclaimer() #发布关卡缺少怪物失败,添加怪物 self.publish() #发布关卡缺少背景失败,添加背景 self.publish() #发布关卡缺少名称失败,添加名称 self.publish() #发布成功 self.publish() #测试关卡修改 self.modifyLevel() self.updatePrivacy() self.swipeMylevel() self.deleteLevel() #结束测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("finish test")
def snap_shot(self, value: List): """ 截图 :param value: :return: """ with shelve.open(f"{mydbs_dir}/screenshot_dir") as db: screenshot_dir = db["screenshot_dir"] time_stamp = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) file_path = os.path.join(screenshot_dir, f"{time_stamp}_{value[1]}.png") self.log.info(f"截图--{file_path}") # 截图 snapshot(filename=file_path) # 日志中增加截图 allure.attach.file(f"{file_path}", f"{value[1]}", attachment_type=allure.attachment_type.PNG)
def testCommentNotEnoughCoins(self): self.permissionClick() self.autoUpdate() self.login("wn10002", "z123456") self.waitLogin() sleep(5) self.enterReward() #金币不足无法进入一个关卡 self.enterOneReward() #进入评论,输入星级和评论文字,点击评论,提示金币不足 self.poco("Tree").child()[0].child("Evaluate").click() sleep(1) self.startRating() self.enterCommnet() self.comment() #结束测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("finish test")
def test_tutorial_0(dev, poco): out('Tutorial_0 test started...') f_ret = False t0 = time.time() state = find_current_state(poco) if state == State.MAP: if reset_progress(dev, poco): f_ret = run_test_tutorial(dev, poco) else: if state == State.TUTORIAL: f_ret = run_test_tutorial(dev, poco) out("Tutorial_0 test time: " + str(time.time() - t0)) if not f_ret: out('last snapshot') snapshot() if not f_ret: skip_tutorial_0(dev, poco) return f_ret
def traverse_layer(action, params): snapshot() if uiobj and 'visibleBounds' in uiobj: b = uiobj['visibleBounds']['bottom'] l = uiobj['visibleBounds']['left'] r = uiobj['visibleBounds']['right'] t = uiobj['visibleBounds']['top'] if params and params[-1] == "topleft": # 点击识别区域的左上角 x, y = l, t elif params and params[-1] == "bottomright": # 点击识别区域的右下角 x, y = r, b else: # 点击中间位置 x, y = (l + r) / 2, (b + t) / 2 log_in_func({ "cv": { "confidence": 1, "result": [x, y], "rectangle": [[l, t], [l, b], [r, b], [r, t]] }, 'ret': [x, y], })
def testCommentNoPlayed(self): self.permissionClick() self.autoUpdate() self.login("wn10008", "z123456") self.waitLogin() sleep(5) self.enterReward() self.poco("Tree").child()[0].child("Evaluate").click() sleep(1) self.startRating() self.enterCommnet() self.comment() self.poco("Return").click() sleep(1) self.poco("Return").click() sleep(1) #结束测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("finish test")
# coding=utf-8 import json import time from poco.drivers.unity3d import UnityPoco as Poco from airtest.core.api import start_app, stop_app, Template, exists, snapshot from base64 import b64decode poco = Poco() path = snapshot('../../res/img/chat/emoji_chat.png') print("path:" + path)
def testRewardLevel(self): self.permissionClick() self.autoUpdate() self.login("wn10001", "z123456") self.waitLogin() sleep(7) player = self.getUserData() #进入悬赏关卡 self.enterReward() #查看帮助 self.rewardHelp() #切换标签测试 self.changeLabel() #列表滑动测试 self.swipeList() #筛选测试 #由于bug会复制filters,所以退出重进 self.filterOpen() self.switchFliters() self.cancelAll() self.recoveryFilters() #由于bug会复制filters,所以退出重进 self.poco("Return").click() sleep(1) self.poco("RewardLV").click() sleep(1) self.onlyMine(player) self.recoveryFilters() #具体关卡进入和退出 self.enterOneReward() #进入评论 self.poco("Tree").child()[0].child("Evaluate").click() sleep(1) #直接评论弹出星级不能为空 self.comment() # #输入星级再评论弹出文字不能为空 self.startRating() self.comment() # #输入文字再评论弹出评论成功 self.enterCommnet() self.comment() #点赞和踩 self.like() self.hate() #举报测试 self.reportLevel() self.poco("Btn_Back").click() sleep(1) #长按测试 self.longPress() stop_app("com.gameholic.drawsomethingbyspider") self.permissionClick() self.autoUpdate() self.login("wn10008", "z123456") self.waitLogin() sleep(5) self.enterReward() self.poco("Tree").child()[0].child("Evaluate").click() sleep(1) self.startRating() self.enterCommnet() self.comment() self.poco("Return").click() sleep(1) self.poco("Return").click() sleep(1) #结束测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("finish test")
def getScreen(self, width): savepath = snapshot() return base64.b64encode(open(savepath, 'rb').read()), 'png'
# coding=utf-8 from poco.drivers.unity3d import UnityPoco from airtest.core.api import snapshot poco = UnityPoco() path = snapshot('../../res/img/optionsmenu/accountfound.jpg') print("path:" + path)
def runTest(): stop_app("com.gameholic.drawsomethingbyspider") clear_app("com.gameholic.drawsomethingbyspider") wake() home() start_app("com.gameholic.drawsomethingbyspider") sleep(7) permissionClick() autoUpdate() login("wn10001", "z123456") waitLogin() sleep(5) poco = UnityPoco() #进入商店 poco("Shop").click() sleep(1) #关闭购买去广告提示弹框 if poco("BitchPopup").child("Image").child("Image").exists(): print("弹出支付去广告成功") poco("Button").child("Text").click() if not poco("BitchPopup").child("Image").child("Image").exists(): print("关闭弹框成功") sleep(1) #关闭商店 poco("Return").click() sleep(1) if not poco(text="Limited").exists(): print("退出商店成功") poco("Shop").click() sleep(1) #关闭购买去广告提示弹框 if poco("BitchPopup").child("Image").child("Image").exists(): print("弹出支付去广告成功") poco("Button").child("Text").click() sleep(1) #切换标签和购买 #切换所有标签 poco(text="Gift").click() sleep(1) if poco("PropName").get_text() == "Marvellous Gift": print("切换礼物标签成功") poco("Text (2)").click() sleep(1) if poco("PropName").get_text() == "Speed-up": print("切换到道具标签成功") poco(text="Diamonds").click() sleep(1) if poco(text="Super Gems Pack").get_text() == "Super Gems Pack": print("切换钻石标签成功") poco(text="Limited").click() sleep(1) if not poco("PropName").exists(): print("切换到礼包标签成功") poco(text="Monster").click() sleep(1) if poco(text="Green Fluffy").get_text() == "Green Fluffy": print("切换到怪物标签成功") #滑动列表 poco(texture="monster_A1_1").wait_for_appearance() poco(texture="monster_A1_1").click() beforSwipe = poco(texture="monster_A1_1").get_position() poco.swipe([300.0/576, 850.0/1024],[300.0/576, 150.0/1024]) sleep(2) afterSwipe = poco(texture="monster_A1_1").get_position() if beforSwipe != afterSwipe: print("滑动列表成功") else: print("滑动列表失败") #滑动回顶部 poco.swipe([300.0/576, 150.0/1024],[300.0/576, 850.0/1024]) sleep(2) #购买逻辑 poco("Tree").child("ShopProp(Clone)")[0].child("BuyIt").child("Text").click() sleep(2) buyConfirm = poco("lable").get_text() if buyConfirm == "Confirm to purchase": print("打开确认购买弹框成功") #取消购买 poco(text="Cancel").click() sleep(1) if not poco(text="Confirm to purchase").exists(): print("取消购买成功") #wn10001购买怪物成功 buy() #切换到钻石标签查看sdk调出 poco(text="Diamonds").click() sleep(1) if poco(text="Super Gems Pack").get_text() == "Super Gems Pack": print("切换钻石标签成功") buy() #完成测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("shop finish test")
# coding=utf-8 from poco.drivers.unity3d import UnityPoco from airtest.core.api import snapshot poco = UnityPoco() path = snapshot('../../res/img/Commons.jpg') print("path:" + path)
def RecordResult(self): filename = os.path.join(self.path, time.strftime("%Y%m%d-%H%M%S", time.localtime()) + ".jpg") self.logger.info(f"image save at {filename}") snapshot(filename, "result snapshot", 99)
def testHandBook(self): self.permissionClick() self.autoUpdate() self.login("wn10001", "z123456") self.waitLogin() sleep(5) #进入图鉴 # poco = UnityPoco() self.poco("Favorites").click() sleep(1) if self.poco(text="Handbook").get_text() == 'Handbook': print("进入图鉴成功") #查看帮助 self.poco("Explain").click() sleep(1) if self.poco("txt").exists(): print("打开帮助成功") self.poco("confirm").click() sleep(1) if not self.poco("txt").exists(): print("关闭帮助成功") #切换标签 self.poco("Text (1)").click() sleep(1) if self.poco("10102").exists(): print("切换悬赏关卡标签成功") self.poco(text="Basic Stage").click() sleep(1) if self.poco("Levelnum2001").exists(): print("切换基础关卡标签成功") #滑动列表 beforeSwipe = self.poco("Levelnum2001").child("thumbnail").child("Image").get_position() self.poco("OursLevel").swipe([0,-0.2]) sleep(2) afterSwipe = self.poco("Levelnum2001").child("thumbnail").child("Image").get_position() if beforeSwipe != afterSwipe: assert("滑动基础关卡图鉴成功") self.poco("OursLevel").swipe([0,0.4]) sleep(2) #查看具体图鉴 self.poco("Levelnum1").click() sleep(1) if self.poco(texture="zhizuoguanka_kuang").exists(): print("查看具体图鉴成功") #恢复图鉴状态 for _ in range(2): self.poco("Left").click() sleep(1) #读取第1、3张图位置 beforeSwipe1 = self.poco("Scroll View").child("Content").child("pic")[0].child("Panel").child("image").get_position() beforeSwipe3 = self.poco("Scroll View").child("Content").child("pic")[2].child("Panel").child("image").get_position() for _ in range(3): self.poco("BigPic").child("Middle").child("Scroll View").swipe([-0.4,0]) sleep(1) afterSwipe3 = self.poco("Scroll View").child("Content").child("pic")[2].child("Panel").child("image").get_position() if beforeSwipe3 != afterSwipe3: assert("向右滑动翻页成功") for _ in range(3): self.poco("BigPic").child("Middle").child("Scroll View").swipe([0.4,0]) sleep(1) afterSwipe1 = self.poco("Scroll View").child("Content").child("pic")[0].child("Panel").child("image").get_position() if beforeSwipe1 == afterSwipe1: assert("向左滑动翻页成功") for _ in range(2): self.poco("right").click() sleep(1) afterClick3 = self.poco("Scroll View").child("Content").child("pic")[2].child("Panel").child("image").get_position() if afterClick3 == afterSwipe3: assert("点击右翻页成功") for _ in range(2): self.poco("Left").click() sleep(1) afterClick1 = self.poco("Scroll View").child("Content").child("pic")[0].child("Panel").child("image").get_position() if afterClick1 == beforeSwipe1: assert("点击左翻页成功") self.poco("BigPic").child("Middle").child("Scroll View").click() if self.poco(text="Handbook").exists(): assert("关闭具体图鉴成功") #退出图鉴 self.poco("Return").click() sleep(1) if not self.poco(text="Handbook").exists(): print("退出图鉴成功") print("handBook finish test") #完成测试 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("finish test")
def testBasicLevel(self): # init_device() self.permissionClick() self.autoUpdate() self.login("wn10001", "z123456") self.waitLogin() sleep(5) # self.self.poco = Unityself.poco() self.poco(text="Basic Stage").click() sleep(1) if self.poco("Up").child("Text").get_text() == "Select Stage": assert ("进入基础关卡成功") self.poco("Explain").click() sleep(1) if self.poco("zi").exists(): assert ("成功打开帮助") self.poco("confirm").click() sleep(1) if not self.poco("txt").exists(): assert ("成功关闭帮助界面") for _ in range(4): self.poco.swipe([50.0 / 720, 400.0 / 1280], [670.0 / 720, 400.0 / 1280]) sleep(3) self.poco("Content").offspring('Levelnum1').click() sleep(1) if self.poco("HPimage").exists(): assert ("成功进入具体关卡") sleep(1.0) self.poco("Return2").click() sleep(1) exitText = self.poco("lable").get_text() if exitText == "Are you sure you want to exit the game?": assert ("成功打开退出弹框") self.poco(text="Cancel").click() sleep(1) if not self.poco("lable").exists() and self.poco("HPimage").exists(): assert ("成功关闭退出弹框") self.poco("Return2").click() sleep(1) if exitText == "Are you sure you want to exit the game?": assert ("再次成功打开退出弹框") self.poco(text="OK").click() if self.poco("Up").child("Text").get_text() == "Select Stage": assert ("成功退出具体关卡") for _ in range(4): self.poco.swipe([670.0 / 720, 400.0 / 1280], [50.0 / 720, 400.0 / 1280]) sleep(3) if self.poco("WaitAfter").exists(): assert ("所有关卡都可以翻页") self.poco("Levelnum40").click() sleep(1) if not self.poco("HPimage").exists() and self.poco("Up").exists(): assert ("未解锁关闭无法进入") self.poco("Return").click() sleep(1) if self.poco("StartGame").exists(): assert ("返回主界面成功") stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("basic level finish test")
def test4(): from airtest.core.api import snapshot snapshot('screenshot.png')
def on_pre_action(self, action, proxy, args): # airteset log用 from airtest.core.api import snapshot snapshot(msg=unicode(proxy))
def testMonsterBook(self): self.permissionClick() self.autoUpdate() self.login("wn10001", "z123456") self.waitLogin() sleep(5) #由于怪物图鉴重新安装游戏后会消失的bug存在,所以先进入一个关卡解锁一个怪物 self.poco(text="Basic Stage").click() sleep(1) for _ in range(4): self.poco.swipe([16.0 / 576, 400.0 / 1024], [560.0 / 576, 400.0 / 1024]) sleep(3) if self.poco("Levelnum1").child("thumbnail").child("Image").exists(): self.poco("Levelnum1").child("thumbnail").child("Image").click() sleep(1) self.poco("Return2").click() sleep(1) self.poco(text="OK").click() sleep(1) self.poco("Return").click() sleep(1) #进入图鉴 self.poco("MonsterCompose").click() sleep(1) if self.poco("Tree").child("LvTemplate(Clone)").child( "thumbnail").exists(): print("进入图鉴成功") #测试帮助 self.poco("Explain").click() sleep(1) helpText = self.poco("txt").get_text() if "Monsters illustrated" in helpText: print("打开帮助成功") self.poco("confirm").click() sleep(1) if not self.poco("zi").exists(): print("关闭帮助成功") #测试单个怪物 self.poco("Tree").child("LvTemplate(Clone)").child("thumbnail").click() sleep(1) if self.poco("MonsterInfo").exists(): print("查看具体怪物详情成功") self.poco("Return").click() sleep(1) if not self.poco("MonsterInfo").exists(): print("关闭具体怪物详情成功") #测试滑动 beforeSwipe = self.poco("Tree").child("LvTemplate(Clone)")[0].child( "thumbnail").get_position() self.poco("Viewport").swipe([0, -0.4]) sleep(2) afterSwipe = self.poco("Tree").child("LvTemplate(Clone)")[0].child( "thumbnail").get_position() assert_not_equal(beforeSwipe, afterSwipe, "滑动成功") #退出图鉴 self.poco("Return").click() sleep(1) if not self.poco("Tree").child("LvTemplate(Clone)").child( "thumbnail").exists(): print("退出怪物图鉴成功") #测试完成 stop_app("com.gameholic.drawsomethingbyspider") sleep(2.0) snapshot(msg="app stopped") print("monster handbook finish test")