안드로이드 테스트 자동화를 위한 applium 가져오기 (윈도우즈 + ptyhon)

8681 단어 Androidappium
안드로이드 + 윈도우즈 +python 환경에서 applium의 가져오는 방법을 조사한 노트입니다.
python을 사용하는 데도 공식.의 js 코드가 움직이지 않는 이유가 있다.
개요는 Get started with mobile automation: Appium & Python의 개요이다.

차리다


Android Studio、python、Node.js 등이 설치되었습니다.

1. appium


GUI 및 CLI 가 있습니다.CLI를 사용했습니다.
도입 방법 상세여기 기사.
본체
npm install -g appium
설치에 결함이 없는지 진단하는 도구
npm install -g appium-doctor
진단하다
appium-doctor --android
Bin directory for %JAVA_HOME% is not set
왜냐하면 %JAVA_HOME%\bin; path 추가

2. ptyhon 클라이언트 라이브러리


python을 사용하려고 하기 때문에 아래에 설치합니다pip install Appium-Python-Client

3. Android Virtual Device 시작 만들기


Android Studio에서 AVD 관리자를 시작하여 가상 장치를 제작합니다.다음 설정을 사용했습니다.
터미널: Nexus One
APILevel: 26
ABI: x86
target:Android8.0 (Google APIs)

4. 애플리케이션 시작


2019/1/14 추기 관리자 권한으로 시작해야 할 수도 있음
appium

테스트


1. 상대의 apk 준비


원문에서 테스트 대상은 Chess Free라는 응용 프로그램을 사용했다.에서 오다여기..apk를 다운로드하여 적당한 위치에 두다.

2. AndroidManifest.xml에서 필요한 정보 얻기


필요한 것은
1. 포장 이름
2. 활동 이름 시작
apk의 루트 디렉토리에 있는 Android Manifest.xml에서 얻습니다.또는 명령 프롬프트에서aapt dump badging apkへのパス그런데 소식이 있는 것 같아요.
Chess Free 정보
package="uk.co.aifactory.chessfree"and
android:name=".ChessFreeActivity"
필요한 정보.

3. 시험 쓰기


android_chess.py
"""
Qxf2: Example script to run one test against the Chess Free app using Appium
The test will:
- launch the app
- click the 'PLAY!' button
"""

import os
import unittest
from appium import webdriver
from time import sleep

class ChessAndroidTests(unittest.TestCase):
    "Class to run tests against the Chess Free app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '8.0'
        desired_caps['deviceName'] = 'Nexus'
        # Returns abs path relative to this file and not cwd
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'apps/Chess Free.apk'))
        desired_caps['appPackage'] = 'uk.co.aifactory.chessfree'
        desired_caps['appActivity'] = '.ChessFreeActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        "Tear down the test"
        self.driver.quit()

    def test_single_player_mode(self):
        "Test the Chess app launches correctly and click on Play button"
        sleep(15)
        element = self.driver.find_element_by_id("uk.co.aifactory.chessfree:id/ButtonPlay")
        element.click()
        sleep(5)

#---START OF SCRIPT
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)
주의 setUp() 내의 설정은 자신의 환경의 설정과 일치한다.
원래 보도와 달리 Chess Free의 응용 프로그램에는 다음과 같은 그림의 확인 화면이 나타난다

어쨌든sleep(15) 할 때 "Accept"를 수동으로 눌러요.
자신의 앱을 테스트하려면 버튼의 식별명 등을 알아야 한다
다른 프로그램의 버튼 id를 아는 방법이 있나요?
2019/4/7 보충
Android Studio와 함께 제공되는 UI Automator Viewer는 가능합니다@jwoff25.또 애플의 GUI 버전도 가능하다.

4. 실행


AVD와 applium이 시작되고 있기 때문에 실행만 남았습니다python android_chess.pyChessFree의 "PLAY!"버튼이 눌린 후에 프로그램이 끝납니다
지령 제시 화면은 이런 느낌이다.
test_single_player_mode (_main_.ChessAndroidTests)
Test the Chess app launches correctly and click on Play button ... ok
----------------------------------------------------------------------
Ran 1 test in 29.538s
OK

좋은 웹페이지 즐겨찾기