如果在线安装Android SDK时,镜像文件老是加载失败时的解决方案
Android SDK 的安装与配置
具体的安装配置参考以下链接
APPIUM自动化测试环境搭建实践
Appium+python自动化1-环境搭建(上)
Appium+python自动化2-环境搭建(下)
环境
java: 8
appium: 1.14.2
Genymotion模拟器的安装很简单,在官网设置账号,然后安装后登录账号就行了。在主界面选择系统进行安装,安装成功后启动就能看到Android的主界面了。
Genymotion模拟器 de 默认端口是 5555
查看apk的apk包名和launcherActivity,参考以下的地址
Appium+python自动化3-启动淘宝app
添加依赖
Appium-Python-Client 0.47
selenium 3.141.0
测试代码
# coding=utf-8
# 如果未安装Appium-Python-Client,使用from appium import webdriver时报错:ModuleNotFoundError: No module named 'appium'
from appium import webdriver
desired_caps = {
#系统类型 Android|IOS
'platformName': 'Android',
#设备名称 备注:如果您使用的模拟器,就是模拟器中虚拟机的名称
'deviceName': 'Samsung Galaxy S9',
#系统版本
'platformVersion': '9.0',
#指向模拟器的IP端口
'udid': '192.168.34.xx:5555',
# apk包名
'appPackage': 'com.taobao.taobao',
# apk的launcherActivity
'appActivity': 'com.taobao.tao.welcome.Welcome',
#等待超时,服务端没接收到命令将关闭appium
'newCommandTimeout': '180',
#等待元素出现超时时间
'implicitlyWait': '30'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
如果系统版本platformVersion=5.1
,可能会出现如下的错误
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Failed to launch Appium Settings app: Condition unmet after 5090 ms. Timing out.
解决方案是升级系统版本。参考地址:https://github.com/appium/appium/issues/12901
在终端下运行命令appium -a 127.0.0.1 -p 4723
,启动appium
appium -a 127.0.0.1 -p 4723
[Appium] Welcome to Appium v1.14.2
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
运行Python脚本,在appium的运行日志中出现[HTTP] <-- POST /wd/hub/session 200
;说明app在模拟器中启动成功。
Appium 测试遇到问题解决方案
问题一:org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
解决办法:
(1)启动appium
(2)运行cmd 输入 adb devices -l 查看UDIDadb devices -l List of devices attached 192.168.34.xx:5555 device product:vbox86p model:Samsung_Galaxy_S9 device:vbox86p transport_id:7
(3)再在cmd中输入 appium -a 127.0.0.1 -p4723 -USamsung_Galaxy_S9 (-a表示ip,-p表示端口,-U表示设备的udid 可以通过appium -h查看更多命令)
C:\Users\hj>appium -a 127.0.0.1 -p4723 -USamsung_Galaxy_S9 [Appium] Welcome to Appium v1.14.2 [Appium] Non-default server args: [Appium] address: 127.0.0.1 [Appium] udid: Samsung_Galaxy_S9 [Appium] Deprecated server args: [Appium] -U,--udid => --default-capabilities '{"udid":"Samsung_Galaxy_S9"}' [Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities: [Appium] udid: Samsung_Galaxy_S9 [Appium] Appium REST http interface listener started on 127.0.0.1:4723
(4)表示 appium服务启动成功了,注意这个窗口不要关闭 因为这是appium的服务 关了就关了服务,后面过程无法执行,而且这个窗口也是 日志输出的窗口用于排错。
问题二:org.openqa.selenium.SessionNotCreatedException: A new session could not be created.
(Original error: Device ZX1C622BU3 was not in the list of connected devices)
(WARNING: The server did not provide any stacktrace information)解决办法:可能手机驱动未安装成功,虽然在adb devices中可以正常查看到devices
问题三:
问题:org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Waited 20 secs for selendroid server and it never showed up)解决办法:
查看包的签名的和Activity
例如:APP从I5版本后启动界面的capabilities.setCapability(“appActivity”, “.CordovaApp”);
从I5版本后Acitivity变成了MainActivity
capabilities.setCapability(“appActivity”,".MainActivity");// 被测app的Activity类问题四:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)解决方法:
查看设备上是否安装Selendroid,或者升级SelendroidIOS问题五:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)解决办法:IOS_webkit_debug_proxy –c –[Udid] -d