Android IOS UI自动化测试:Appium

本文详细介绍了如何使用Appium进行Android和iOS的UI自动化测试。涵盖了环境搭建,包括Win和Mac下的Android及iOS环境,Ruby+Cucumber和Python+Behave的脚本环境设置,以及基础用法。同时,提到了Jenkins的集成和测试报告的生成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

移动APP自动化测试框架对比【 腾讯移动品质中心TMQ】

客户端自动化测试研究【美团技术团队】

Appium【github】

Cucumber【github】

环境搭建

【Win下Android环境搭建】
1. Node.js
官网下载安装包并安装
验证:打开cmd,输入npm
2. Java环境
3. Android环境
4. 安装Appium
github 下载Appium,安装(可能会提示缺少.net framework,建议在微软官网上安装对应的)
安装后,直接【Start Server】启动服务。
这里写图片描述
5.验证Appium环境

npm install -g appium-doctor
appium-doctor --android

这里写图片描述

【Mac下IOS环境搭建】
基本上类似
1.Node.js
官网下载并安装
在mac下的安装目录如下
Node.js v8.11.1 to /usr/local/bin/node
npm v5.6.0 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
安装完之后,可使用node -v查看node版本,npm -v查看npm版本
2.安装carthage
Carthage 是一款iOS项目依赖管理工具,与 Cocoapods 有着相似的功能

brew install carthage

3.安装Appium
github下载Appium并安装,安装后直接【Start Server】启动服务

5.验证Appium环境

npm install -g appium-doctor
appium-doctor --ios

这里写图片描述

脚本环境【Ruby + cucumber】

以一个求和的应用为例,app效果展示如下
这里写图片描述

1.启动Appium服务,【Start Server】
2.安装Ruby
利用rubyinstaller安装Ruby
3.安装appium_lib,一个支持Appium服务端的ruby客户端

gem update –system
gem update bundler
gem uninstall -aIx appium_lib
gem install –no-rdoc –no-ri appium_lib
4.新建一个test文件夹,新建文件,命名为Gemfile文件【没有后缀】,用编辑器打开,写入以下代码

source 'https://www.rubygems.org'

gem 'appium_lib',         '~> 9.7.4'
gem 'rest-client',        '~> 2.0.2'
gem 'rspec',              '~> 3.6.0'
gem 'cucumber',           '~> 2.4.0'
gem 'rspec-expectations', '~> 3.6.0'
gem 'spec',               '~> 5.3.4'
gem 'sauce_whisk',        '~> 0.0.13'
gem 'test-unit',          '~> 2.5.5' # required for bundle exec ruby xunit_android.rb

保存退出
用Ruby在目录下执行以下命令,安装Ruby依赖(包括cucumber),并初始化cucumber

bundle update
bundle install
cucumber --init

生成目录如下

features # 存放feature的目录
├── step_definitions # 存放steps的目录
└── support # 环境配置
└── env.rb

现在对support目录下的env.rb进行修改,改成匹配android和ios两种移动端环境
修改后目录如下

features # 存放feature的目录
├── step_definitions # 存放steps的目录
└── support # 环境配置
   ├── android
      └── appium.txt
   ├── ios
      └── appium.txt
   ├── env.rb

env.rb修改后变成如下

# This file provides setup and common functionality across all features.  It's
# included first before every test run, and the methods provided here can be
# used in any of the step definitions used in a test.  This is a great place to
# put shared data like the location of your app, the capabilities you want to
# test with, and the setup of selenium.

require 'rspec/expectations'
require 'appium_lib'
require 'cucumber/ast'

# Create a custom World class so we don't pollute `Object` with Appium methods
class AppiumWorld
end

# Load the desired configuration from appium.txt, create a driver then
# Add the methods to the world
case ENV['PLATFORM']
when 'android'
    caps = Appium.load_appium_txt file: File.expand_path('./android/appium.txt', __FILE__), verbose: 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值