appuim框架二次封装-UI自动化-自整理亲自实践

IDE下载(eclipse/IDEA等)

IDEA的下载地址 (IDEA下载社区版-Community就够用)(用例是用java来编写)

备注:建议用IEDA,在编写用例的时候,效率会高很多

 

Maven下载与配置

maven下载:

apache-maven-3.3.3.zip(8.2 MB)

Mac OS X 安装Maven:

  • 下载 Maven, 并解压到某个目录。例如/Users/robbie/apache-maven-3.3.3

  • 打开Terminal,输入以下命令,设置Maven classpath

     $ vi ~/.bash_profile
    

    添加下列两行代码,之后保存并退出Vi
    export M2_HOME=/Users/robbie/apache-maven-3.3.3
    export PATH=$PATH:$M2_HOME/bin

bash_profile

  • 输入命令以使bash_profile生效
    $ source ~/.bash_profile

  • 输入mvn -v查看Maven是否安装成功

  • 如果遇到以下异常,重新编辑bash_profile文件,增加export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home后,并重新运行$ source ~/.bash_profile即可

exception

new bash_profile

 

maven配置方法:http://www.jianshu.com/p/191685a33786 ,详见https://lark.pay.com/oeqy62/sgffza/gma0o5(用例是maven来执行,maven配置异常,会导致依赖的jar包下载不下来,建议使用本文档中提供的maven,本文档中提供的maven中的settings.xml做过修改,能拉取到公司内部的jar包)

Maven的下载与配置方法

maven的下载

apache-maven-3.3.3.zip(8.2 MB)

maven的配置

环境变量中maven的配置

http://www.jianshu.com/p/191685a33786

 

编辑器中maven的配置

eclipse中maven配置,如下图所示

 

 

 

IDEA中maven配置,如下图所示

 

 

** 如果配置完之后,bizlib 还未下载下来,则:对比一下我们这边的maven中settings文件和你们实际用的的maven,将你们没有的拷贝过去一份 **

 

JDK安装

  1. JDK(1.8版本)

 

iOS自动化需要额外配置的环境:

硬件:Mac OS 10.10+的Mac电脑 iOS9.0+的iPhone设备

软件:

1. Xcode8.0+(测试采用XCUITest,XCUITest是在iOS9.0以后才提供)。

推荐使用Xcode10.1版本最为稳定。任意版本Xcode下载地址 https://developer.apple.com/downloads/  无需苹果开发者权限,普通的苹果账号登录即可。

2.下载node,下载命令:brew install node(用于起自动化服务)

3. 手机的键盘需要用系统键盘,不能设置为第三方的(当有输入的场景时,用第三方的键盘会导致输入失败)

4. 建议测试机上只安装一个支付宝,避免导致目标的被测包不能切换的环境

5. 如果是运行ios H5的,则需要额外按照 https://lark.pay.com/oeqy62/sgffza/fhl782 中配置环境

6. 安装xcode命令行工具

xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

 

IOS注意事项

  1. ios第一次运行case时,用于自动化的服务(wda)会因为证书问题导致启动失败,需要按照https://lark.pay.com/oeqy62/sgffza/yalng0 进行设置

  1. 电脑上最好不要安装两个xcode,当有两个xcode时,会出现很多诡异的问题

  1. 手机需要用系统自带的输入法(用第三方的输入法会导致输入异常!!!)

 

 

Android自动化需要额外配置的环境:

  1. android sdk的下载与配置:

https://developer.android.com/studio/index.html (推荐通过Android studio下载android sdk)

操作步骤(以mac环境为例):

1

 

3. 加环境变量

vi ~/.bash_profile
export ANDROID_HOME=/Users/xiaoche/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools

 

也可以参考下面的链接:

    Mac os环境:  mac配置adb

Windows环境:windows配置adb

⚠️:由于很多命令有兼容性,暂不推荐windows环境运行

===================================自整理部分=================================

 

iOS 审核脚本UI自动化

Xcode苹果iOS开发者账号申请   https://jingyan.baidu.com/article/48b37f8d61b5e41a646488f0.html

xcode下载地址   https://developer.apple.com/

iOS远程真机之usbmuxd中iproxy的作用   https://blog.csdn.net/yxys01/article/details/77188976

在此之前,需要打开xcode-product-test 

在终端输入 iproxy 8100 8100,等连接之后,在浏览器输入http://127.0.0.1:8100/inspector  

浏览器输入本地IP(默认端口8100),回车,可正常显示iOS上APP的组件元素

 

如遇以下报错,需要在xcode-product-test一下,是因为连接断了,test一下就连接上了

正常连接成功,iproxy日志正常

 

详细环境搭建步骤:

 

WebDriverAgent中证书的配置

修改WebDriverAgent里面证书的配置

注:如果是在真机上测试,则需要配置证书,如果是在模拟器上,请忽略

 

在第一次打开运行case启动WebDriverAgent的服务时,会因为证书的问题导致服务起不来,请按照如下操作配置:

 

  1. 打开WebDriverAgent(如果发现没下面目录,则说明WDA的源码未下载成功,请先配置git的sshkey)

    cd  ~/xx/xxWDA/WebDriverAgent
    open WebDriverAgent.xcodeproj

     

  1. Xcode -> Preferences -> Accounts 添加一个Apple ID(如果已经添加过,则忽略)

  1. 我们需要为以下地方配置证书。如下图

   (1)如下图中的步骤

General-Signing-Team   选择个人AppleID
General-Identity-Bundle Identifier   重命名,如拼接日期
 

 

如果出现以下情况,

点击

然后选择到以下:

配置证书:

 

 

(2)如果出现以下错误,则先Add Account(这块为apple Id 账户)(如果没有,则忽略此步骤)

 

 

当如下图所示时,则说明Add Account成功了

 

 

(3) 在Team处,选择一个appleId,当出现以下错误时:

 

点击到“Build Settings”中如下设置

 

随意在com.pay.xxWDA.WebDriverAgent后面添加当天的月日时时间(比如:112209),返回到General中,看“Automatically manage signing”中是否报错,如果还报错,则重新设置com.pay.xxWDA.WebDriverAgent,直致“Automatically manage signing”中不报错为止

(这块是和苹果服务器在做校验,有时候会校验不通过,需要多试几次,每次尝试的时候,建议在原来的基础上加1,可能会增加校验通过的概率)

以下为不报错情况:

 

WDAMonito和WDAMonitorUITest也需要设置

处理完成后证书错误的信息不再显示

 

配置完之后,如下图所示,运行一下,看是否配置成功

 

 

运行成功(不报错)后,关闭掉WebDriverAgent的工程(终止掉test),再运行case

(原因:执行case时,会通过命令行的方式启动WebDriverAgent服务,和直接在xcode工程中运行是互斥关系)

 

以下为可能出现的异常情况:

1. 如果出现如下图错误,则到手机设置中信任下证书

 

如果出现以下截图,则将手机上的WebDriveragent应用给删除掉后,再运行一

 

成功后运行,xcode-product-test

 

如遇

Could not launch WebDriverAgent

Soku has denied the launch request.

Internal launch error: process launch failed: Unspecified

具体步骤为: 钥匙串访问 -> 钥匙串访问 -> 证书助理 -> 从证书颁发机构请求证书……

参考

https://www.jianshu.com/p/57bea4d581de

方案三:

证书 + 项目运行缓存,动作路径如下:

  1. 手动删除 Derived data 下的文件,在“前往文件夹”中输入/Users/用户名/Library/Developer/Xcode/DerivedData,或者终端下 open /Users/用户名/Library/Developer/Xcode/DerivedData,删除文件夹下文件;
  2. 钥匙串里,删除 Apple Worldwide Developer Certification,PS:钥匙串的‘登陆’‘系统’里,有时会同时存在这个证书,记得都删除;然后下载最新的 Apple Worldwide 证书;证书下载链接
  3. 如果还不好使,建议删除钥匙串里所有开发中证书,包括 Development 的,以及 Distribution 的;然后重新下载;

最后:附上原问题 stackoverflow链接,大家可以自行参考;

 

 

IOS Inspector工具

详见:https://yuque.antfin-inc.com/oeqy62/sgffza/rop4de

 

备注:

  1. 运行之前需要将“网络加速”关闭掉~

  1. 在ios9.3.4的设备上用inspector工具时,响应会很慢,需要多等待一会

  1. 在ios10.2.1的设备上使用inspector工具,很多控件的属性是“ AX error -25205”,这块是系统导致的显示问题

  1. 当手机页面变化时,刷新页面,也获取到手机当前页面的inspector数据

 

IOS应用安装卸载指南

iOS应用安装卸载方式:

步骤1:打开xcode

 

 

步骤2:点击“window” -> "Devices and Simulatiors",可看到下图所示

 

 图中说明:

 

Identifier

设备的Udid(唯一标识) -- 在自动化的Udid

 

INSTALLED APPS

可查看到当前设备上安装的应用信息,Identifier为应用的唯一标识 -- 自动化的PACKAGE

 

+

点击“+” -- 安装应用

 

-

选中需要卸载的应用,再点击“-” -- 卸载应用

 

View Device Logs

点击可查看到设备上所有的闪退信息

 

 

 

抢先版WDA手动部署办法

1,克隆抢先版WDA到本地xx下/Users/qa/xx文件路径

git clone git@gitlab.xx.xx.xy/WebDriverAgentAlpha.git

克隆好之后双击打开WebDriverAgentAlpha/WebDriverAgent.xcodeproj进行证书配置

 

注意和老版本的只有1个targit不同,新版本有3个targit都需要配置证书信息。

 

 

2,下载附件并解压缩到任意位置

 

3,停止正在执行的任务.终端执行

pkill -9 xx
pkill -9 xcodebuild

 

4,清理旧的xx目录,终端执行。

 

sh <(curl -s http://firm-cooperation-system.cn-hangzhou.pay.inc.com/agent/bin/installer.sh)

出现如下图所示,表示清理成功,即可关闭TTRService窗口。

 

5,替换xx文件

cd ~/xx/xxService/exec

open .

删除目录下的xx文件,并将刚下载的附件xx粘贴到这个文件夹内。

 

cd ~/xx/xxService
git add .
git commit -m"替换xx"
git pull

当出现Already up to date.表示xx替换成功

 

6,替换WDA

 

cd ~/xx/xxWDA/WebDriverAgent

open .

重要:如果电脑可以显示隐藏文件,需要同时按键盘上的command+shift+. 将隐藏文件隐藏起来。目的是下面的操作不要删除掉.git文件。

删除WebDriverAgent目录下除.git之外的所有文件。

复制步骤1中下载好的抢先版wda文件到本目录。(同样不要复制.git)

 

 

复制完成后

 

cd ~/xx/xxWDA/WebDriverAgent

git add .

git commit -m"替换抢先版WDA"

git pull

当出现 Already up to date. 表示wda替换成功。

 

到此抢先版WDA配置完成。

 

 

更新

当抢先版WDA有更新时,重新执行步骤1和步骤6即可。

================================================================================================================================================================================================

与RD沟通后最终版优化,用正式版的wda

xx iOS WDA更新及配置方法

1,停止本地正在执行的测试任务,然后终端执行 pkill -9 xx 。(如未安装过xx请略过次步骤)

2,删除手机中的WebDriverAgentRunner并重启手机。(如未安装过xx请略过次步骤)

3,终端执行脚本:

sh <(curl -s http://firm-cooperation-system.cn-hangzhou.pay.inc.com/agent/bin/installer.sh)

4,出现如下图所示

 

5,设置正确的证书即可。如果不会配置证书可以参考

https://yuque.antfin-inc.com/oeqy62/sgffza/yalng0

备选方案

如果步骤3执行后无法出现步骤4所提示的内容,则可以使用备选方案。

 

1,下载附件

xxClient.zip(300 kB)

2,解压缩到桌面

3,执行命令

cd ~/Desktop/
chmod +x xxClient
~/Desktop/xxClient -s

 

当看到downloadWDA finished!!两个终端窗口就都可以关闭了。

================================================================================================================================================================================================

wda1.1.0本地更新注意事项

本地更新变动包括:

1,缓存机制升级,WDA占用内存过大时会自动清空缓存。

2,自动恢复机制,由于内存等原因造成WDA挂掉,会自动回复现场并继续运行。

3,scheme跳转不再通过Safari,而是通过WDAMonitor进行切换,避免了由于浏览器不在初始状态或输入错误等问题造成跳转失败的情况。

4,运行速度更快。

5,OCR算法库更新,功能更强大,体积更小。

6,修复已知bug。

 

理论上是会自动更新的,如果因为特别情况没有自动更新,可以使用如下方法手动更新:https://yuque.antfin-inc.com/oeqy62/sgffza/ouswas

 

判断是否更新成功,可以通过查看version.txt内容,为1.1.0表示升级成功。

vim ~/xx/xxWDA/WebDriverAgent/version.txt

 

如果wda仍然失败,则使用RD给的脚本 手动部署

➜  ~ chmod 777 xxEnvCheck
➜  ~ /Users/xx/xxEnvCheck -a

本次wda更新变动较大,本地适配需要注意如下几点

1,三个targit均需要设置签名信息。证书设置方法https://yuque.antfin-inc.com/oeqy62/sgffza/yalng0

open ~/xx/xxWDA/WebDriverAgent/WebDriverAgent.xcodeproj/

 

 

 

2,手动启动WDA时需要选择WDAMonitor

    后执行Project->Test

 

 

3,打开WDAMonitor的时候会先显示WDA异常,过几秒就会恢复正常。

 

4,首次打开WDAMonitor会询问网络权限,需要手动点击允许。

 

5,第一跳转Scheme的时候会出现“授权”,手动点击打开或者等待自动打开。

6,使用模拟器进行调试时,需要先打开模拟器再启动任务。

 

常见问题:

现象:用例运行失败,反复进行安装WDA但无法成功。

问题:由于之前WDA运行需要安装1个APP,新版WDA运行需要安装两个APP,个人签名的用户可能会出现APP安装过多无法继续安装的问题。

解决办法:卸载掉原有的WebDriverAgent app和手机中其他使用个人证书签名的APP。

 

如遇报错,

 

真机调试问题
Your maximum App ID limit has been reached. You may create up to 10 App IDs every 7 days.
你的App ID超过了最大限制,7天最多能创建10个App ID

解决办法:出现这种情况,直接用上一次的Bundle ID就行了,因为免费App ID账号苹果官方有所限制。这个时候你不管怎么改变Bundle ID都没有用,直接更换以前调试过的Bundle ID,就可以搞定了,建议每创建Bundle ID就记录一下,当出现这种问题的时候直接更换就可以了

inspect经常会断开连接,安装appium代替

安装 Node.js

在终端输入命令:brew install node 并回车,将默认安装 Node.js 最新版本,如需安装制定版本,可到官网 https://nodejs.org/en/download/ 下载对应版本 .pkg 包安装

安装完成后,使用命令 node -v 和 npm -v 查看版本,检查是否安装成功

如遇Error: node 12.4.0 is already installed
To upgrade to 12.5.0, run `brew upgrade node`.
➜  ~ brew upgrade node

配置 npm 淘宝源:

终端使用命令:npm config set registry https://registry.npm.taobao.org

检查是否配置成功使用命令:npm config get registry

使用 npm 安装 appium

npm 全局安装 appium,使用命令(默认安装最新版本):

npm install appium -g --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver

如需安装指定 appium 版本可在 appium后加@版本号,如安装1.7.2版本:

npm install appium@1.7.2 -g

由于 chromedriver 下载易不成功,故指向淘宝 cdn 下载。

安装 appium 完成后,继续安装 appium-doctor

npm install appium-doctor -g

使用命令 appium-doctor 检查 appium 环境是否完整,发现仍然缺少 Carthage。

继续使用 Homebrew 来安装 Carthage,命令:

brew intall Carthage

直到 appium-doctor 检查所有配置均已正确即表示安装成功:

 

如果遇到失败(其实不需要全部为对勾,只需要Android iOS的环境正确即可)

~ vim ~/.bash_profile

检查如下配置

修改完记得source

➜  ~ appium-doctor
info AppiumDoctor Appium Doctor v.1.10.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ Node version is 12.5.0
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor  ✔ HOME is set to: /Users/xx
info AppiumDoctor  ✔ ANDROID_HOME is set to: /Users/xx/Library/Android/sdk
info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
info AppiumDoctor  ✔ adb exists at: /Users/xx/Library/Android/sdk/platform-tools/adb
info AppiumDoctor  ✔ android exists at: /Users/xx/Library/Android/sdk/tools/android
info AppiumDoctor  ✔ emulator exists at: /Users/xx/Library/Android/sdk/tools/emulator
info AppiumDoctor  ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
info AppiumDoctor  ✔ Python required by node-gyp (used by heapdump) is installed at: /usr/bin/python. Installed version is: 2.7.10
WARN AppiumDoctor  ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor  ✖ ffmpeg cannot be found
WARN AppiumDoctor  ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor  ✖ fbsimctl cannot be found
WARN AppiumDoctor  ✖ applesimutils cannot be found
WARN AppiumDoctor  ✖ idevicelocation cannot be found
WARN AppiumDoctor  ✖ ios-deploy cannot be found
WARN AppiumDoctor  ✖ ios_webkit_debug_proxy cannot be found
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 9 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  ➜ Why fbsimctl is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor  ➜ Why applesimutils is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor  ➜ idevicelocation is used to set geolocation for real device. Please read https://github.com/JonGabilondoAngulo/idevicelocation to install it
WARN AppiumDoctor  ➜ ios-deploy is used to install iOS applications to real device. Please read http://appium.io/docs/en/drivers/ios-xcuitest-real-devices/ to install it
WARN AppiumDoctor  ➜ ios_webkit_debug_proxy is used to proxy requets from Appium to MobileSafari running on real device. Please read https://github.com/google/ios-webkit-debug-proxy to install it
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
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor

以上都很简单,下面重点来了 ,参考博客:https://www.jianshu.com/p/efa9ac4900a6

appium服务端安装:安装appium-xcuitest-driver依赖,进入WebDriverAgent安装目录,运行bootstrap

$ cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent (如果WebDriverAgent 所在路径和此不同,请自行查找)

$ mkdir -p Resources/WebDriverAgent.bundle

$ sh ./Scripts/bootstrap.sh

Appium iOS 环境搭建篇,参考博客

https://testerhome.com/topics/15617

如遇如下报错,则升级xcode

如何在xcode查找UDID

1.连接USB 在MAC 上

2.打开Xcode

3.点击Window---->Devices--->在右侧可查看到identifier

identifier即为我们获取到的iPhone 的UDID

iOS
{
  "platformName": "iOS",
  "platformVersion": "12.1.1",
  "deviceName": "MNGQ2CH/A",
  "udid": "13babfe00af5de86c1a85959d3539eb6d1a125c4",
  "app": "com.xx.xx"
}
Android
{
  "platformName": "Android",
  "platformVersion": "8.0.0",
  "deviceName": "f77bd29d",
  "app": "com.miui.calculator",
  "noReset": true,
  "appActivity": ".Calculator"
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

东方狱兔

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

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

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

打赏作者

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

抵扣说明:

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

余额充值