iOS UITests(自动化测试)常用类参考文档

UITests(自动化测试)Demo地址

Class 类

XCUIApplication 官方

A proxy for an application that can be launched and terminated.
可启动和终止的应用程序的代理。

Language 语言

Swift Objective-C

Overview 概述

The information identifying the application is specified in the Xcode target settings as the "Target Application".
信息识别中的应用是在Xcode的目标设置中指定的“目标”中的应用。

Symbols 符号

Launching the Application 启动应用程序

- launch
Launches the application.
启动应用程序。
launch​Arguments
The arguments that will be passed to the application on launch.
将在启动时传递给应用程序的参数。
launch​Environment
The environment variables that will be passed to the application on launch.
将在启动时传递给应用程序的环境变量。

Terminating the Application 终止应用程序

- terminate
Terminates any running instance of the application.
终止应用程序的任何运行实例。

Relationships 关系

Inherits From 继承

XCUIElement


Class 类

XCUIElement​Query 官方

A query for locating UI elements.
查找UI元素的查询。

Language 语言

Swift Objective-C

Symbols 符号

Query State 查询状态

debug​Description
Provides debugging information about the query.
提供有关查询的调试信息。

Creating New Queries 创建新的查询

- children​Matching​Type:​​
Returns a new query that finds the direct children of all elements found by the receiver.
返回一个新的查询,该查询查找接收到的所有元素的直接子。
- descendants​Matching​Type:​​
Returns a new query that finds the descendants of all elements found by the receiver.
返回一个新的查询,该查询查找接收器所找到的所有元素的后代。
- containing​Predicate:​​
Returns a new query for finding elements that contain a descendant matching the specification.
返回一个新的查询,用于查找包含与规范匹配的后代的元素。
- containing​Type:​​identifier:​​
- matching​Identifier:​​
- matching​Predicate:​​
Returns a new query that applies the specified attributes or predicate to the receiver.
返回将指定的属性或谓词应用到接收器的新查询。
- matching​Type:​​identifier:​​

Accessing Matched Elements 获取匹配元素

all​Elements​Bound​By​Accessibility​Element
Immediately evaluates the query and returns an array of elements bound to the resulting accessibility elements.
立即计算查询并返回绑定到可访问元素的元素数组。
all​Elements​Bound​By​Index
Immediately evaluates the query and returns an array of elements bound by the index of each result.
立即计算查询并返回由每个结果的索引绑定的元素数组。
count
Evaluates the query at the time it is called and returns the number of matches found.
在调用时计算查询并返回找到的匹配数。
element
Returns an element that will use the query for resolution.
返回将使用查询进行解析的元素。
- element​At​Index:​​
Returns an element that will resolve to the index into the query's result set.
返回将该索引解析为查询结果集的元素。
- element​Bound​By​Index:​​
Returns an element that will use the index into the query's results to determine which underlying accessibility element it is matched with.
返回将该索引应用到查询结果中以确定与其匹配的基本可访问性元素的元素。
- element​Matching​Predicate:​​
Returns an element that matches the predicate.
返回与谓词匹配的元素。
- element​Matching​Type:​​identifier:​​
Returns an element that matches the type and identifier.
返回与类型和标识符相匹配的元素。
- object​For​Keyed​Subscript:​​
Returns a descendant element matching the identifier specified by key.
返回与密钥指定的标识符相匹配的后代元素。

Relationships 关系

Inherits From 继承

NSObject

Conforms To 符合

XCUIElement​Type​Query​Provider


Class 类

XCUIElement 官方

A user interface element in an application.
应用程序中的用户界面元素。

Language 语言

Swift Objective-C

Overview 概述

In macOS, XCUIElement provides keyboard- and mouse-like interactions such as typing, hovering, clicking, and scrolling. On iOS, XCUIElement provides gestural interactions such as tapping, pressing, swiping, pinching, and rotating.
在MacOS,xcuielement提供键盘和鼠标等相互作用如打字、悬停、点击和滚动。在iOS上,xcuielement提供手势的交互如攻丝、压制、刷卡,捏和旋转。

Symbols 符号

Element State 元件状态

exists
Test to determine if the element exists.
测试以确定元素是否存在。
hittable
Whether or not a hit point can be computed for the element for the purpose of synthesizing events.
为了合成事件,是否可以计算元素的命中点。
debug​Description
Provides debugging information about the element.
提供有关元素的调试信息。

Querying Descendant Elements 查询子元素

- children​Matching​Type:​​
Returns a query for direct children of the element matching the specified type.
返回与指定类型匹配的元素的直接子类的查询。
- descendants​Matching​Type:​​
Returns a query for all descendants of the element matching the specified type.
返回与指定类型匹配的元素的所有后代的查询。
输入文本

Typing Text 输入文本

- type​Text:​​
Types a string into the element.
在元素中输入一个字符串。

Using Key Modifiers 使用关键修饰符

Available in macOS only. 只有在MacOS可用。
- type​Key:​​modifier​Flags:​​
Types a single key with the specified modifier flags.
使用指定的修饰符标记类型的单个键。
+ perform​With​Key​Modifiers:​​block:​​
Executes block with the given modifier keys held down.
执行块与给定的修改键按住。

Moving the Cursor 移动光标

Available in macOS only. 只有在MacOS可用。
- hover
Moves the cursor over the element.
将光标移动到元素上。

Clicking

Available in macOS only. 只有在MacOS可用。
- click
Sends a click event to a hittable point computed for the element.
发送一个单击事件到碰撞点的元计算。
- click​For​Duration:​​then​Drag​To​Element:​​
Clicks and holds for a specified duration (generally long enough to start a drag operation) then drags to the other element.
点击保存指定的时间(通常是足够长的时间来开始拖动操作)然后拖动到其他元素。
- double​Click
Sends a double click event to a hittable point computed for the element.
发送一个双击一个碰撞点的元计算。
- right​Click
Sends a right click event to a hittable point computed for the element.
发送一个右键单击事件的一个碰撞点的元计算。

Scrolling 滚动

Available in macOS only. 只有在MacOS可用。
- scroll​By​Delta​X:​​delta​Y:​​
Scrolls the view by the specified number of x and y pixels.
按指定数量的x和y像素滚动视图。

Performing Gestures 表演的手势

Available on iOS only. 只有在iOS可用。
- tap
Sends a tap event to a hittable point computed for the element.
发送一个点击事件到碰撞点的元计算。
- double​Tap
Sends a double tap event to a hittable point computed for the element.
发送一个双击事件到碰撞点的元计算。
- two​Finger​Tap
Sends a two finger tap event to a hittable point computed for the element.
结束一二个手指事件到碰撞点的元计算。
- tap​With​Number​Of​Taps:​​number​Of​Touches:​​
Sends one or more taps with one or more touch points.
用一个或多个触摸点发送一个或多个水龙头。
- press​For​Duration:​​
Sends a long press gesture to a hittable point computed for the element, holding for the specified duration.
发送一个长按手势在碰撞点的元计算,持有指定的时间。
- press​For​Duration:​​then​Drag​To​Element:​​
Initiates a press-and-hold gesture, then drags to another element.
启动一个按住手势,然后拖动到另一个元素。
- swipe​Left
Sends a swipe-left gesture.
发送左键手势。
- swipe​Right
Sends a swipe-right gesture.
发送右键手势。
- swipe​Up
Sends a swipe-up gesture.
发送一个上手势。
- swipe​Down
Sends a swipe-down gesture.
发送一个向下的手势。
- pinch​With​Scale:​​velocity:​​
Sends a pinching gesture with two touches.
发送一个捏的手势两触动。
- rotate:​​with​Velocity:​​
Sends a rotation gesture with two touches.
发送两个触摸的旋转手势。

Interacting with Sliders

These methods provide functionality for automating interactions with UISlider and NSSlider. 这些方法提供自动化的相互作用与UISlider和NSSlider的功能。
normalized​Slider​Position
Returns the position of the slider's indicator as a normalized value where 0 corresponds to the minimum value of the slider and 1 corresponds to its maximum value.
将滑块指示器的位置返回到一个标准值,其中0对应于滑块的最小值,1对应于它的最大值。
- adjust​To​Normalized​Slider​Position:​​
Manipulates the UI to change the displayed value of the slider to one based on a normalized position. 0 corresponds to the minimum value of the slider, 1 corresponds to its maximum value. The adjustment is a "best effort" to move the indicator to the desired position; absolute fidelity is not guaranteed.
操纵UI改变滑块的显示值为基于归一化的位置。0对应滑块的最小值,1对应其最大值。调整是一个“最好的努力”移动指示器到所需的位置,绝对保真度不能保证。

Interacting with Pickers 与采摘

This method provides functionality for automating the picker wheels of UIPicker​View and UIDate​Picker controls.
该方法自动uipicker​观和uidate​选择器控制选择器的车轮提供的功能。

- adjust​To​Picker​Wheel​Value:​​
Changes the displayed value for the picker wheel. Will generate a test failure if the specified value is not available.
改变显示值为拾取轮。如果指定的值不可用,将产生测试失败。

Calculating Coordinates

- coordinate​With​Normalized​Offset:​​
Creates and returns a new coordinate with a normalized offset.
创建并返回具有标准化偏移量的新坐标。

Relationships 关系

Inherits From 继承

NSObject

Conforms To 符合

XCUIElement​Attributes,
XCUIElement​Type​Query​Provider


Class

XCTest 官方

An abstract base class for testing.
用于测试的抽象基类。

Language 语言

Swift Objective-C

Overview 概述

XCTest is the base class for XCTest​Case and XCTest​Suite, and defines common functionality for creating, managing, and executing tests. In most cases, you should subclass XCTest​Case directly when defining tests in your project.
xctest是xctest​案例和xctest​套件的基类,定义了通用的功能用于创建、管理和执行测试。在大多数情况下,你应该xctest​类直接当你在项目中定义的测试。

Symbols 符号

Test Properties 测试性能

name
The name of the test.
测试名称。
test​Case​Count
The number of test cases in this test.
本次测试用例数。
test​Run
The XCTest​Run object that executed the test.
xctest​运行对象,执行测试。
test​Run​Class
The XCTest​Run subclass to instantiate when the test is run, to hold the test's results.
xctest​运行子类来实例化测试运行时,测试结果。

Setup and Teardown 安装和拆卸

- set​Up
Called before the invocation of each test method in the class.
在类中的每个测试方法调用之前调用。
- tear​Down
Called after the invocation of each test method in the class.
调用类中的每个测试方法后调用。

Running Tests 运行测试

- perform​Test:​​
The method through which tests are executed.
执行测试的方法。
- run​Test
Creates an instance of the class specified by test​Run​Class and passes it as a parameter to the perform​Test:​ method.
创建测试运行的​​类指定的类的一个实例并把它作为一个参数来执行​测试:​方法。

Relationships 关系

Inherits From 继承

NSObject


Class 类

XCTestAssertions 官方

Assertions Listed by Category 按类别列出的断言

XCTestAssertions are categorized into five groups. ... Unconditional Fail, Equality Tests, Nil Tests, Boolean
xctestassertions分成五组。…无条件失效,相等检验,零检验,布尔

The following sections list the XCTest assertions. You can obtain more information on XCTest assertions by referencing XCTestAssertions.h in Xcode using Quick Help.
下面列出xctest断言。你可以通过引用xctest断言xctestassertions获取更多信息。利用快速帮助在Xcode。

无条件失败

XCTFail。无条件的返回失败
XCTFail(format...)

等于测试

XCTAssertEqualObjects。当表达式1不等于表达式2(或一个对象是nil另一个不是)时返回失败。
XCTAssertEqualObjects(expression1, expression2, format...)

XCTAssertNotEqualObjects。当表达式1等于表达式2时返回失败。
XCTAssertNotEqualObjects(expression1, expression2, format...)

XCTAssertEqual。当表达式1不等于表达式2时返回失败。用于测试标量值。
XCTAssertEqual(expression1, expression2, format...)

XCTAssertNotEqual。当表达式1等于表达式2时返回失败。用于测试标量值。
XCTAssertNotEqual(expression1, expression2, format...)

XCTAssertEqualWithAccuracy。当表达式1与表达式2之间的差值大于accuracy。这个测试用于标量值如float、double。
XCTAssertEqualWithAccuracy(expression1, expression2, accuracy, format...)

XCTAssertNotEqualWithAccuracy。当表达式1与表达式2之间的差值小于或等于accuracy。这个测试用于标量值如float、double。
XCTAssertNotEqualWithAccuracy(expression1, expression2, accuracy, format...)

XCTAssertGreaterThan。当表达式1小于或等于表达式2时返回失败。用于测试标量值。
XCTAssertGreaterThan(expression1, expression2, format...)

XCTAssertGreaterThanOrEqual。当表达式1小于表达式2时返回失败。用于测试标量值。
XCTAssertGreaterThanOrEqual(expression1, expression2, format...)

XCTAssertLessThan。当表达式1大于或等于表达式2时返回失败。用于测试标量值。
XCTAssertLessThan(expression1, expression2, format...)

XCTAssertLessThanOrEqual。当表达式1大于表达式2时返回失败。用于测试标量值。
XCTAssertLessThanOrEqual(expression1, expression2, format...)

nil测试

XCTAssertNil。当表达式参数不是是nil时返回失败。
XCTAssertNil(expression, format...)

XCTAssertNotNil。当表达式参数是nil时返回失败。
XCTAssertNotNil(expression, format...)

布尔测试

XCTAssertTrue。当表达式计算结果为false时返回失败。
XCTAssertTrue(expression, format...)

XCTAssert。当表达式计算结果为false时返回失败。XCTAssertTrue的代名词。
XCTAssert(expression, format...)

XCTAssertFalse。当表达式计算结果为true时返回失败。
XCTAssertFalse(expression, format...)

异常测试

XCTAssertThrows。当表达式不抛出异常时返回失败。
XCTAssertThrows(expression, format...)

XCTAssertThrowsSpecific。当表达式不抛出特定类的异常时返回失败。
XCTAssertThrowsSpecific(expression, exception_class, format...)

XCTAssertThrowsSpecificNamed。当表达式不抛出特定类的特定名称的异常则返回失败。AppKit framework或Foundation抛出的异常名字以NSException开头(NSInvalidArgumentException等等)。
XCTAssertThrowsSpecificNamed(expression, exception_class, exception_name, format...)

XCTAssertNoThrow。当表达式抛出异常时返回失败。
XCTAssertNoThrow(expression, format...)

XCTAssertNoThrowSpecific。当表达式抛出指定类的异常时返回失败。其他任何异常都通过,即,不返回失败。
XCTAssertNoThrowSpecific(expression, exception_class, format...)

XCTAssertNoThrowSpecificNamed。当表达式抛出特定类的特定名称的异常时返回失败。AppKit framework或Foundation抛出的异常名字以NSException开头(NSInvalidArgumentException等等)。
XCTAssertNoThrowSpecificNamed(expression, exception_class, exception_name, format...)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容