测试环境
测试场景
自动安装考研帮App(kaoyan3.1.0.apk),然后启动App
测试步骤
运行前置条件
代码如下:
# -*- coding: utf-8 -*
from appium import webdriver
desired_caps={}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = '127.0.0.:62026'
desired_caps['platforVersion'] = '5.1.1'
desired_caps['app'] = r'D:\download\kaoyan3.1.0.apk'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps[''] = 'com.tal.kaoyan.ui.activity.SplashActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
pycharm常用快捷键
1.首次启动Appium会在设备上安装2个守护app,Appium Settings和Unlock 部分设备系统由于权限的问题(如:三星S6 edge+)需要用户手动确认安装,否则不安装守护App会导致脚本运行失败,安装好后不要随意卸载这两个App。
webdriver模块源码路径:
{python安装路径}}\Lib\site-packages\appium\webdriver
Appium报错&解决方案——那些年我们踩过的坑
Appium服务未启动
urllib.error.URLError: <urlopen error [WinError 10061] 由于目标计算机积极拒绝,无法连接。
【解决方案】点击启动Appium按钮后,出现[Appium] Welcome to Appium v1.7.2提示后再运行脚本
会话冲突
error: Failed to start an Appium session, err was: Error: Requested a new session but one was in progress
【报错分析】 之前的会话没有关闭,然后你又运行了测试实例,也没有设置覆盖.
【解决方案】 重新停止appium服务,开启Appium服务 在AdVance界面勾选Allow Session Override选项 ,重启Appium 测试结束在AfterClass加driver.quit()
未安装java环境
selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: 'java -version' failed. Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "java -version"
设备未连接
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device.
【解决方案】由于设备未连接,或者连接后未开启USB Debug。需要重新连接设备即可。
更换手机设备后如下对应的属性要记得更新,否则无法正常运行脚本。
desired_caps['platformVersion'] = 'XXX'
desired_caps['deviceName'] = 'Galaxy S6 edge+'
launchable activity 值写错
Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
【解决方案】
系统权限问题
Failure [INSTALL_FAILED_USER_RESTRICTED])
【解决方案】
服务异常
An unknown server-side error occurred while processing the command” while opening the App
【解决方案】重新启动Appium服务