トップページ > Appium API(逆引き) > 【Appium Python】アプリケーションの起動とその関連

【Appium Python】アプリケーションの起動とその関連

【PR】業界トップクラスの「高単価報酬」「低マージン」を実現!レバテックフリーランス

アプリケーションをインストール後、アクティベート「activate_app」を実行することでアプリケーションを前面に表示させて起動させることが出来ます。


起動させたアプリケーションに対してバッググラウンド「background_app」の実行で、アプリケーションを非表示にさせた形で起動状態にすることが出来ます。
「background_app」は引数に秒数を指定することで、バッググラウンド状態の時間を指定することが出来ます。


「query_app_state」でアプリケーションの状態を0~4までの数値で表します。

「terminate_app」で指定したアプリケーションを終了させます。

説明

◆メソッド
  ○アプリケーションアクティベート
       ・driver.activate_app("com.example.app")
      
  ○アプリケーションバッググラウンド
       ・driver.background_app(15)
      
  ○アプリケーション状態の確認
       ・app_state = driver.query_app_state("com.example.app")
         	0 :  is not installed.
         	1 :  is not running.
         	2 :  is running in background or suspended.
         	3 :  is running in background.
         	4 :  is running in foreground.
          
  ○アプリケーションの終了
       ・driver.terminate_app("com.example.app")
◆備考
  ・ー
◆その他「Appium API」
  ・キャプチャ関連
  ・デバイスロック関連

サンプル

from appium import webdriver
import time

#接続したいアプリ情報を変数に格納
desired_caps = {}
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.install_app("C:\\appium_test\\app-debug.apk")
# インストールしたアプリを起動
test_session.activate_app("com.example.appium_test_app")
# フォアグラウンド起動で5秒間待機
time.sleep(5)
# アプリの状態を確認
app_state = test_session.query_app_state("com.example.appium_test_app")
print(app_state) # 4
# バッググラウンドで10秒実行
test_session.background_app(10)
# 10秒後にフォアグラウンド起動に戻った後5秒間待機
time.sleep(5)
# アプリの終了
test_session.terminate_app("com.example.appium_test_app")
# アプリの状態を確認
app_state = test_session.query_app_state("com.example.appium_test_app")
print(app_state) # 1
※Appium v2.0.0-beta.55で動作確認をしています

実行結果

launch1
 ※GoogleおよびGoogleロゴはGoogle Inc.の登録商標であり、同社の許可を得て使用しています。
yajirushi
launch2

Warning: Invalid argument supplied for foreach() in /home/users/1/monda-muki/web/seleniumqref.com/api/appium_python/app/app_launch_related-AppiumPython.html on line 196

Appium PythonAPI TOP10
過去1週間(4/20~4/26)

    カテゴリー

    環境構築

    APIリファレンス

    その他

    ページ上部へ戻る
    トップページ > Appium API(逆引き) > 【Appium Python】アプリケーションの起動とその関連
    Copyright © 2016- Seleniumクイックリファレンス All Rights Reserved