[关闭]
@Gebitang 2015-01-13T06:11:14.000000Z 字数 10370 阅读 6163

iOS自动化测试环境部署

iOS


系统环境

Mac:10.8.4-10.9.2
iDevice:iOS5.0-7.0.6
注:由于需越狱,因此以下设备不支持:
Touch5(7.0.6),Touch4(5.0,5.1),Touch3(5.0,5.1),iPhone3GS(5.0,5.1),iPhone4(5.0,5.1),iPhone4s(5.1),iPhone5s(7.0.7)


安装xCode

下载并安装xCode(开发环境版本为5.0.2)(now latest version is 5.1,size: 2.18G, download from app store.)
在xCode > Preferences > Downloads > Components下,选择安装Command Line Tools


安装brew

官网打开Terminal,输入:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

安装usbmuxd

usbmuxd, the USB multiplexor daemon, is in charge of coordinating access to iPhone and iPod Touch services over USB. Synchronization and management applications for the iPhone and iPod Touch need this daemon to communicate with such devices concurrently.

usbmuxd
iTunes使用一种叫”usbmux”的东西与iphone通信, 这个东西提供了一个USB - TCP的转换服务.
这个服务在Mac端是由/System/Library/PrivateFrameworks/MobileDevice.framework/Resources/usbmuxd提供的, 当然, 开机自动启动.
它创建了一个Unix Domain Socket 在 /var/run/usbmuxd. usbmuxd服务程序监控iPhone在USB口上的连接, 当它监控到iPhone以用户模式连接到USB, (相对的是recovery模式), usbmuxd服务程序就会连接到这个/var/run/usbmuxd的TCP端口, 并开始成为一个USB - TCP 请求转发器

那么,如果想编写个第三方程序与iphone进行通信,实现类似iTunes的功能, 你的程序可以通过usbmuxd! 建立一个TCP连接到/var/run/usbmuxd端口, 根据协议发送对应的请求包, usbmuxd服务会将请求转发到USB的iPhone上
brew install usbmuxd


安装libimobiledevice

下载地址

安装依赖工具:

  1. brew install libtool
  2. brew install autoconf
  3. brew install automake

安装libimobiledevice

  1. ./autogen.sh
  2. make
  3. sudo make install

安装参考Problems

Install libusbmuxd1.0.9: https://github.com/libimobiledevice/libusbmuxd/releases

Install libplist 1.11: https://github.com/libimobiledevice/libplist/releases
Must install latest version, otherwise make is not successful. Error: Undefined symbols for architecture x86_64:
may occurs, which is not unable to be solved for now.

附加信息

in order to install:
libxml >= 2.7.8
libplist
libusbmuxd
libimobiledevice


安装ideviceinstaller

安装依赖包:
brew install libzip
安装ideviceinstaller,源码见附件ideviceinstaller.zip。官网

  1. ./autogen.sh
  2. make
  3. sudo make install

Q&A:
brew install libzip
提示:Warning: libzip-0.11.2 already installed, it's just not linked
执行: brew link libzip 提示:Error: Could not symlink share/man/man3/zip_unchange_archive.3
/usr/local/share/man/man3 is not writable.

需要添加man3到当前用户,如sudo chown -R 'cmmac' /usr/local/share/man/man3
然后再执行 brew link libzip


安装iproxy

由于对iproxy有源码修改,所有需要进行手动编译生成,源码见附件usbmuxd-1.0.8.zip
安装iproxy:

  1. mkdir build
  2. cd build
  3. cmake ..
  4. make
  5. sudo cp ./tools/iproxy /usr/local/bin/

---

利用iproxy安装deb包

  1. Neu:~/myTemp root# DevStat
  2. 2014-06-25 13:21:22.588 DevStat[694:707] model=iPhone
  3. 2014-06-25 13:21:22.600 DevStat[694:707] systemName=iPhone OS
  4. 2014-06-25 13:21:22.605 DevStat[694:707] systemVersion=6.1.3
  5. 2014-06-25 13:21:22.609 DevStat[694:707] CPUFrequency=1GMHz
  6. 2014-06-25 13:21:22.613 DevStat[694:707] MemeorySize=504.95 M
  7. 2014-06-25 13:21:22.616 DevStat[694:707] TotalDiskSpace=13.69 G
  8. 2014-06-25 13:21:22.620 DevStat[694:707] FreeDiskSpace=11.16 G
  9. 2014-06-25 13:21:22.638 DevStat[694:707] ScreenPixel=(640 x 960)
  10. 2014-06-25 13:21:22.642 DevStat[694:707] ScreenResoultion=iPhone Retina 3.5-inch

ruby依赖项

安装ruby1.9.3(推荐使用rvm安装,教程

  1. curl -sSL https://get.rvm.io | bash -s stable
  2. source ~/.bashrc
  3. source ~/.bash_profile

安装rvm依赖项:
brew installer gcc46

注:
1,若gmp4下载不动,更改/usr/local/Library/Taps/homebrew-versions/gmp4.rb中url为’http://mirror.anl.gov/pub/gnu/gmp/gmp-4.3.2.tar.bz2
2,若cloog-pp1015下载不动,更改/usr/local/Library/Taps/homebrew-versions/cloog-pp1015.rb中url为’ http://gcc.cybermirror.org/infrastructure/cloog-ppl-0.15.11.tar.gz’)
brew install libyaml
brew install readline
brew install libksba
注:
若下载不动,更改/usr/local/Library/Formula/libksba.rb中url为’ http://ftp.heanet.ie/mirrors/ftp.gnupg.org/gcrypt/libksba/libksba-1.3.0.tar.bz2’)
brew install openssl
rvm install 1.9.3

如果安装ruby1.9.3时提示:

Ruby 'ruby-1.9.3-p547' was built using clang - but it's not (fully) supported, expect errors.
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering

Please consider upgrading to ruby-2.1.2 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

“No available formula for gcc46” while installing Ruby 1.9.3 on OS X with RVM:
Use:
rvm install 1.9.3 —with-gcc=clang
and it works.

然后安装以下gem

  1. gem install rubyzip
  2. gem install net-ssh
  3. gem install run_loop
  4. gem install plist
  5. gem install --local autotest-0.2.5.gem(本地gem,见附件)

*使用本地安装,不能使用在线安装的方式 gem install autotest
*如果安装了多个autotest,可以使用 gem uninstall autotest进行卸载,会自动提示卸载哪个版本。

安装log如下:

  1. chinamobiledeiMac:~ cmmac$ gem install rubyzip
  2. Fetching: rubyzip-1.1.3.gem (100%)
  3. Successfully installed rubyzip-1.1.3
  4. Installing ri documentation for rubyzip-1.1.3
  5. 1 gem installed
  6. chinamobiledeiMac:~ cmmac$ gem install net-ssh
  7. Fetching: net-ssh-2.9.1.gem (100%)
  8. Successfully installed net-ssh-2.9.1
  9. Installing ri documentation for net-ssh-2.9.1
  10. 1 gem installed
  11. chinamobiledeiMac:~ cmmac$ gem install run_loop
  12. Fetching: thor-0.19.1.gem (100%)
  13. Successfully installed thor-0.19.1
  14. Fetching: run_loop-0.2.0.gem (100%)
  15. Successfully installed run_loop-0.2.0
  16. unable to convert "\xCF" from ASCII-8BIT to UTF-8 for scripts/udidetect, skipping
  17. Installing ri documentation for run_loop-0.2.0
  18. Installing ri documentation for thor-0.19.1
  19. 2 gems installed
  20. chinamobiledeiMac:~ cmmac$ gem install plist
  21. Fetching: plist-3.1.0.gem (100%)
  22. Successfully installed plist-3.1.0
  23. Installing ri documentation for plist-3.1.0
  24. 1 gem installed
  25. chinamobiledeiMac:~ cmmac$ gem install autotest
  26. Fetching: ZenTest-4.10.0.gem (100%)
  27. Successfully installed ZenTest-4.10.0
  28. Fetching: autotest-4.4.6.gem (100%)
  29. Successfully installed autotest-4.4.6
  30. Installing ri documentation for ZenTest-4.10.0
  31. Installing ri documentation for autotest-4.4.6
  32. 2 gems installed
  33. chinamobiledeiMac:~ cmmac$ gem install net-scp
  34. Fetching: net-scp-1.2.1.gem (100%)
  35. Successfully installed net-scp-1.2.1
  36. Installing ri documentation for net-scp-1.2.1
  37. 1 gem installed
  38. chinamobiledeiMac:~ cmmac$

设备依赖项

越狱(可使用windows安装PP助手或91助手进行越狱,参见越狱文档),进入Cydia选择“开发者”
用Cydia安装openssh
用Cydia安装top
用Cydia安装network-cmds
添加PP源(http://apt.25pp.com),并安装Appsync(请注意对应iOS版本)

安装clean.deb至iDevice

依赖项:iproxy,net-ssh,net-scp
依赖项使用gem安装即可,如gem install net-scp
使用installdeb.rb:
使用方法:
-u 设备UDID
-d DEB文件路径
例:
./installdeb.rb -u ea9e02572eb2feeb191d2e5b851c05fe9b576dde -d ./clean.deb

*由于取log是根据本地mac时间,因此注意把移动设备时间和mac时间校准(无法精确校准的话,请把移动设备时间设置的快1分钟)


设置Mac的环境变量

资料来源
Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI apps, your only option is /etc/launchd.conf

Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here.

1) Open a terminal prompt

2) Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

3) Put contents like the following into the file

  1. # Set environment variables here so they are available globally to all apps
  2. # (and Terminal), including those launched via Spotlight.
  3. #
  4. # After editing this file run the following command from the terminal to update
  5. # environment variables globally without needing to reboot.
  6. # NOTE: You will still need to restart the relevant application (including
  7. # Terminal) to pick up the changes!
  8. #
  9. # grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
  10. #
  11. # See http://www.digitaledgesw.com/node/31
  12. # and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/
  13. #
  14. # Note that you must hardcode the paths below, don't use enviroment variables.
  15. # You also need to surround multiple values in quotes, see MAVEN_OPTS example below.
  16. #
  17. setenv rvm_bin_path /Users/cmmac/.rvm/bin
  18. setenv GEM_HOME /Users/cmmac/.rvm/gems/ruby-1.9.3-p547
  19. setenv MY_RUBY_HOME /Users/cmmac/.rvm/rubies/ruby-1.9.3-p547
  20. setenv rvm_path /Users/cmmac/.rvm
  21. setenv PATH "/Users/cmmac/.rvm/gems/ruby-1.9.3-p547/bin:/Users/cmmac/.rvm/gems/ruby-1.9.3-p547@global/bin:/Users/cmmac/.rvm/rubies/ruby-1.9.3-p547/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/cmmac/.rvm/bin:/Users/cmmac/.rvm/gems/ruby-1.9.3-p547/gems/autotest-0.3.1/bin/"

4) Save your changes in VI and reboot your Mac. Or use the grep/xargs command show in the code comment above.

5) Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ and other GUI apps you launch via Spotlight.


配置Mac

配置Mac,用于可以进行自动重启,并执行TestAgent

修改sodu配置文件

等同与编辑sudo vi /etc/sudoers文件
sudo visudo
%admin ALL=(ALL) ALL改为%admin ALL=(ALL) NOPASSWD: ALL

  1. root ALL=(ALL) ALL
  2. %admin ALL=(ALL) NOPASSWD: ALL

打开Automatic login

在系统偏好设置 -- 用户和群组 -- 登录选项中设置

制作运行脚本,用于启动TestAgent

如:

  1. #!/bin/sh
  2. java -jar testAgent.jar

保存,并加上可执行权限。

制作Automator Application

-- 在LaunchPad中选择Automator程序。
-- 文档类型选择 Automator程序
-- 资源库(Library)选择 文件和文件夹(Files & Folders)
-- 选择 获取指定的Finder项目(Get Specified Finder Items)
-- 选择添加,将shell脚本选中
-- 再选择打开Finder项目 (Open Finder Items);选择打开程序为终端Terminal
-- 保存为应用程序

在Login Items中添加保存的应用程序

在系统偏好设置 -- 用户和群组 -- 登录选项中设置


Xcode越狱开发相关

下载越狱开发插件
参考文档
clean、reachability项目模板:

choose a template for your new project -- Command-line Tool

iOS私有API文档

iOS录制环境

功能测试录制工具
下载地址
下载MonkeyTalk Community对应版本。

前提条件:

  1. iPhone已经越狱。
  2. MonkeyTalk已经安装。
  3. PC机和iPhone在同一个wifi局域网里。

注意事项:

  1. iPhone不升级(越狱后也不要升级)。因升级后不一定可以越狱成功,即使可以越狱成功,也有可能出现“白苹果”(即只有启动页面的一个白色苹果,无法正常开机)的现象。。
  2. 越狱时请保证iPhone有稳定的wifi连接。因越狱过程中会进行越狱程序的安装。

一键越狱方法:

可参看:PP助手iOS7完美越狱
或参考文档《越狱帮助文档.doc》
简明步骤如下:
0. 保证iPhone有稳定的wifi连接
1. 下载后,解压缩(PPGhost.zip)即可直接启动PPGhost.exe
2. 连接iPhone,识别后点击 开始越狱
3. PP越狱助手自动识别iOS设备与固件版本自动弹出越狱evasi0n7工具
4. 等待自动执行,期间iPhone会自动重启
5. 重启解开锁屏之后,点击iPhone端的evasi0n7图标
6. 等待越狱成功提示。


MonkeyTalk安装:

MonkeyTalk实际上是重新封装后的Eclipse,依赖于Java环境。因我们之前已经配置过Android的录制环境,所以这一步可以忽略。
只需要下载解压到本地即可使用。
可到官方网站下载Community版本
我们提供了已经下载好的win32版《monkeytalk-2.0.4-win32.zip》


MonkeyTalk使用教程

请参考《MonkeyTalk说明文档.doc》。在线文档
简明步骤如下:
1. 启动MonkeyTalkIDE
2. 新建MonkeyTalkProject工程
3. 新建脚本
4. 启动手机端含有monkeyagent的程序(通常由开发人员提供,目前我们只要1.8.0版本的手机营业厅10086.ipa)
5. 在MonkeytalkIDE中wifi连接手机
6. 开始操作手机程序,进行录制


注意事项:

  1. 连接后控制台如果没有iOS agent的提示出现。
    说明没有连接成功,此时录制按钮是不可用的状态。这种情况下:先从PC端执行ping 命令,如 ping 192.168.1.117(此IP为iPhone的ip地址,可在设置的网络详情里看到)。如果提示超时,或无法连接主机,说明连接异常,可以断开iPhone端的连接,再重新连接。通常这样处理之后,再次执行ping命令时即可连接正常。

  2. 录制首次启动的问题。
    因为iPhone没有提供程序管理--清除数据的类似功能。只能通过删除和重新安装来实现首次启动的效果。
    利用XY苹果助手(下载地址)完成本地程序的安装。启动该程序,连接手机后通过程序管理进行卸载和重新安装本地程序。具体可参看《MonkeyTalk说明文档.doc》最后的部分。


越狱后使用xy苹果助手无法安装本地应用

(提示没有安装AppSync)的解决方法:
通过 pp源安装 “ PP助手ipa补丁iOS7.X ”即可。

详情如下:
需要手机可以wifi联网:
1. 越狱后手机端有个Cydia程序。
2. 启动Cydia程序,选择“开发者”。(首次启动后会有提示选择)
3. 添加PP源。在 管理 -- 软件源 -- 编辑 -- 添加。 然后在 地址中输入:http://apt.25pp.com
4. 等待刷新完毕,回到Cydia后,进入25pp手机助手源
5. 安装 PP助手ipa补丁iOS7.X



脚本录制

编辑脚本内容

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注