XCUITest:Xcode User Interface Testing
Appium’s primary support for automating iOS apps is via the XCUITest
driver. (New to Appium? Read our introduction to Appium drivers). This driver leverages Apple’s XCUITest libraries under the hood in order to facilitate automation of your app . This access to XCUITest is mediated by the WebDriverAgent server. WebDriverAgent (also referred to as “WDA”) is a project managed by Facebook, to which the Appium core team contributes heavily. WDA is a WebDriver-compatible server that runs in the context of an iOS simulator or device and exposes the XCUITest API. Appium’s XCUITest driver manages WDA as a subprocess opaque to the Appium user, proxies commands to/from WDA, and provides a host of additional functionality (like simulator management and other methods, for example).
Appium对iOS应用程序自动化的主要支持是通过xguitest驱动程序.
这个驱动程序利用了Apple提供的XCUITest库,以促进应用程序的自动化。
对XCUITest的访问由WebDriverAgent服务器调节。
WebDriverAgent(也称为“WDA”)是由Facebook管理的项目,Appium核心团队做出重大贡献。WDA是一个与Web驱动兼容运行在iOS环境模拟器或设备环境中运行并公开XCUITest API。
Appium的XCUITest驱动程序将WDA作为对Appium用户不透明的子进程进行管理,代理WDA的命令,并提供大量附加功能(如,模拟器管理和其他方法)
Development of the XCUITest driver happens at the appium-xcuitest-driver repo.
XCUITest驱动程序在appium-xcuitest-driver repo中开发运行
需求和支持
In addition to Appium’s general requirements:
Appium一般要求除外
从UIAutomation驱动程序迁移
If you are migrating to the XCUITest driver from Appium’s old UIAutomation-based driver, you may wish to consult this migration guide.
用法
The way to start a session using the XCUITest driver is to include the automationName
capability in your new session request, with the value XCUITest
. Of course, you must also include appropriate platformName
, platformVersion
, deviceName
, and app
capabilities, at a minimum.
使用XCUITest驱动程序在新的会话请求中包含`automationName`必须包含元素
The platformName
should be iOS
for iPhone or iPad. tvOS devices are available if the platformName
is tvOS
.
json { "automationName": "XCUITest", "platformName": "iOS", "platformVersion": "12.2", "deviceName": "iPhone 8", ... }
json { "automationName": "XCUITest", "platformName": "tvOS", "platformVersion": "12.2", "deviceName": "Apple TV", ... }
The XCUITest driver supports a number of standard Appium capabilities, but has an additional set of capabilities that modulate the behavior of the driver. These can be found currently at the appium-xcuitest-driver README.
XCUITest驱动支持许多Appium标准功能,
但有一组额外的功能可调节驱动程序的行为
To automate Safari instead of your own application, leave the app
capability empty and instead set the browserName
capability to Safari
.
要自动化Safari而不是自己的应用,
将`app`功能保留为空,
改为将`browserName`功能设置为`Safari`
命令
To see the various commands Appium supports, and specifically for information on how the commands map to behaviors for the XCUITest driver, see the API Reference.
基本设置
(We recommend the use of Homebrew for installing system dependencies)
建议使用自制软件安装系统依赖项
Ensure that you have Appium’s general dependencies (e.g., Node & NPM) installed and configured.
确保已安装并配置了Appium的常规依赖项(例如,Node和NPM)
If you don’t need to automate real devices, you’re done! To automate an app on the simulator, the app
capability should be set to an absolute path or url pointing to your .app
or .app.zip
file, built for the sim.
如果你不需要自动化真正的设备,
你就完了!要在模拟器上自动化应用程序,
应将应用程序功能设置为指向.app或的绝对路径或url.
应用程序.zip文件,为sim卡构建
Automating a real device with XCUITest is considerably more complicated, due to Apple’s restrictions around running apps on real devices. Please refer to the XCUITest real device setup doc for instructions.
由于苹果对在真实设备上运行应用程序的限制,
用xguitest实现真实设备的自动化要复杂得多
Once set up, running a session on a real device is achieved by using the following desired capabilities:
设置完成后,
可通过使用以下所需功能在实际设备上运行会话:
app
or bundleId
- specifies the application (local path or url referencing your signed .ipa file) , or, if it is already installed, simply the bundle identifier of the app so that Appium can launch it.`app`或`bundleId`-指定应用程序(引用已签名的.ipa文件的本地路径或url),
或者,如果已经安装了,
只需指定应用程序的绑定标识符,
以便Appium可以启动它
udid
- the specific id of the device to test on. This can also be set to auto if there is only a single device, in which case Appium will determine the device id and use it.`udid`-要测试的设备的特定id。
如果只有一个设备,这也可以设置为自动,
在这种情况下,Appium将确定设备id并使用它
操作设置
安装idb以更好地处理各种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/*
$HOME/Library/Developer/Xcode/DerivedData/*
键盘配置
Over Appium 1.14.0, Appium configures keyboard preferences by default to make test running more stable. You can change sone of them via settings API.
在Appium1.14.0以上版本,
Appium键盘配置默认首选项使测试运行更加稳定,
你可以更改API设置中的其中一个
Auto-Correction
in Keyboards off关闭键盘中的自动更正
Predictive
in Keyboards off关闭键盘
将键盘标记为完成
打开软键盘(模拟器)
辅助功能选项微调
In some cases, enabling of the below preferences helps to make some view elements accessible. Appium does not modify these settings automatically, since they could affect the way your application under test performs. Please change them manually if needed
有时候,启用以下首选项有助于访问某些视图元素。
Appium不会自动修改这些设置,
因为它们可能会影响被测应用程序的执行方式。
如果需要,请手动更改
Spoken Content
in Settings > Accessibility onSpeak Selection
in Settings > Accessibility on