Appium appium-ios 自动化入门

tunsuy · 2015年03月09日 · 最后由 lillian 回复于 2017年05月23日 · 1870 次阅读
本帖已被设为精华帖!

在 mac 下配置 appium 的自动化测试环境在这里就不说了,网上很多
因为查了下 appium 针对 ios 的自动化测试,网上的资料比较少,且说得不是很清楚,
故这篇文章主要介绍怎样使用 appium 自动化测试自己的项目。
这些操作步骤均是自己亲自操作并实践通过的

这里以自己实现的一个简单的 ios app 来一步步介绍
这篇文章先介绍在模拟器下运行的情况

1、编译 ios app

$ cd /Users/xxx/Documents/lesFour/

$ xcodebuild -sdk iphonesimulator
注:I、官网上的介绍中是这样写的:xcodebuild -sdk iphonesimulator6.0,表示编译成 ios6 版本的
这里要说明的就是 如果你在这里指定了版本号,那么你就必须修改编译文件为对应的版本,不然运行不成功
II、这条命令会在项目目录下产生一个 build 文件夹,等下我们会用到里面的一些文件
III、关于 在命令行下编译 ios 项目的知识 会在后续简单的介绍

2、下载并更新 appium-ruby 项目库

切换到你喜欢的目录下,下载 appium-ruby 库
$ git clone https://github.com/appium/sample-code.git

$ cd /Users/xxx/sample-code/sample-code/examples/ruby/

因为 mac 自带 ruby,所有这里直接更新项目依赖即可
$ gem install bundle

$ bundle update

3、开始测试自己的项目

I、这里先运行一下官方的测试程序检查是否配置正确

在 mac 下启动一个终端,开启 appium-server

$ appium
info: Welcome to Appium v1.3.5 (REV a124a15677e26b33db16e81c4b3b34d9c6b8cac9)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug

——启动成功

另启动一个终端
$ cd /Users/xxx/sample-code/sample-code/examples/ruby/

$ rspec simple_test.rb

注:这时可以看到 appium-server 所在的终端正在持续打出一系列日志,然后可以看到模拟器启动并测试成功

II、自动化测试自己的项目
拷贝项目目录下之前编译产生的 build 文件夹 到 /Users/xxx/sample-code/sample-code/apps/TestApp/ 目录下,覆盖掉已有的 build 文件夹(你也可以先备份再覆盖)

修改/Users/xxx/sample-code/sample-code/examples/ruby/目录下的 simple_test.rb 文件
$ vi simple_test.rb
修改 APP_PATH = '../../apps/TestApp/build/Release-iphonesimulator/lesThree.app' 为自己的路径
同时将 module Calculator 整个模块注释掉,也是自己的自动化代码,你也可以先不写,先看启动效果

启动测试

$ rspec simple_test.rb
No examples found.


Finished in 0.00012 seconds
0 examples, 0 failures

因为没有写测试代码,所有这里显示 0 个案例,0 个错误

程序正常被启动起来了,如下图所示:

共收到 8 条回复 时间 点赞

代码请贴代码并使用代码块!
日志请贴日志并使用代码块!
提问,指明问题信息,请像一个职业测试一样报问题
支持 Markdown 格式, 粗体删除线单行代码
支持表情,见 Emoji cheat sheet
按 “M” 键查看更多 帮助。

#1 楼 @monkey 好的,以后把排版弄好看些

写得不错!手把手入门了。
话说为啥大伙的运行环境都喜欢用 npm 安装 appium ? 总觉得 npm 安装依赖项很多,容易出现各种坑,而且会影响其他 node.js 项目。用 dmg 里面的 app 或者 exe 就简单多了。

#3 楼 @chenhengjie123 我没用过那个 GUI 的,不知道使用情况怎样,可能用源码安装能够了解到更多的东西吧,也许这就是极客精神,哈哈

请问,自动化测试 ios 是不是在 xcode 下要有源代码项目才可以进行?而且要连接上项目才可以进行看到 log

有源代码在真机上怎么启动。您能给我指导下吗。我的 qq120046303

#6 楼 @120046303 警告一次,别刷帖子。不相关的问题,刷贴干嘛?再有情况,删号。

LilliandeMacBook-Pro:~ lillian$ cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

LilliandeMacBook-Pro:WebDriverAgent lillian$ xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=a0d70c4a53bd51d9697ddb81e277c60092c3baf5' test

2017-05-23 09:54:11.430 xcodebuild[1826:101977] IDETestOperationsObserverDebug: Writing diagnostic log for test session to:
/Users/lillian/Library/Developer/Xcode/DerivedData/WebDriverAgent-cugadjxaiofygzgpwawfegxnduse/Logs/Test/38051C82-0CF6-41CB-81E1-5BE763C54811/Session-WebDriverAgentRunner-2017-05-23_095411-cPp7z3.log
2017-05-23 09:54:11.430 xcodebuild[1826:101940] [MT] IDETestOperationsObserverDebug: (E6AF1412-48F0-459B-BE39-AA8A13ECD1BF) Beginning test session WebDriverAgentRunner-E6AF1412-48F0-459B-BE39-AA8A13ECD1BF at 2017-05-23 09:54:11.430 with Xcode 8E2002 on target {
deviceSerialNumber: FK4PQGTSG5QR
identifier: a0d70c4a53bd51d9697ddb81e277c60092c3baf5
deviceClass: iPhone
deviceName: lillianiphone
deviceIdentifier: a0d70c4a53bd51d9697ddb81e277c60092c3baf5
productVersion: 10.0.2
buildVersion: 14A456
deviceSoftwareVersion: 10.0.2 (14A456)
deviceArchitecture: arm64
deviceTotalCapacity: 11920494592
deviceAvailableCapacity: 833273856
deviceIsTransient: NO
ignored: NO
deviceIsBusy: NO
deviceIsActivated: YES
deviceActivationState: Activated
isPasscodeLocked: YES
deviceType:
supportedDeviceFamilies: (
1
)
applications: (null)
provisioningProfiles: (null)
activityProgress: -2
activityTitle:

hasInternalSupport: NO
isSupportedOS: YES
developerDiskMountError: (null)
(null)
bootArgs:
} (10.0.2 (14A456))
=== BUILD TARGET WebDriverAgentLib OF PROJECT WebDriverAgent WITH CONFIGURATION Debug ===

Check dependencies

=== BUILD TARGET WebDriverAgentRunner OF PROJECT WebDriverAgent WITH CONFIGURATION Debug ===

Check dependencies
Signing for "WebDriverAgentRunner" requires a development team. Select a development team in the project editor.
Code signing is required for product type 'UI Testing Bundle' in SDK 'iOS 10.3'
Signing for "WebDriverAgentRunner" requires a development team. Select a development team in the project editor.
Code signing is required for product type 'UI Testing Bundle' in SDK 'iOS 10.3'
2017-05-23 09:54:12.142 xcodebuild[1826:101940] Error Domain=IDETestOperationsObserverErrorDomain Code=4 "Test operation was canceled. If you believe this error represents a bug, please attach the log file at /Users/lillian/Library/Developer/Xcode/DerivedData/WebDriverAgent-cugadjxaiofygzgpwawfegxnduse/Logs/Test/38051C82-0CF6-41CB-81E1-5BE763C54811/Session-WebDriverAgentRunner-2017-05-23_095411-cPp7z3.log" UserInfo={NSLocalizedDescription=Test operation was canceled. If you believe this error represents a bug, please attach the log file at /Users/lillian/Library/Developer/Xcode/DerivedData/WebDriverAgent-cugadjxaiofygzgpwawfegxnduse/Logs/Test/38051C82-0CF6-41CB-81E1-5BE763C54811/Session-WebDriverAgentRunner-2017-05-23_095411-cPp7z3.log}
Signing for "WebDriverAgentRunner" requires a development team. Select a development team in the project editor.
Code signing is required for product type 'UI Testing Bundle' in SDK 'iOS 10.3'
Code signing is required for product type 'UI Testing Bundle' in SDK 'iOS 10.3'

Testing failed:
Signing for "WebDriverAgentRunner" requires a development team. Select a development team in the project editor.
Code signing is required for product type 'UI Testing Bundle' in SDK 'iOS 10.3'
Test operation was canceled. If you believe this error represents a bug, please attach the log file at /Users/lillian/Library/Developer/Xcode/DerivedData/WebDriverAgent-cugadjxaiofygzgpwawfegxnduse/Logs/Test/38051C82-0CF6-41CB-81E1-5BE763C54811/Session-WebDriverAgentRunner-2017-05-23_095411-cPp7z3.log
** TEST FAILED **

The following build commands failed:
Check dependencies
(1 failure)
谁遇到这个问题吗,IOS 真机上不能运行,模拟器可以

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册