Appium_4_常见报错&解决方案

测试环境

  • Win 10 64bit
  • Python 3.5
  • Appium 1.7.2
  • Andriod 5.1.1 模拟器& Android 5.1 MX4
  • 测试App:考研帮Android版 3.1.0

测试场景

自动安装考研帮App(kaoyan3.1.0.apk),然后启动App

测试步骤

  • 获取待测试app的packageName和Activity
  • 配置Capability
  • 连接设备
  • 编辑脚本并运行
  • 查看结果

运行前检查事项

  1. 检查设备是否连接
  2. 检查Appium server是否启动
  3. 检查Capability配置信息是否正确

测试脚本

from  appium import webdriver

desired_caps={'platformName':'Android',
              'platforVersion':'4.2.2',
              'deviceName':'127.0.0.1:62001',
              'appPackage':'com.tal.kaoyan',
              'appActivity':'com.tal.kaoyan.ui.activity.SplashActivity',
              'noReset':'true'}
#mx4真机
# desired_caps['platformVersion']='5.1'
# desired_caps['deviceName']='MX4'
# desired_caps['udid']='750BBKL22GDN'
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

    1.首次启动Appium会在设备上安装2个守护app,Appium Settings和Unlock 部分设备系统由于权限的问题(如:三星S6 edge+)需要用户手动确认安装,否则不安装守护App会导致脚本运行失败,安装好后不要随意卸载这两个App。

  • Unlock :用于解锁手机弹窗提示
  • Appium Setting:Appium守护app

         2.from appium import webdriver 中的webdriber模块和selenium中的webdriver模块不一样!

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

【解决方案】

  • launchable activity 写错更正即可。
  • 如果是存在此activity,则一定是AndroidMainfest.xml.xml中,当前activity设置的属性exported=false,表示当前activity无法被外部程序唤醒。(appium无法唤醒此类)需要研发人员去修改参数。

 

系统权限问题

Failure [INSTALL_FAILED_USER_RESTRICTED])

【解决方案】

  1. USB安装管理权限限制,关闭即可。
  2. 开启安装允许未知来源app选项

服务异常

An unknown server-side error occurred while processing the command while opening the App

【解决方案】重新启动Appium服务

 

猜你喜欢

转载自blog.csdn.net/qq_42758861/article/details/82178267
今日推荐