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.
將在啟動時傳遞給應用程序的參數(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...)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,837評論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,196評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,688評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,654評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,456評論 6 406
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 54,955評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,044評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,195評論 0 287
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,725評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 40,608評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,802評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,318評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,048評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,422評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,673評論 1 281
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,424評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,762評論 2 372

推薦閱讀更多精彩內(nèi)容