LoginSignup
1
0

More than 1 year has passed since last update.

setup & sample run android app with appium + python in Mac

Last updated at Posted at 2022-12-02

Outline

先日、webのtest自動化するための構築,sample codeを記載した
[Set up] Robot framework - python in mac
Selenium WebDriver Java Simple Program - Login

今回は、NativeAPPをテストするための第一歩までを記述する。

Condition

APP, OS Version 等
Mac Monterey version 12.4
Python 3.9.6
Appium 1.22.3

Setup

Install Appium

appiumのinstallはこちら参考
setup appium in Mac for iOS APP (Monterey)

Install Homebrew

Pythonをinstallするにあたり、パッケージ管理ツールHomebrewをinstallする
terminalを起動し、以下コマンドを入力する

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Install Python

macはdefaultでPython2.7がinstallされている。
しかし、最新にして動かしたいので、Python3をinstallする
※python3がdefaultで入っていれば、ここはskip

homebrewを使って、python3をinstallする

brew install python3

install後、version確認をする

python3 --version

PATH 設定

pip のpathを設定する
基本的に、user (${USERNAME}) のLibraryにinstallされる。
まず、installされた先を確認する

/Users/${USERNAME}/Library/Python/3.9/bin

bashを使用している場合、.bash_profileにexportでPATHの追加をする

vi ~/.bash_profile 

export例

export PATH="/Users/${USERNAME}/Library/Python/3.9/bin:$PATH"

改めて、terminalを起動し、PATHを有効にする。

Install pip

pythonのpackage管理ツールをinstallする

python3 -m pip install pillow

install確認をする

pip3 --version

Install Appium-Python-Client

pip3 install Appium-Python-Client

Script

今回のsampleは、あくまでappiumを使って自動化が動くかの疎通確認のため
kdreams appの”その他”をクリックするテストにとどめる。

appium serverはlocalにてdefaultの設定で起動する

# 1. import
import os
import time
import unittest
from appium import webdriver
from time import sleep


# 2. capabilities
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'XPERIA5'
desired_caps['app'] = 'kdreams.apk'
desired_caps['appPackage'] = 'jp.xxxxx.kdreams'
desired_caps['autoGrantPermissions'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 3. main test step

time.sleep(5)

print("click ETC")
el1 = driver.find_element_by_accessibility_id("その他, タブ: 4/4")
el1.click()

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0