appium
И устранение связанных с этим проблем в процессе установки.;appium
Ознакомьтесь с услугами:C:\Users\Administrator>appium
[Appium] Welcome to Appium v2.2.3
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] http://172.16.1.33:4723/
[Appium] http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] http://172.23.16.1:4723/
[Appium] No drivers have been installed in C:\Users\Administrator\.appium. Use the "appium driver" command to install the one(s) you want to use.
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
appium driver
Не установлено,Давайте установим его;appium driver
Тестовые драйверы управляются отдельно,По умолчанию тестовые драйверы не будут установлены.,проходить appium driver
Подкоманда управляет всеми драйверами;C:\Users\Administrator>appium driver list
- Listing available drivers
✔ Listing available drivers
- uiautomator2 [not installed]
- xcuitest [not installed]
- mac2 [not installed]
- espresso [not installed]
- safari [not installed]
- gecko [not installed]
- chromium [not installed]
uiautomator2
,Другие могут быть установлены в зависимости от ситуации.appium driver install uiautomator2
Установка команд,Но произошла ошибка:C:\Windows\System32>appium driver install uiautomator2
- Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
× Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
Error: × Encountered an error when installing package: npm command 'install --save-dev --omit=peer --save-exact --global-style --no-package-lock appium-uiautomator2-driver --json' failed with code 1.
STDOUT:
{
"error": {
"code": "ETIMEDOUT",
"summary": "request to https://registry.npmjs.org/appium-uiautomator2-driver failed, reason: ",
"detail": "This is a problem related to network connectivity.\nIn most cases you are behind a proxy or have bad network settings.\n\nIf you are behind a proxy, please make sure that the\n'proxy' config is set properly. See: 'npm help config'"
# 1. Просмотр настроек зеркала npm
npm config get registry
# 2. Установите npm в качестве зеркала Taobao.
npm config set registry https://registry.npm.taobao.org
# 3. Еще раз проверьте настройки зеркала npm.
npm config get registry
C:\Windows\System32>appium driver install uiautomator2
- Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
√ Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
i Driver uiautomator2@2.34.2 successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]
Python Client
Для разных языков существуют разные способы установки.,мы используемpython
версия;Appium Python Client
:pip install Appium-Python-Client
Successfully built Appium-Python-Client
Installing collected packages: sortedcontainers, urllib3, sniffio, pysocks, pycparser, idna, h11, certifi, attrs, wsproto, outcome, cffi, trio, trio-websocket, selenium, Appium-Python-Client
Successfully installed Appium-Python-Client-3.1.0 attrs-23.1.0 certifi-2023.11.17 cffi-1.16.0 h11-0.14.0 idna-3.6 outcome-1.3.0.post0 pycparser-2.21 pysocks-1.7.1 selenium-4.16.0 sniffio-1.3.0 sortedcontainers-2.4.0 trio-0.23.1 trio-websocket-0.11.1 urllib3-2.1.0 wsproto-1.2.0
пряжка
,Потому что наш эмулятор — Android 6.0;пряжка
проходитьприезжать В симуляторе,Сохраните локально следующим образом:F:\monkey_test\QQv5.apk
adb uninstall com.tencent.mobileqqi
F:\monkey_test>adb uninstall com.tencent.mobileqqi
Success
adb install QQv5.apk /data/temp
F:\monkey_test>adb install QQv5.apk /data/temp
Performing Push Install
QQv5.apk: 1 file pushed, 0 skipped. 13.1 MB/s (22506899 bytes in 1.634s)
pkg: /data/local/tmp/QQv5.apk
ver: /data/temp
Success
Имя пакета и имя активного окна текущего приложения.
;app
;APP
Затем введите в командной строке:adb shell dumpsys | find "mFocusedActivity"
mFocusedActivity: ActivityRecord{54035c5 u0 com.tencent.mobileqqi/com.tencent.mobileqq.activity.InstallActivity t4}
# Имя пакета: com.tencent.mobileqqi
# Имя окна активности: com.tencent.mobileqq.activity.LoginActivity.
AndroidKiller
В основном правapk
Выполните операции декомпиляции для получения соответствующей информации.;F:\monkey_test
Вниз:aapt dump badging QQv5.apk
F:\monkey_test>aapt dump badging QQv5.apk
package: name='com.tencent.mobileqqi' versionCode='6062' versionName='5.1.1'
install-location:'auto'
sdkVersion:'7'
targetSdkVersion:'15'
uses-permission: name='com.android.launcher.permission.INSTALL_SHORTCUT'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.VIBRATE'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.CHANGE_CONFIGURATION'
uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
uses-permission: name='android.permission.WAKE_LOCK'
uses-permission: name='android.permission.SYSTEM_ALERT_WINDOW'
uses-permission: name='android.permission.RECORD_AUDIO'
uses-permission: name='com.tencent.msf.permission.account.sync'
uses-permission: name='android.permission.MODIFY_AUDIO_SETTINGS'
uses-permission: name='android.permission.CAMERA'
uses-permission: name='android.permission.CHANGE_WIFI_STATE'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.KILL_BACKGROUND_PROCESSES'
uses-permission: name='android.permission.CALL_PHONE'
uses-permission: name='com.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.android.launcher.permission.UNINSTALL_SHORTCUT'
uses-permission: name='android.permission.PERSISTENT_ACTIVITY'
uses-permission: name='android.permission.WRITE_SETTINGS'
uses-permission: name='android.permission.SEND_SMS'
uses-permission: name='android.permission.READ_SMS'
uses-permission: name='android.permission.GET_TASKS'
uses-permission: name='com.tencent.permission.VIRUS_SCAN'
uses-permission: name='android.permission.READ_LOGS'
uses-permission: name='android.permission.READ_CONTACTS'
uses-permission: name='android.permission.FLASHLIGHT'
uses-permission: name='android.permission.BLUETOOTH'
uses-permission: name='android.permission.BLUETOOTH_ADMIN'
uses-permission: name='android.permission.BROADCAST_STICKY'
uses-permission: name='android.permission.WRITE_CONTACTS'
uses-permission: name='android.permission.WRITE_OWNER_DATA'
uses-permission: name='android.permission.SYSTEM_OVERLAY_WINDOW'
uses-permission: name='android.permission.CHANGE_NETWORK_STATE'
uses-permission: name='com.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.android.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.android.launcher3.permission.WRITE_SETTINGS'
uses-permission: name='com.htc.launcher.permission.READ_SETTINGS'
uses-permission: name='com.htc.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.huawei.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.google.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.google.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='android.permission.READ_CALENDAR'
uses-permission: name='android.permission.WRITE_CALENDAR'
uses-permission: name='com.sonyericsson.home.permission.BROADCAST_BADGE'
uses-permission: name='com.sec.android.provider.badge.permission.READ'
uses-permission: name='com.sec.android.provider.badge.permission.WRITE'
uses-permission: name='android.permission.GET_ACCOUNTS'
uses-permission: name='android.permission.MANAGE_ACCOUNTS'
uses-permission: name='android.permission.AUTHENTICATE_ACCOUNTS'
uses-permission: name='android.permission.WRITE_CONTACTS'
uses-permission: name='android.permission.READ_SYNC_SETTINGS'
uses-permission: name='android.permission.WRITE_SYNC_SETTINGS'
uses-permission: name='android.permission.DISABLE_KEYGUARD'
uses-permission: name='android.permission.CHANGE_WIFI_MULTICAST_STATE'
uses-permission: name='com.qq.qcloud.permission.ACCESS_ALBUM_BACKUP_LIST'
uses-permission: name='com.android.vending.BILLING'
uses-permission: name='android.permission.RESTART_PACKAGES'
uses-permission: name='android.permission.NFC'
application-label:'QQi'
application-label-de:'QQi'
application-label-es:'QQi'
application-label-fr:'QQi'
application-label-ja:'QQi'
application-label-ko:'QQi'
application-label-zh-CN:'QQi'
application-label-zh-TW:'QQi'
application-icon-120:'R/m/hcw.png'
application-icon-160:'R/m/hcw.png'
application-icon-240:'R/m/hcw.png'
application-icon-320:'R/m/hcw.png'
application-icon-480:'R/m/hcw.png'
application-icon-65535:'R/m/hcw.png'
application: label='QQi' icon='R/m/hcw.png'
launchable-activity: name='com.tencent.mobileqq.activity.SplashActivity' label='QQi' icon=''
uses-library-not-required:'com.google.android.media.effects'
uses-library-not-required:'com.motorola.hardware.frontcamera'
uses-permission: name='com.tencent.photos.permission.DATA'
uses-permission: name='com.tencent.msf.permission.account.sync'
uses-permission: name='com.tencent.music.data.permission'
uses-permission: name='com.tencent.msf.permission.ACCOUNT_NOTICE'
uses-permission: name='android.permission.CHANGE_WIFI_STATE'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.CAMERA'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.WAKE_LOCK'
uses-permission: name='com.android.launcher.permission.INSTALL_SHORTCUT'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
uses-permission: name='com.tencent.msg.permission.pushnotify'
uses-permission: name='com.tencent.msf.permission.account.sync'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
uses-implied-permission: name='android.permission.READ_EXTERNAL_STORAGE' reason='requested WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.READ_CALL_LOG'
uses-implied-permission: name='android.permission.READ_CALL_LOG' reason='targetSdkVersion < 16 and requested READ_CONTACTS'
uses-permission: name='android.permission.WRITE_CALL_LOG'
uses-implied-permission: name='android.permission.WRITE_CALL_LOG' reason='targetSdkVersion < 16 and requested WRITE_CONTACTS'
feature-group: label=''
uses-feature-not-required: name='android.hardware.camera'
uses-feature-not-required: name='android.hardware.camera.autofocus'
uses-feature-not-required: name='android.hardware.location'
uses-feature-not-required: name='android.hardware.location.gps'
uses-feature-not-required: name='android.hardware.location.network'
uses-feature-not-required: name='android.hardware.telephony'
uses-feature: name='android.hardware.bluetooth'
uses-implied-feature: name='android.hardware.bluetooth' reason='requested android.permission.BLUETOOTH permission, requested android.permission.BLUETOOTH_ADMIN permission, and targetSdkVersion > 4'
uses-feature: name='android.hardware.faketouch'
uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps'
uses-feature: name='android.hardware.microphone'
uses-implied-feature: name='android.hardware.microphone' reason='requested android.permission.RECORD_AUDIO permission'
uses-feature: name='android.hardware.screen.portrait'
uses-implied-feature: name='android.hardware.screen.portrait' reason='one or more activities have specified a portrait orientation'
uses-feature: name='android.hardware.wifi'
uses-implied-feature: name='android.hardware.wifi' reason='requested android.permission.ACCESS_WIFI_STATE permission, requested android.permission.CHANGE_WIFI_MULTICAST_STATE permission, and requested android.permission.CHANGE_WIFI_STATE permission'
main
other-activities
other-receivers
other-services
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--' 'de' 'es' 'fr' 'ja' 'ko' 'zh-CN' 'zh-TW'
densities: '120' '160' '240' '320' '480' '65535'
native-code: 'armeabi'
name='com.tencent.mobileqqi'
launchable-activity: name='com.tencent.mobileqq.activity.SplashActivity'
aapt
Подсказка не найденаприезжать Заказ,需要Пучок它из Установитьсоединение путиприезжатьв переменных системной среды,aapt
из Путь находится в:D:\android-sdk-windows\build-tools\29.0.3
Capabilities
это начатьappium
Служитьконецизпараметрнастраивать;Capabilities
Вы можете обратиться к официальной документации:Appium capabilities;
Capabilities
параметр。automationName
выражать Автоматизированное современный двигатель, как у тест-драйвера;Appium、Selendriod、uiautomator2
ждать;uiautomator2
。platformName
выражать Используйте на мобильном телефоне или эмулятореиз Операционная система;iOS、Android
ждать;Android
。platformVersion
выражать真机或模拟器Операционная системаиз Версия;Android6.0
。deviceName
выражатьиспользоватьиз Тип испытательного оборудования;adb devices
Посмотреть название типа устройства:C:\Windows\System32>adb devices
List of devices attached
emulator-5554 device
emulator-5554
。app
выражать Установить Сумка;app
Установитьприезжатьобозначениеизпуть。newCommandTimeout
выражатьдваAppium
Заказмеждуиз最长时междумежду隔;app
。noReset
выражать Нет необходимости сбрасывать состояние приложения перед сеансом;false
。fullReset
Можетпроходить卸нагрузкаи Не очищать данные для сброса состояния приложения;false
。app
изappPackage
иappActivity
;appPackage
даappиз Сумка名;appActivity
даapp
изимя активного окна;Есть несколько параметров, я не буду объяснять их по отдельности. Просто посмотрите официальную документацию.
python
версия;import unittest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
capabilities = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='Android',
appPackage='com.android.settings',
appActivity='.Settings',
language='en',
locale='US'
)
appium_server_url = 'http://localhost:4723'
class TestAppium(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))
def tearDown(self) -> None:
if self.driver:
self.driver.quit()
def test_find_battery(self) -> None:
el = self.driver.find_element(by=AppiumBy.XPATH, value='//*[@text="Battery"]')
el.click()
if __name__ == '__main__':
unittest.main()
пряжка
,и получилприезжать Понятноиз Сопутствующая информация;appium
Служить,прямо в Заказлинейный входappium
Вот и все:
# -*- coding:utf-8 -*-
# автор:Насекомые без границ
# Дата: 12.12.2023
# Имя файла: test_qq.py
# Функция: appium запускает приложение
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
import time
capabilities = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='emulator-5554',
appPackage='com.tencent.mobileqqi',
appActivity='com.tencent.mobileqq.activity.SplashActivity',
language='en',
locale='US'
)
print("start....")
# Создать объект драйвера
appium_server_url = 'http://localhost:4723'
driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))
# Запустить приложение
print(driver.capabilities)
# driver.launch_app()
time.sleep(1)
print("Уже подключено к симулятору~")
driver.quit()
D:\Python37\python.exe F:/python_study/appium_test/test_qq.py
start....
{'platformName': 'Android',
'automationName': 'uiautomator2',
'deviceName': 'emulator-5554',
'appPackage': 'com.tencent.mobileqqi',
'appActivity': 'com.tencent.mobileqq.activity.SplashActivity',
'language': 'en',
'locale': 'US',
'platform': 'LINUX',
'webStorageEnabled': False,
'takesScreenshot': True,
'javascriptEnabled': True,
'databaseEnabled': False,
'networkConnectionEnabled': True,
'locationContextEnabled': False,
'warnings': {},
'desired': {'platformName': 'Android', 'automationName': 'uiautomator2', 'deviceName': 'emulator-5554', 'appPackage': 'com.tencent.mobileqqi', 'appActivity': 'com.tencent.mobileqq.activity.SplashActivity', 'language': 'en', 'locale': 'US'},
'deviceUDID': 'emulator-5554', 'pixelRatio': '2', 'statBarHeight': 48, 'viewportRect': {'left': 0, 'top': 48, 'width': 768, 'height': 1136},
'deviceApiLevel': 23, 'platformVersion': '6.0', 'deviceManufacturer': 'unknown', 'deviceModel': 'sdk_phone_armv7', 'deviceScreenSize': '768x1280', 'deviceScreenDensity': 320}
Уже подключеноприезжать Симулятор~
appium
из Служитьконец也给出了启动信息:[AndroidUiautomator2Driver@455c (f190abfc)] Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/session/f9cc13f6-4c4e-4ab5-a2eb-8dfb44f05100] with no body
[AndroidUiautomator2Driver@455c (f190abfc)] Got response with status 200: {"sessionId":"f9cc13f6-4c4e-4ab5-a2eb-8dfb44f05100","value":null}
[ADB] Running 'D:\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop com.tencent.mobileqqi'
[Instrumentation] .
[Instrumentation] Time: 74.226
[Instrumentation]
[Instrumentation] OK (1 test)
пряжка
приложение。DEPRECATION: celery 5.0.5 has a non-standard dependency specifier pytz>dev. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of celery or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063
Python
Окружающая среда использует OpenSSL 1.1.0h
,и urllib3 v2.0
Нужно использовать OpenSSL 1.1.1
;# Либо обновить OpenSSL приезжать 1.1.1 или выше.
# Либо понизить версию urllib3 приезжать v1.x версию, вы можете передать команду pip install urllib3==1.* добиться.
urllib3
решитьиз,Но это может вызвать другие проблемы с пакетом зависимостей.pip install urllib3==1.26.15
UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'D:\\android-sdk-windows\\platform-tools\\adb.exe -P 5037 -s emulator-5554 shell pm install -r /data/local/tmp/appium_cache/72200c7819db015d5717d05800401c19b35842d5.apk' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'uiautomator2ServerInstallTimeout' capability
adb
Установитьappium
Служитьизошибка времени;adb uninstall /data/local/tmp/appium_cache/72200c7819db015d5717d05800401c19b35842d5.apk
adb -P 5037 -s emulator-5554 shell pm install -r /data/local/tmp/appium_cache/72200c7819db015d5717d05800401c19b35842d5.apk