appium、夜神模拟器 环境配置 出现报错 整理及其解答

环境配置

配置Java环境,JAVA_HOME多参考确保配置正确

Android SDK包下载

SDK环境配置

在这里插入图片描述
其他几个路径配置到系统环境Path中如下图所示:

在这里插入图片描述
配置检测

在cmd界面输入“adb” 和"appt"来判断安装是否成功。
adb命令
C:\Users\Shuqing>adb
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as E:\Andriod_sdk\platform-tools\adb.exe

global options:
 -a         listen on all network interfaces, not just localhost
 -d         use USB device (error if multiple devices connected)
 -e         use TCP/IP device (error if multiple TCP/IP devices available)
 -s SERIAL
     use device with given serial number (overrides $ANDROID_SERIAL)
 -p PRODUCT
     name or path ('angler'/'out/target/product/angler');
     default $ANDROID_PRODUCT_OUT
 -H         name of adb server host [default=localhost]
 -P         port of adb server [default=5037]
 -L SOCKET  listen on given socket for adb server [default=tcp:localhost:5037]

aapt命令
C:\Users\Shuqing>aapt
Android Asset Packaging Tool

Usage:
 aapt l[ist] [-v] [-a] file.{zip,jar,apk}
   List contents of Zip-compatible archive.

 aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]
   strings          Print the contents of the resource table string pool in the APK.
   badging          Print the label and icon for the app declared in APK.
   permissions      Print the permissions from the APK.
   resources        Print the resource table from the APK.
   configurations   Print the configurations in the APK.
   xmltree          Print the compiled xmls in the given assets.
   xmlstrings       Print the strings of the given compiled xml assets.

夜神模拟器安装配置

下载
操作步骤

1.下载成功之后点击安装包。
2.安装成功之后会默认启动一个模拟器,基于Andriod 4.4.2系统
3.关闭该模拟器,找到桌面生成的“夜神多开器”图标,点击打开。
4.点击底部“添加模拟器” 然后选择全新模拟器Android 5.1.1 等待下载安装完成。
5.点击启动模拟器按钮即可成功启动模拟器,默认是平板屏幕模式,可以通过设置切换为手机模式。

多开新手教
开启VT
VT是什么?为什么要开启VT?
VT,全称是Virtualization Technology,即是虚拟化技术,虚拟化技术可以扩大硬件的容量,简化软件的重新配置过程。CPU的虚拟化技术可以单CPU模拟多CPU并行,允许一个平台同时运行多个操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率。
VT开启教程

appium环境搭建

环境依赖

Node.js
Appium
Appium-desktop
Appium-doctor
Appium-Python-Client
Python
JDK
Andriod SDK

安装Node.js

下载地址
注意:Node.js版本要注意与Appium兼容,本套教程Appium版本是1.7.2,则选择的Node.js版本为6.11.3
安装完成后在按键Win+R输入cmd打开Windows 命令提示符,
输入如下命令:
C:\Users\Shuqing>node -v
v6.11.3

C:\Users\Shuqing>npm -v
3.10.10
说明:
npm(node package manage)是node.js安装包管理工具,类似Python中的pip工具。
如果显示‘npm’不是内部命令提示,则可以管理员省份运行cmd,如果还是失败,则需要检查一下环境变量是否配置,或者重新安装nodejs。

Appium 安装

Appium Server其实可以通过命令 npm install -g appium来安装。不过由于众所周知的网络原因,直接使用这样安装会非常非常慢,甚至会安装失败,所以我们可以使用国内镜像来安装。
镜像设置

npm install -g cnpm --registry=https://registry.npm.taobao.org

执行完成命令看到如下提示则表示设置完成

C:\Users\Shuqing> npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
C:\Users\Shuqing\AppData\Roaming\npm\cnpm -> C:\Users\Shuqing\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm
+ cnpm@5.2.0
added 764 packages in 63.767s

appium 安装

#安装最新版本
npm install -g appium --registry=https://registry.npm.taobao.org

看到如下命令时则表示下载安装完成。

All packages installed (565 packages installed from npm registry, used 57s, speed 835.67kB/s, json 477(6.16MB), tarball 40.58MB)
[appium@1.8.0] link C:\Users\Shuqing\AppData\Roaming\npm\appium@ -> C:\Users\Shuqing\AppData\Roaming\npm\node_modules\appium\build\lib\main.js

npm的包安装分为本地安装(local)、全局安装(global)两种,一般我们推荐使用全局安装。
appium配置
安装完成之后可以使用如下命令查看appium的安装路径

C:\Users\Shuqing>where appium
C:\Users\Shuqing\AppData\Roaming\npm\appium
C:\Users\Shuqing\AppData\Roaming\npm\appium.cmd

appium运行

在控制台输入命令 appium即可启动appium服务,appium -v查看版本

C:\Users\Shuqing>appium -v
1.7.2

C:\Users\Shuqing>appium
[Appium] Welcome to Appium v1.7.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

如果输入appium后显示:“appium不是内部或外部命令,也不是可运行的程序或批处理文件” 可以将appium安装的路径 如: “C:\Users\Shuqing\AppData\Roaming\npm”配置到系统环境变量Path中

安装Appium-desktop

下载地址
上面提到的问题可以使用前面我们已经介绍了Appium Server来解决,Appium-desktop工具其实也封装了Appium server和Node.js依赖环境。
appium-desktop是我们初学者最容易上手的工具,后面课程首先会基于这个工具来讲解!然后再基于appium 命令来讲。

python环境安装配置

参考

安装Appium-Python-Client

通过命令: pip install Appium-Python-Client 进行安装。 安装后可以通过如下命令来检测是否安装成功。
输入命令“from appium import webdriver” 回车,如果控制台没有报错,则说明安装成功。

安装 appium-doctor

appium-doctor可以检测Appium整体依赖环境配置情况。

C:\Users\Shuqing>cnpm install appium-doctor -g

在控制台输入命令:appium-doctor 看到如下提示说明整体环境配置成功。

C:\Users\王蕴奥>appium-doctor
info AppiumDoctor Appium Doctor v.1.16.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: D:\Andriod_SDK\node.EXE
info AppiumDoctor  ✔ Node version is 16.12.0
info AppiumDoctor  ✔ ANDROID_HOME is set to: D:\Andriod_SDK
info AppiumDoctor  ✔ JAVA_HOME is set to: D:\JAVA
info AppiumDoctor    Checking adb, android, emulator
info AppiumDoctor      'adb' is in D:\Andriod_SDK\platform-tools\adb.exe
info AppiumDoctor      'android' is in D:\Andriod_SDK\tools\android.bat
info AppiumDoctor      'emulator' is in D:\Andriod_SDK\tools\emulator.exe
info AppiumDoctor  ✔ adb, android, emulator exist: D:\Andriod_SDK
info AppiumDoctor  ✔ 'bin' subfolder exists under 'D:\JAVA'
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor  ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor  ✖ ffmpeg cannot be found
WARN AppiumDoctor  ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
WARN AppiumDoctor  ✖ gst-launch-1.0.exe and/or gst-inspect-1.0.exe cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 5 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor  ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md
WARN AppiumDoctor  ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor  ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'.
WARN AppiumDoctor  ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it. Also consider adding the ".jar" extension into your PATHEXT environment variable in order to fix the problem for Windows
WARN AppiumDoctor  ➜ gst-launch-1.0.exe and gst-inspect-1.0.exe are used to stream the screen of the device under test. Please read https://appium.io/docs/en/writing-running-appium/android/android-screen-streaming/ to install them and for more details
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!

第一个测试脚本

测试环境

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={}
desired_caps['platformName']='Android'

#模拟器设备
desired_caps['platformVersion']='5.1.1'
desired_caps['deviceName']='127.0.0.1:62025'

#mx4真机
# desired_caps['platformVersion']='5.1'
# desired_caps['deviceName']='MX4'
# desired_caps['udid']='750BBKL22GDN'

desired_caps['app']=r'C:\Users\Shuqing\Desktop\kaoyan3.1.0.apk'

desired_caps['appPackage']='com.tal.kaoyan'
desired_caps['appActivity']='com.tal.kaoyan.ui.activity.SplashActivity'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

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服务
出现一下错误按下文配置

Original error: 'GET /appium/device/pixel_ratio' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed).

Running 'D:\Andriod_SDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62001 reconnect offline

appium Original error: Could not extract process ID of 'io.appium.settings'

Android SDK 的adb命令(首先连接设备adb connect 127.0.0.1:62001;然后查看连接设备列表adb devices)查询不到连接的设备,但是夜神模拟器安装目录bin目录下使用nox_adb命令(首先连接设备nox_adb connect 127.0.0.1:62001;然后查看连接设备列表nox_adb devices)可以看到这里展示了已连接的设备。一般原因是Android SDK的adb的版本和夜神模拟器bin目录下的不一致(或相差太多不匹配)造成的,解决方法如下:

1、第一步,将Android SDK安装目录的platform-tools文件夹下adb.exe文件复制一份出来,复制到夜神模拟器的安装目录bin目录下覆盖里面的nox_adb.exe,因为夜神模拟器目录下原本的adb文件名字叫做nox_adb.exe,因此复制过去之后也得改名为nox_adb.exe。

(可能会遇到这样的情况:夜神模拟器安装目录的bin目录下本来就有一个adb.exe文件还有一个nox_adb.exe文件,这个时候我的操作是,先将Android SDK里面的adb.exe文件复制到桌面一份进行重命名,改成nox_adb.exe,然后再将这个文件粘贴到夜神模拟器安装目录bin目录里进行覆盖原有的nox_adb.exe文件,【这时我又遇到了不能讲文件移动至此目录下的提示,解决办法:打开任务管理器,杀掉nox_adb.exe后台进程立刻进行刚才的复制改名成nox_adb.exe的文件覆盖夜神模拟器安装目录bin目录里夜神模拟器安装目录bin目录里,哈,ok了】)。

原文链接:https://blog.csdn.net/user_dongdong/article/details/107560749

Toast简介

Android中的Toast是一种简易的消息提示框。 当视图显示给用户,在应用程序中显示为浮动。和Dialog不一样的是,它永远不会获得焦点,无法被点击。
Toast类的思想就是尽可能不引人注意,同时还向用户显示信息,希望他们看到。而且Toast显示的时间有限,一般3秒左右就消失了。因此使用传统的元素定位工具,我们是无法定位到Toast元素的(传说中低调奢华有内涵)。
Appium Toast内容获取
Add ability to verify TOAST messages (these can’t be interacted with, only text retrieval allowed)
Appium 1.6.3开始支持识别Toast内容,主要是基于UiAutomator2,因此需要在Capablity配置如下参数:

desired_caps['automationName']='uiautomator2'

安装appium-uiautomator2-driver: 安装命令如下:

cnpm install appium-uiautomator2-driver

问题参考:https://www.cnblogs.com/-ming/p/12085311.html

安装selenium模块

pip install selenium

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
你好!对于使用Python和Appium夜神模拟器进行自动化测试,你可以按照以下步骤进行操作: 1. 安装Appium:使用pip命令安装Appium库。在命令行输入以下命令: ``` pip install Appium-Python-Client ``` 2. 安装夜神模拟器:你需要先在电脑上安装夜神模拟器,并确保它可以正常运行。 3. 配置Appium连接夜神模拟器:在代码中设置Appium连接夜神模拟器的相关参数,例如设备名称、设备版本、App包名和启动Activity等。 4. 编写测试脚本:使用Python编写Appium测试脚本。你可以使用Appium提供的API来控制模拟器的操作,如启动应用、查找元素、点击按钮等。 以下是一个简单的示例代码,用于启动夜神模拟器上的应用并点击按钮: ```python from appium import webdriver desired_caps = { 'platformName': 'Android', 'deviceName': '夜神模拟器', 'platformVersion': '夜神模拟器的版本号', 'appPackage': '应用的包名', 'appActivity': '应用的启动Activity' } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 查找元素并点击按钮 button = driver.find_element_by_id('按钮的id') button.click() # 关闭模拟器连接 driver.quit() ``` 请确保你已经正确安装了Appium夜神模拟器,并且使用正确的参数来配置连接。这只是一个简单的示例,你可以根据自己的需求进行扩展和修改。 希望对你有所帮助!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yuno Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值