Test mobile base end (1)



First, the mobile terminal testing Introduction

1.1 Test defined movement end

  • Mobile-end testing refers to testing for mobile applications that meet the needs of the characteristics of an entity (product documentation, implicit demand) degree

1.2 Test mobile terminal classification

1.2.1 app functional testing

1. The service logic test correctness

  • Product Documentation
  • Implicit Demand

= Write => test

2. Compatibility Test

prompt:

name Explanation
system version ➢ Android

official, Lenovo, Huawei and other

➢ IOS

official
Resolution ➢720p

720x1280

➢ 1080p

1080x1920

➢ 2k

2560x1440
Network conditions 2G ➢

➢ 3G

➢ 4G

➢ a Wi-Fi

3. abnormal test

  • Application of hot start
    applications in the background handover = => foreground process
  • Network switches & interruption recovery
  • Phone or interruption recovery information

4. upgrades, installation, uninstallation test

(1) upgrade
system upgrade, upgrade channel, near the version (1.0> 1.1), cross-version (1.0> 1.5)

(2) install
the system version, the first installation, covering installation, uninstall

(3) unloaded
unloading -> Installation -> Uninstall

5. Robustness Testing

  • Phone resource consumption
    CPU, memory
  • Traffic consumption
    picture, transmission data compression
  • Crash recovery test
    flash back, the error (stop running)
  • ...

1.2.2 app automated testing

  • And data through preset scene, the human-driven behavior test into the machine to perform a process in
  • Repetitive machine work to do
  • The liberation of some people to do new functional testing and exploratory testing

    remind:
    • Not all functions can be automated
    • 新功能(不稳定)或很难通过脚本模拟的业务

1.2.3 app安全测试

  • 通过安全测试技术,保证app尽可能的不存在安全漏洞

二、移动端测试环境搭建

参阅:

2.1 安装JAVA

2.2 安装SDK

  • 自动化测试获取taost消息时需要对应系统版本的Android SDK Build-tools

    2.3 安装模拟器

    参阅:

三、ADB命令

3.1 ADB

Andorid Debug Bridge

  • 一个Debug工具
  • 为何称之为Bridge?
    因为adb是一个标准的C/S结构的工具, 是要连接开发电脑和调试手机的
    包含如下几个部分:
  1. Client端
    运行在开发机器中,即你的开发PC机;用来发送adb命令
  2. Daemon
    守护进程, 运行在调试设备中, 即调试的手机或模拟器
  3. Server端,
    作为一个后台进程运行在开发机器中, 即你的开发PC机. 用来管理PC中的Client端和手机的Daemon之间的通信

  • 三者之间的通信
    Client<—>Server<—>Daemon

3. 2 ADB基本命令

名称 命令
ADB
adb帮助 adb --help
启动adb server adb start-server
关闭adb server adb kill-server
获取设备号 adb devices

获取系统版本 adb shell getprop ro.build.version.release

只有一个设备就可以省略-s 设备号

ADB与手机
查看手机运行日志 adb logcat
手机shell命令行 adb shell



top

发送文件到手机 格式:adb push 电脑端文件路径/需要发送的文件 手机端存储的路径

eg:

将桌面的6809.bmp发送到手机/sdcard目录下

adb push 6809.bmp /sdcard

从手机拉取文件 格式:adb pull 手机端的路径/拉取文件名 电脑端存储文件路径

eg:

将手机/sdcard目录中的xx.png文件发送到电脑桌面

adb pull /sdcard/001.jpg C:\Users\zifeng\Desktop

获取app启动包名和启动名 手机需要先打开对应app

1. Mac/Linux

adb shell dumpsys window windows \| grep mFocusedApp



adb shell dumpsys window windows \| grep mFocusedApp \| cut -d " " -f 7



2. Windows

提示:看mFocusedApp这一行的内容

adb shell dumpsys window windows

安装app到手机 adb install 路径/xx.apk

卸载手机手机app adb uninstall 包名

获取app启动时间 格式:adb shell am start -W 包名/启动名

eg:

TotalTime:app自身启动时间

WaitTime:系统启动应用时间


四、主流的移动端自动化工具

  • 自动化工具选择的关注点
    ➢ 1. 是否支持native,webview
    ➢ 2. 是否支持获取toast
    ➢ 3. 是否支持跨应用
工具名 支持语言 支持系统 支持跨应用
Robotium Java Android 不支持
Macaca Java、Python、Node.js Android、iOS 支持
Appium Java、Python、Node.js

C#、php、perl、ruby
Android、iOS 支持

4.1 Appium

Appium是由nodejs的express框架写的Http Server,Appium使用WebDriver的json wire协议,来驱动Apple系统的UIAutomation库、Android系统的UIAutomator框架

  • 支持语言:Java、C#、Python、php、perl、ruby、Node.js
  • 支持Android和iOS系统
  • 支持跨应用

4.1.1 Appium环境搭建

1. 安装Appium

第一种方式:桌面客户端
平台 地址
Appium客户端 https://github.com/appium/appium-desktop/releases

配置

提示:

  • ANDROID_HOME为SDK Manager的安装路径

运行Appium

第二种方式:命令行

参阅:

1. 安装Node.js

提示:

  • Linux: yum install
  • Macos: brew install

查看是否安装成功
npm -v

node -v

2. 安装cnpm

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

提示:

3. 安装appium

cnpm install -g appium

提示:

  • Windows安装会提示os的模块错误,这个需要mac系统支持,不影响Windows操作使用

参阅:

4. 配置appium
  • 修改默认地址
    C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\build\lib\parser.js

  • 配置环境变量
    需要在"此电脑->属性->高级系统设置->环境变量"中配置环境变量
    ANDROID_HOME=SDK Manager所在的安装路径
5. appium-doctor(可选)

检查appium所有配置是否正确,正确表示安装和配置成功
cnpm install -g appium-doctor
appium-doctor

6. 启动appium服务

appium &

启动参数 说明 另一种写法
-a 指定监听的ip --address
-p 指定监听的端口,也可以修改为你需要的端口 --port
--session-override 指覆盖之前的session
-bp 是连接Android设备bootstrap的端口号,默认是4724 --bootstrap-port
--chromedriver-port chromedriver运行指定的端口号,默认是9515
-U 连接的设备的设备号,获取方式:

adb devices
--udid

eg:

appium -a 127.0.0.1

appium -a 127.0.0.1 -p 4723 -bp 4728 --chromedriver-port 9519 -U xiaomi --session-override

参阅:

2. 安装Appium-python库

第一种方式:命令行

pip install Appium-Python-Client

pip3 install Appium-Python-Client

第二种方式:安装包

前提:python已安装setuptools包

  • 安装setuptools
    (1)解压setuptools-38.2.4.zip
    (2)进入解压后文件夹执行命令: python setup.py install
    (3)等待安装完成,无错误信息即可

  • 安装Appium-Python-Client
    (1)解压Appium-Python-Client-0.47.tar.gz
    (2)进入解压后文件夹执行命令: python setup.py install
    (3)等待安装完成,无错误信息即可

4.1.2 脚本测试

1. 脚本语法

  • 手机驱动对象
    驱动对象会帮助我们完成手机和脚本之间交互
  • 导入driver对象
    from appium import webdriver
  • 声明手机驱动对象

    提示:
    • 只有声明驱动对象我们才可以让手机完成脚本的操作
#声明对象后会直接启动参数中的应用
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 

提示:

  • wd即webdriver
  • hub与分布式相关,代表中心节点
  • 手机启动参数
    desired_caps
    负责启动服务端时的参数设置,appium server 与手机端建立会话关系时,根据这些参数服务端可以做出相应的处理
desired_caps常用参数 说明
platformName 平台的名称

iOS、Android、 FirefoxOS
platformVersion 设备系统版本号
deviceName 设备号

IOS instruments -s devices

Android adb devices
app 安装文件路径

/abs/path/to/my.apkhttp://myapp.com/app
appActivity 启动的Activity
appPackage 启动的包
unicodeKeyboard unicode设置(允许中文输入)
resetKeyboard 键盘设置(允许中文输入)
#server启动参数
    desired_caps = {}

    #设备信息(系统、版本、设备号)
    desired_caps['platformName'] = 'Android' 
    desired_caps['platformVersion'] = '5.1'
    desired_caps['deviceName'] = '192.168.56.101:5555'

    #app信息(包名、启动名)
    desired_caps['appPackage'] = 'com.android.settings'
    desired_caps['appActivity'] = '.Settings'
    
    desired_caps['unicodeKeyboard'] = True
    desired_caps['resetKeyboard'] = True
  • 脚本内启动其他app
    driver.start_activity(appPackage,appActivity)
  • 关闭app
# 关闭当前操作的app,不会关闭驱动对象
driver.close_app()
  • 关闭驱动对象
# 关闭驱动对象,同时关闭所有关联的app
driver.quit()

2. 示例脚本

功能:打开设置并点击搜索按钮

准备:

  • 运行Appium软件并开启服务(appium服务器)
    客户端:直接运行并修改host为127.0.0.1
    命令行:appium &
  • 启动模拟器中的系统(移动端)
  • 运行Pycharm(自动化测试脚本)
from appium import webdriver

import time

# server 启动参数
desired_caps = {}
# 设备信息(系统、版本、设备号)
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = '192.168.72.103:5555'
# app信息(包名、启动名)
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'

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

time.sleep(5)

driver.quit()

提示:

  • desired_caps['platformVersion']值获取
    adb shell getprop ro.build.version.release

  • desired_caps['deviceName'] 值获取
    adb devices

参阅:

Guess you like

Origin www.cnblogs.com/ricsy/p/11541668.html