Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AirtestとPocoとOpenSTFによるUnity製スマートフォン向けゲームの実機自動テスト環境構築とその利用方法

 AirtestとPocoとOpenSTFによるUnity製スマートフォン向けゲームの実機自動テスト環境構築とその利用方法

「CEDEC 2020」の発表資料です。
http://cedec.cesa.or.jp/2020/session/detail/s5e82a55322244

CyberAgent SGE Engineer

September 04, 2020
Tweet

More Decks by CyberAgent SGE Engineer

Other Decks in Technology

Transcript

  1. PocoManager 導入 #if ENABLE_AIRTEST // Airtestデバッグの為に実体化 var pocoGameObject = new

    GameObject(); pocoGameObject.name = "Poco"; pocoGameObject.gameObject.AddComponent<Poco Manager>(); #endif シーン上に予めPocoManagerを 配置しても動作するが、 シンボルで切り分けた方が 取り回しが良い 28
  2. テストコードを書く from airtest.core.api import start_app from poco.drivers.unity3d import UnityPoco #

    ゲームを起動し、Pythonコードを実行すると # ゲーム内PocoSDKとPythonが接続される。 poco = UnityPoco() # 特定のゲームオブジェクトのタップ poco("BattleButton").click # 長押し処理 poco.long_click(pos=[0, 0], duration=3.0) # テキスト情報の取得 text = poco("ErrorCode").get_text() 36
  3. 取得できる情報 # UIの名前の取得 poco("CoalitionName").get_name() # UIの座標取得 poco("CoalitionName").get_position() # テキスト値の取得 poco("CoalitionName").get_text()

    # 体力を確認して、その値が0以下じゃなければ # みたいな処理をよく書いたりする hp = poco("HitPoint").get_text() if hp not 0: 37
  4. 38 エラーがあったら Slackに通知 def exists_end_report(self, poco): if poco("ErrorCode").exists(): image =

    poco.snapshot() text = poco("ErrorCode").get_text() self.messenger.upload("screen." + image[1], text, base64.b64decode(image[0])) sys.exit() 画面上にエラーコードが発行さ れていたらslackに投稿する
  5. 39 指定のスキルが見つ かるまで遷移   def skill_table_pos_check(self, skill_name): pos = self.poco(text=skill_name).get_position() #

    画面外に押したいボタンがある while pos[0] < 0 or pos[0] > 1: # スワイプさせたり、ボタンを押したり等の処理 if pos[0] < 0: self.poco("LeftArrowButtonSprite").click() if pos[0] > 1: self.poco("RightArrowButtonSprite").click() pos = self.poco(text=skill_name).get_position()
  6. 端末確保の自動化 def main(adb_path, serials): api_instance = create_api_instance() devices = api_instance.get_user_devices()

    print(devices) for serial in serials: print(serial) device = swagger_client.AddUserDevicePayload(serial) add_user_device(api_instance, device) thread = api_instance.remote_connect_user_device_by_serial(serial, async_req=True) res = thread.get() remote_connect_url = res.remote_connect_url cmd = adb_path + " connect " + remote_connect_url while True: proc = subprocess.run(cmd, shell=True, stdout=PIPE, stderr=PIPE, text=True) time.sleep(1) if 'connected' in proc.stdout: break swagger-codegenを利用し て、Pythonでクライアントを作 成 45
  7. 自動化のタスクを CSVで表現する task_classes = [TaskHttpGet, AttacklTask, TacticsTask, HealTask, SpecialTask, CheerTask,

    TaskBasicTap, TaskScreenShot, TaskHttpRuleChange, TaskHttpBattleBegin, TaskHttpBattleEnd, TaskHttpEditStatus, TaskStartWar, TaskGameStart, SpreadSheetLogger, TaskHttpEditHp, TaskTriggerCheck] obj_graph = pinject.new_object_graph(binding_specs=[PocoCSVBindingSpec()]) for task in task_classes: instance = obj_graph.provide(task) self.worker[instance.tag()] = instance for index, row in df.iterrows(): if row[0] in self.worker.keys(): var = self.worker[row[0]].action(row) 大まかに表現するとこのような 感じ タスク毎にクラスを作成し、 CSVのコード毎に呼び出す 54
  8. 高速化のちょっと したコツ dev = device() poco = UnityPoco() screen_width, screen_height

    = poco.get_screen_size() pos_attack_scale_x, pos_attack_scale_y = poco("LeftBgSprite").get_position() pos_x = screen_width * pos_attack_scale_x dev.minitouch.touch((pos_x, pos_y)) https://github.com/DeviceFarmer/minitouch 59
  9. 参考文献や素材等 かわいいフリー素材集 いらすとや 4,750,000+ free and premium vector icons in

    SVG, PNG, CSH and AI format. Azusa 3 - 大体いい感じになる無料 Keynote・Googleスライドテンプレート 【Unity】「Airtest IDE」を使用して Android のゲームで画像認識による UI の自動テストを試してみた Androidのリモート操作/管理ツール「OpenSTF」をDocker for Windowsで使う OpenSTF+Dockerで社内Android端末管理システムを Mac上に構築する https://airtest.netease.com/ AirtestProject/Poco-SDK Device Farmer stfのiosサポート https://github.com/tmobile/stf_ios_support Welcome to Poco (ポコ) documentation! — poco 1.0 documentation 69