end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install appium and Appium-Python-Client to windows 10

「"RPA"風に利用できるかも」と思い、次のurlを参考にさせて頂きながら、 appium を windows10にinstall 。

今回は「とりあえずのinstall」まで行っています。

java , python , nodejs

それぞれが、何の prerequired かであるかは、忘れましたが、 appium 等のinstall 前に以下のversionがinstallされていました。

C:\Users\end0t>java -version
java version "10.0.1" 2018-04-17

C:\Users\end0t>python --version
Python 2.7.16

C:\Users\end0t>node -v
  v10.15.3
C:\Users\end0t>npm -v
  6.4.1

install android studio (3.3.2 for Windows 64-bit (948 MB))

android仮想端末とplatform-toolsが必要ですので、 android studio をinstallしています。

インストーラandroid-studio-ide-182.5314842-windows.exe です。 (ver.3.3.2 という文字列がファイル名にないことが少々、気になります)

android studioのinstallにより、SDKも合わせてinstallされますが windows環境変数に以下を追加しています。

android studioから仮想端末を作成し、adbで動作確認

次のように追加した仮想端末が認識されていれば、OK

C:\Users\end0t>adb devices
List of devices attached
emulator-5554   device

install appium (GUI版)

http://appium.io/ から appium-desktop-setup-1.11.0.exe をダウンロードし、installするだけです。

install appium (CUI版)

C:\Users\end0t>npm install -g appium
C:\Users\end0t>npm install -g appium-doctor
C:\Users\end0t>appium-doctor

install後の appium の状態?は、appium-doctor が診断してくれます。 私の場合、 windows-build-tools や opencv4nodejs をinstallしています。 ( cmake もinstallしたような)

PS C:\WINDOWS\system32> npm install --global windows-build-tools
PS C:\WINDOWS\system32> npm install --save opencv4nodejs

install Appium-Python-Client

C:\Users\end0t>pip install Appium-Python-Client

軽く動作確認

#!python
# -*- coding: utf-8 -*-
import getopt
import sys
import os
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import unittest


# https://github.com/appium/python-client

class TestAppium(unittest.TestCase):

    def setUp(self):
        desired_caps = {}
        desired_caps["platformName"] = "Android"
        desired_caps["automationName"] = "Appium"
#        desired_caps["automationName"] = "uiautomator2"
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'ApiDemos-debug.apk'))
        desired_caps["platformVersion"] =  "8.1"
        desired_caps['deviceName'] = 'Nexus 5 API 27'
        desired_caps["appPackage"] = "io.appium.android.apis"
        desired_caps["appActivity"] = "io.appium.android.apis.ApiDemos"
        
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
                                       desired_caps)

    def tearDown(self):
        self.driver.quit()

    def test_contexts_list(self):
        el = self.driver.find_element_by_class_name('android.widget.ListView')

        actions = TouchAction(self.driver)
        actions.flick_element(el, 0, -300, 0)
        actions.perform()
        sleep(5)


#    def test_find_element(self):

#        elm = self.driver.find_element_by_class_name('android.widget.TextView');
#        print(elm)
#        elm.click()
        
#        TouchAction(self.driver).tap(x=204, y=530).perform()
#        TouchAction(self.driver).tap(x=204, y=700).perform()

        # 要素が見つかるまで ?sec待つ
#        self.driver.implicitly_wait(5)
        
#        elm = self.driver.find_element_by_accessibility_id("App");
#        elm = self.driver.find_element_by_id("android:id/text7");


if __name__ == "__main__":
    unittest.main()