「get_screenshot_as_file」の実行で画面キャプチャをファイルで取得することが出来ます。保存先は「get_screenshot_as_file」の引数で指定することでローカルPCに保存することが出来ます。
動画キャプチャは「start_recording_screen」の実行での記録を開始し、「stop_recording_screen」で記録を終了させます。startとstop間の記録は「stop_recording_screen」実行の戻り値であるバイナリデータを、base64デコードでファイルに書き込むことで動画ファイルとして保存することが出来ます。
説明
◆メソッド ○画面キャプチャ(静止画) ・driver.get_screenshot_as_file("/path/to/capture_file") ○動画キャプチャ(録画開始) ・driver.start_recording_screen() ○動画キャプチャ(録画終了) ・device.stop_recording_screen ◆備考 ・ー ◆その他「Appium API」 ・デバイスロック関連 ・画面向きの設定と取得
サンプル
from appium import webdriver import time import base64 #接続したいアプリ情報を変数に格納 desired_caps = {} desired_caps["appium:app"] = "C:\\appium_test\\app-debug.apk" desired_caps["platformName"] = "Android" desired_caps["platformVersion"] = "12.0" desired_caps["appium:deviceName"] = "PixelXLAPI31" desired_caps["appium:automationName"] = "UiAutomator2" #セッションの作成 test_session = webdriver.Remote( command_executor='http://localhost:4723/wd/hub', desired_capabilities= desired_caps) #画面キャプチャを取得 test_session.get_screenshot_as_file("c:\\capture\\image.png") #動画キャプチャを開始 test_session.start_recording_screen() #この15秒の間でアプリ上で任意の操作をする time.sleep(15) #動画キャプチャを終了 raw = test_session.stop_recording_screen() #動画ファイルとして保存 filepath = "C:\\capture\\2023001.mp4" with open(filepath,"wb") as vd: vd.write(base64.b64decode(raw))
※Appium v2.0.0-beta.55で動作確認をしています