Appium-Drivers-UIAutomation(iOS)

iOS自动化测试


Note: This driver is DEPRECATED and should not be used unless absolutely necessary. The information in this doc may not keep up to date with reality, and the driver will be removed in a future version of Appium. To begin iOS automation with Appium today, please use the XCUITest Driver instead.

此程序已弃用,如非必要不应使用。
以下内容可能与实际情况不符,
驱动程序将在未来版本的Appium中删除。
今天要用Appium开始iOS自动化,
请改用XCUITest Driver

Appium’s former method for iOS app automation was based on UIAutomation, an Apple-provided framework that shipped with the iOS SDK until iOS 10, when it was removed. UIAutomation was one of the tools included in Apple’s Instruments profiling system, and provided a JavaScript API that ran synchronously in the context of a single app. The Appium UIAutomation driver established an asynchronous, session-based WebDriver front end for this API.

Appium曾用于iOS应用程序的自动化方法是基于UIAutomation,
这是一个苹果提供的框架,
iOS SDK至iOS 10,在被删除前。
UIAutomation 是苹果Instruments评测系统中包含的工具之一,
并提供一个JavaScript API在单个程序的环境中运行。
Appium UIAutomation driver是一个基于异步的基于session-based WebDriver此API前端

Development of the UIAutomation driver is done at the appium-ios-driver repo.

UIAutomation driver开发在appium-ios-driver中完成
Requirements and Support
需求和支持

In addition to Appium’s general requirements:

除了Appium的一般要求外
  • Xcode 7 or lower. //Xcode以下
  • iOS simulators or devices with version 9.3 or lower.
  • All versions of Appium ship with this driver.
  • For correct functioning of the driver, see additional setup below.
Usage

The way to start a session using the UIAutomation driver is to set the platformName capability in your new session request to the value of iOS. Of course, you must also include appropriate platformVersion, deviceName, and app capabilities, at a minimum.

这里介绍包含元素的用法(platName/platVersion/derviceName/app minimum)
Capabilities
功能

The UIAutomation driver supports a number of standard Appium capabilities, but has an additional set of capabilities that work for this driver only (see the iOS section of the aforementioned doc).

UIAutomation支持多标准的Appium功能,
但有一组仅限此驱动程序的附加功能

To automate Safari instead of your own application, leave the app capability empty and instead set the browserName capability to Safari.

Commands

To see the various commands Appium supports, and specifically for information on how the commands map to behaviors for the UIAutomation driver, see the API Reference.

Simulator Setup
模拟器设置

(Note that due to limitations of Xcode and the iOS simulator, only one simulator may be open, and automated, at any given time. For multiple simulator support, you will need to upgrade to the XCUITest driver).

由于Xcode和iOS模拟器的限制,
只可运行一个模拟器,如需多模拟器支持,
需升级XCUITest driver

1.For best results, launch each simulator you wish to use and ensure the following:

  • The soft keyboard is enabled (Command+K in the Simulator app) //软键盘
  • UIAutomation is enabled in the Developer settings menu //开发人员设置
  • There is not more than one simulator with the same name in Xcode’s “Devices” organizer //模拟器同名
Real Device Setup

Running tests on real devices is considerably more complicated due to code signing and additional workarounds to Apple limitations. The basic process for a successful automation strategy using this driver are as follows:

真实设备运行测试相对复杂,
因代码签名和苹果限制的额外解决方法,
成功使用此驱动程序的自动化策略过程如下

1.Build your app with a Debug configuration, for the specific type of real device you will run the test on, ensuring that the app is also signed for running on your specific device. For example:/确保已签名

xcodebuild -sdk <iphoneos> -target <target_name> -configuration Debug \ CODE_SIGN_IDENTITY="iPhone Developer: Mister Smith" \ PROVISIONING_PROFILE="XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"

2.Install the built app (usually now located in a build directory specified in Xcode) to your test device yourself, ensuring it exists on the device and there are no signing issues. There are a number of methods for installing apps onto devices. One is to just use Xcode itself. Another is to use the ideviceinstaller tool provided as part of the libimobiledevice suite. A third is to use ios-deploy. Here’s an example for ideviceinstaller:

自己将构建的应用程序(通常现在位于Xcode中指定的构建目录中)安装到测试设备上,
确保该应用程序存在于设备上并且没有签名问题。
在设备上安装应用程序有多种方法。
一种是只使用Xcode本身。
另一种方法是使用“libimobiledevice”套件中提供的“ideviceinstaller”工具。
第三种是使用ios部署
first install ideviceinstaller, using Homebrew (http://brew.sh)
brew install libimobiledevice ideviceinstaller -u -i 

3.Use the bundle ID of your application as the value of the app capability.

使用应用程序的bundle ID作为app capability value

4.Use the UDID of your device as the udid capability.取设备UUID
5.As above, ensure that UI Automation is enabled in the Developer settings.
Following these steps should ensure your success! If you’re using newer versions of Xcode (7.x, for example), you may wish to consult the XCUITest Driver Real Device Docs as they may contain some pertinent information as well.

如上所述,确保开发者在设置中启用了UI Automation.
跟着步骤确保成功,
如果是较新版本参阅XCUITest Driver Real Device Docs
Real Device Hybrid / Web Testing
真机混合/Web测试

For hybrid and web testing, Appium requires the use of the Remote Debugging Protocol to send JavaScript to execute inside a web view. For real iOS devices, this protocol is encrypted and access must be facilitated using a 3rd-party tool, provided by Google, called ios-webkit-debug-proxy (IWDP). For information on installing and using IWDP within Appium, check out the IWDP doc.

对于混合测试和web测试,
appium需要使用远程调试协议来发送JavaScript在Web视图中执行。
对于真正的iOS设备,
这个协议是加密的,
必须使用Google提供的第三方工具iOS-webkit-debug-proxy(IWDP).

For web testing, i.e., tests that run in the Safari browser, we have another hurdle to jump. On real devices, apps that are not signed by the developer cannot be instrumented with UIAutomation. Safari is one such app. Thus we have a helper app called SafariLauncher, which can be signed by the developer. Its sole purpose upon launching is to turn around and launch Safari, which can then be automated via the Remote Debugger in conjunction with IWDP. Unfortunately you cannot, in this case, move into the native context and do any automation of the browser itself.

对于Web测试,在Safari浏览器中运行的测试,
我们还有另一个障碍要跨过。
在真机测试中,未经开发人员签名的应用程序无法使用UIAutomation进行检测。
Safari就是这样一个app。
因此我们有一名为SafariLauncher的助手应用程序,可以由开发者签名。
它在启动时时的唯一目的是找出并启动Safari,
然后可以通过自动化与IWDP一起远程调试,
不幸的是你不可以在这种情况下,
移动到本机环境中并对浏览器执行任何操作

For instructions on setting up SafariLauncher, check out the SafariLauncher doc.

Files generated by iOS test runs
iOS测试运行生成的文件

Testing on iOS generates files that can sometimes get large. These include logs, temporary files, and derived data from Xcode runs. Generally the following locations are where they are found, should they need to be deleted:

测试在iOS引起间歇性变大,
包括日志、临时文件和Xcode运行的驱动数据,
通常来说,如果需要删除,
以下是删除它们的具体位置
$HOME/Library/Logs/CoreSimulator/*
/Library/Caches/com.apple.dt.instruments/*
Running iOS tests using Jenkins
使用Jenkins运行iOS测试

First download the jenkins-cli.jar and verify that the Mac successfully connects to Jenkins master.

先下载,验证连接成功
wget https://jenkins.ci.cloudbees.com/jnlpJars/jenkins-cli.jar

java -jar jenkins-cli.jar \
 -s https://team-appium.ci.cloudbees.com \
 -i ~/.ssh/id_rsa \
 on-premise-executor \
 -fsroot ~/jenkins \
 -labels osx \
 -name mac_appium

Next define a LaunchAgent for Jenkins to launch automatically on login. A LaunchDaemon will not work because daemons don’t have GUI access. Make sure the plist doesn’t contain the SessionCreate or User key as that may prevent tests from running. You’ll see a Failed to authorize rights error if misconfigured.
LaunchDaemon启动守护进程

接下来定义一个LaunchAgent让Jekins在登录时自动启动,
LaunchDaemon将无法工作,
GUI不具有访问权限。
确保plist不包含SessionCreate或Uers key因为这样可能会阻止测试运行,
如果配置错误将看到`Failed to authorize rights`或者`授权权限失败`
$ sudo nano /Library/LaunchAgents/com.jenkins.ci.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.jenkins.ci</string>
    <key>ProgramArguments</key>
    <array>
        <string>java</string>
        <string>-Djava.awt.headless=true</string>
        <string>-jar</string>
        <string>/Users/appium/jenkins/jenkins-cli.jar</string>
        <string>-s</string>
        <string>https://instructure.ci.cloudbees.com</string>
        <string>on-premise-executor</string>
        <string>-fsroot</string>
        <string>/Users/appium/jenkins</string>
        <string>-executors</string>
        <string>1</string>
        <string>-labels</string>
        <string>mac</string>
        <string>-name</string>
        <string>mac_appium</string>
        <string>-persistent</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/appium/jenkins/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/appium/jenkins/error.log</string>
</dict>
</plist>

Finally set the owner, permissions, and then start the agent.

最后设置所有者、权限,然后启动代理
sudo chown root:wheel /Library/LaunchAgents/com.jenkins.ci.plist
sudo chmod 644 /Library/LaunchAgents/com.jenkins.ci.plist

launchctl load /Library/LaunchAgents/com.jenkins.ci.plist
launchctl start com.jenkins.ci
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Aniona

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

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

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

打赏作者

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

抵扣说明:

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

余额充值