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.
將在啟動時傳遞給應用程序的參數(shù)。
launch?Environment
The environment variables that will be passed to the application on launch.
將在啟動時傳遞給應用程序的環(huán)境變量。
Terminating the Application 終止應用程序
- terminate
Terminates any running instance of the application.
終止應用程序的任何運行實例。
Relationships 關(guān)系
Inherits From 繼承
XCUIElement
Class 類
XCUIElement?Query 官方
A query for locating UI elements.
查找UI元素的查詢。
Language 語言
Swift Objective-C
Symbols 符號
Query State 查詢狀態(tài)
debug?Description
Provides debugging information about the query.
提供有關(guān)查詢的調(diào)試信息。
Creating New Queries 創(chuàng)建新的查詢
- 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.
返回一個新的查詢,用于查找包含與規(guī)范匹配的后代的元素。
- 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.
立即計算查詢并返回綁定到可訪問元素的元素數(shù)組。
all?Elements?Bound?By?Index
Immediately evaluates the query and returns an array of elements bound by the index of each result.
立即計算查詢并返回由每個結(jié)果的索引綁定的元素數(shù)組。
count
Evaluates the query at the time it is called and returns the number of matches found.
在調(diào)用時計算查詢并返回找到的匹配數(shù)。
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.
返回將該索引解析為查詢結(jié)果集的元素。
- 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.
返回將該索引應用到查詢結(jié)果中以確定與其匹配的基本可訪問性元素的元素。
- 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 關(guān)系
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提供手勢的交互如攻絲、壓制、刷卡,捏和旋轉(zhuǎn)。
Symbols 符號
Element State 元件狀態(tài)
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.
提供有關(guān)元素的調(diào)試信息。
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 使用關(guān)鍵修飾符
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.
執(zhí)行塊與給定的修改鍵按住。
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.
發(fā)送一個單擊事件到碰撞點的元計算。
- 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.
發(fā)送一個雙擊一個碰撞點的元計算。
- right?Click
Sends a right click event to a hittable point computed for the element.
發(fā)送一個右鍵單擊事件的一個碰撞點的元計算。
Scrolling 滾動
Available in macOS only. 只有在MacOS可用。
- scroll?By?Delta?X:??delta?Y:??
Scrolls the view by the specified number of x and y pixels.
按指定數(shù)量的x和y像素滾動視圖。
Performing Gestures 表演的手勢
Available on iOS only. 只有在iOS可用。
- tap
Sends a tap event to a hittable point computed for the element.
發(fā)送一個點擊事件到碰撞點的元計算。
- double?Tap
Sends a double tap event to a hittable point computed for the element.
發(fā)送一個雙擊事件到碰撞點的元計算。
- two?Finger?Tap
Sends a two finger tap event to a hittable point computed for the element.
結(jié)束一二個手指事件到碰撞點的元計算。
- tap?With?Number?Of?Taps:??number?Of?Touches:??
Sends one or more taps with one or more touch points.
用一個或多個觸摸點發(fā)送一個或多個水龍頭。
- press?For?Duration:??
Sends a long press gesture to a hittable point computed for the element, holding for the specified duration.
發(fā)送一個長按手勢在碰撞點的元計算,持有指定的時間。
- 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.
發(fā)送左鍵手勢。
- swipe?Right
Sends a swipe-right gesture.
發(fā)送右鍵手勢。
- swipe?Up
Sends a swipe-up gesture.
發(fā)送一個上手勢。
- swipe?Down
Sends a swipe-down gesture.
發(fā)送一個向下的手勢。
- pinch?With?Scale:??velocity:??
Sends a pinching gesture with two touches.
發(fā)送一個捏的手勢兩觸動。
- rotate:??with?Velocity:??
Sends a rotation gesture with two touches.
發(fā)送兩個觸摸的旋轉(zhuǎn)手勢。
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對應其最大值。調(diào)整是一個“最好的努力”移動指示器到所需的位置,絕對保真度不能保證。
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.
改變顯示值為拾取輪。如果指定的值不可用,將產(chǎn)生測試失敗。
Calculating Coordinates
- coordinate?With?Normalized?Offset:??
Creates and returns a new coordinate with a normalized offset.
創(chuàng)建并返回具有標準化偏移量的新坐標。
Relationships 關(guān)系
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?套件的基類,定義了通用的功能用于創(chuàng)建、管理和執(zhí)行測試。在大多數(shù)情況下,你應該xctest?類直接當你在項目中定義的測試。
Symbols 符號
Test Properties 測試性能
name
The name of the test.
測試名稱。
test?Case?Count
The number of test cases in this test.
本次測試用例數(shù)。
test?Run
The XCTest?Run object that executed the test.
xctest?運行對象,執(zhí)行測試。
test?Run?Class
The XCTest?Run subclass to instantiate when the test is run, to hold the test's results.
xctest?運行子類來實例化測試運行時,測試結(jié)果。
Setup and Teardown 安裝和拆卸
- set?Up
Called before the invocation of each test method in the class.
在類中的每個測試方法調(diào)用之前調(diào)用。
- tear?Down
Called after the invocation of each test method in the class.
調(diào)用類中的每個測試方法后調(diào)用。
Running Tests 運行測試
- perform?Test:??
The method through which tests are executed.
執(zhí)行測試的方法。
- run?Test
Creates an instance of the class specified by test?Run?Class and passes it as a parameter to the perform?Test:? method.
創(chuàng)建測試運行的??類指定的類的一個實例并把它作為一個參數(shù)來執(zhí)行?測試:?方法。
Relationships 關(guān)系
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。當表達式參數(shù)不是是nil時返回失敗。
XCTAssertNil(expression, format...)
XCTAssertNotNil。當表達式參數(shù)是nil時返回失敗。
XCTAssertNotNil(expression, format...)
布爾測試
XCTAssertTrue。當表達式計算結(jié)果為false時返回失敗。
XCTAssertTrue(expression, format...)
XCTAssert。當表達式計算結(jié)果為false時返回失敗。XCTAssertTrue的代名詞。
XCTAssert(expression, format...)
XCTAssertFalse。當表達式計算結(jié)果為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...)