自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

IOS 4中實(shí)現(xiàn)UI自動(dòng)測(cè)試教程

移動(dòng)開發(fā) iOS
本文介紹的IOS 4中實(shí)現(xiàn)UI自動(dòng)測(cè)試教程,主要介紹了IOS中UI的實(shí)現(xiàn),我們來看內(nèi)容。

IOS 4中實(shí)現(xiàn)UI自動(dòng)測(cè)試教程是本文要介紹的內(nèi)容,這篇文章的對(duì)象是 iOS 4 的初學(xué)者,我希望一個(gè)典型的iPhone 開發(fā)者能夠通過這篇文章掌握自動(dòng)設(shè)置UI測(cè)試的方法。

UI 自動(dòng)測(cè)試iOS 4中重要的附加功能,它由名為“Automation”的新的工具對(duì)象支持,非常適合Producitivity風(fēng)格應(yīng)用的UI測(cè)試。

Automation工具從腳本工作(用JavaScript語言編寫),它在應(yīng)用上模仿/擊發(fā)被請(qǐng)求的事件。測(cè)試腳本必須是可靠的可執(zhí)行JavaScript文件,而且該文件可獲取主機(jī)的工具。

什么是測(cè)試腳本?

測(cè)試腳本是有順序的命令集合,每一個(gè)命令獲取一個(gè)應(yīng)用中的用戶接口組件,然后在上面執(zhí)行一個(gè)用戶行為,或者使用與之相關(guān)的信息。

描述

我使用的應(yīng)用例子有一個(gè)名為“登陸”的屏幕,包含兩個(gè)文本域名:分別是“用戶名”和“密碼”,以及一個(gè)“登陸”按鈕。

寫測(cè)試腳本之前,在“Interface Builder”中標(biāo)記所有的UI控制,在視圖中將可存取性標(biāo)簽設(shè)置成一個(gè)唯一值(必須)。

在調(diào)試模式中編譯你的應(yīng)用

測(cè)試腳本:

正如我上面提到的,測(cè)試腳本基本上是有順序的命令集合。換言之,它將文本測(cè)試的例子轉(zhuǎn)換成可以被“Automation”工具自動(dòng)執(zhí)行的JavaScript

下面是測(cè)試腳本的例子

  1.  // Get the handle of applications main window  
  2. var window = UIATarget.localTarget().frontMostApp().mainWindow();   
  3.    
  4. // Get the handle of view  
  5. var view = window.elements()[0];   
  6.    
  7. var textfields = window.textFields();  
  8. var passwordfields = window.secureTextFields();  
  9. var buttons = window.buttons();  
  10. var textviews = window.textViews();  
  11. var statictexts = window.staticTexts();  
  12. var target = UIATarget.localTarget();   
  13.    
  14. // Check number of Text field(s)  
  15. if(textfields.length!=1)  
  16. {  
  17.    UIALogger.logFail("FAIL: Inavlid number of Text field(s)");  
  18. }  
  19. else  
  20. {  
  21.    UIALogger.logPass("PASS: Correct number of Text field(s)");  
  22. }  
  23. // Check number of Secure field(s)  
  24. if(passwordfields.length!=1)  
  25. {  
  26.    UIALogger.logFail("FAIL: Inavlid number of Secure field(s)");  
  27. }  
  28. else  
  29. {  
  30.    UIALogger.logPass("PASS: Correct number of Secure field(s)");  
  31. }   
  32.    
  33. // Check number of static field(s)  
  34. if(statictexts.length!=2)  
  35. {  
  36.    UIALogger.logFail("FAIL: Inavlid number of static field(s)");  
  37. }  
  38. else  
  39. {  
  40.    UIALogger.logPass("PASS: Correct number of static field(s)");  
  41. }   
  42. // Check number of buttons(s)  
  43. if(buttons.length!=1)  
  44. {  
  45.    UIALogger.logFail("FAIL: Inavlid number of button(s)");  
  46. }  
  47. else  
  48. {  
  49.    UIALogger.logPass("PASS: Correct number of button(s)");  
  50. }   
  51. //TESTCASE_001 : Test Log on Screen  
  52. //Check existence of desired TextField On UIScreen  
  53. if(textfields["username"]==null || textfields["username"].toString() == "[object UIAElementNil]")  
  54. {  
  55.    UIALogger.logFail("FAIL:Desired textfield not found.");  
  56. }  
  57. else  
  58. {  
  59.    UIALogger.logPass("PASS: Desired UITextField is available");  
  60. }   
  61.    
  62. //TESTCASE_1.2 :Check existence desired of PasswordField On UIScreen  
  63. if(passwordfields[0]==null || passwordfields[0].toString() == "[object UIAElementNil]")  
  64. {  
  65.    UIALogger.logFail("FAIL:Desired UISecureField not found.");  
  66. }  
  67. else  
  68. {  
  69.    UIALogger.logPass("PASS: Desired UISecureField is available");  
  70. }   
  71.    
  72. //TESTCASE_1.3 :Check For Existence of Buttons On UIScreen  
  73. if(buttons["logon"]==null || buttons["logon"].toString() == "[object UIAElementNil]")  
  74. {  
  75.    UIALogger.logFail("FAIL:Desired UIButton not found.");  
  76. }  
  77. else  
  78. {  
  79.    UIALogger.logPass("PASS: Desired UIButton is available");  
  80. }   
  81. //TESTCASE_001 : Missing User Name  
  82. ///////////////////////////////////////   
  83. textfields["username"].setValue("");  
  84. passwordfields[0].setValue("password");  
  85. buttons["logon"].tap();   
  86. //target.delay(2);   
  87. var errorVal=textviews["error"].value();  
  88. if(errorVal!="Invalid User Name or Password")  
  89. {  
  90.    UIALogger.logFail("Did Not Get Missing UserName Error : "+errorVal);  
  91. }  
  92. else  
  93. {  
  94.    UIALogger.logPass("Missing User Name");  
  95. }   
  96. //TESTCASE_002 : Missing Password  
  97. ////////////////////////////////////////////////   
  98. textfields["username"].setValue("username");  
  99. passwordfields[0].setValue("");  
  100. buttons["logon"].tap();  
  101. target.delay(2);   
  102.    
  103. var errorVal=textviews["error"].value();  
  104. if(errorVal!="Invalid User Name or Password")  
  105. {  
  106.    UIALogger.logFail("Did Not Get Missing Password Error : "+errorVal);  
  107. }  
  108. else  
  109. {  
  110.    UIALogger.logPass(" Missing Password");  
  111. }   
  112. //TESTCASE_003 : Successful Log On  
  113. textfields["username"].setValue("username");  
  114. passwordfields[0].setValue("password");  
  115. buttons["logon"].tap();  
  116. target.delay(2);  

應(yīng)用中的所有UI組件通過有次序的對(duì)象層級(jí)結(jié)構(gòu)傳達(dá)給腳本,該層次結(jié)構(gòu)通過UIAElements類定義,包括UIATarget、UIALogger等子類。

請(qǐng)參照蘋果開發(fā)者網(wǎng)站的UI Automation Reference Collection獲取更多信息。

完成腳本之后按下列步驟執(zhí)行。

第一步

打開Instruments(你可以在Spotlight中找到它),在樣本選擇窗口中選擇“Automation”

第二步

Trace窗口會(huì)打開,在“Choose Target”下拉窗口的幫助下選擇應(yīng)用的調(diào)試版本。

第三步

使用“Script”下拉窗口選擇測(cè)試腳本文件,然后點(diǎn)擊“Run and Record”按鈕。

之后會(huì)自動(dòng)運(yùn)行“iPhone Simulator”,并開始執(zhí)行測(cè)試腳本(可能花費(fèi)4-5秒時(shí)間)。

可重用的測(cè)試腳本

API提供一個(gè)#import指令,你可以用它編寫更小的、可重用的、分離的測(cè)試腳本。

例如:如果你準(zhǔn)備在文件 TestUtilities.js中定義常用函數(shù),你可以在腳本中加入命令行 #import”<path-to-library-folder>/TestUtilities.js”,從而使你的測(cè)試腳本能夠使用這些函數(shù)。

測(cè)試樣本代碼的硬件要求

帶有 Snow Leopard 10.6(或者更高版本)和iOS SDK 4.0 的Mac Mini(Intel處理器版本)

(1)解壓附件“LoginWindow_src.zip”,在調(diào)試模式下編譯它,并在模擬器Simulator上進(jìn)行測(cè)試。

(2)“用戶名/密碼”是可靠證明;在相應(yīng)的“User ID”和“Password”字段中填寫值。

你遇到“Unexpected error…”了?
“Unexpected error in -[UIATarget_0x5a20d20 frontMostApp], /SourceCache/UIAutomation_Sim/UIAutomation-37/Framework/UIATargetElements.m line 437″

如果你遇到了這個(gè)錯(cuò)誤,復(fù)制一個(gè) com.apple.Accessibility.plist 到4.0.1就可以解決這個(gè)問題。

復(fù)制com.apple.Accessibility.plist 到~/Library/Application Support/iPhone Simulator/4.0.1/Library/Preferences

確保這個(gè)文件中僅有兩個(gè)分別名為“AccessibilityEnabled”和“ApplicationAccessibilityEnabled”的鍵值,并且都經(jīng)過效驗(yàn)。

小結(jié):IOS 4中實(shí)現(xiàn)UI自動(dòng)測(cè)試教程的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-08-03 11:17:50

iOS程序 測(cè)試

2009-08-27 14:09:09

布線測(cè)試跳線測(cè)試串?dāng)_測(cè)試

2023-03-17 16:32:51

測(cè)試軟件開發(fā)

2023-07-17 13:57:05

2023-06-05 07:49:13

?左移測(cè)試敏捷

2009-07-06 10:22:26

Web網(wǎng)站壓力測(cè)試

2019-02-15 15:07:39

AndroidiOS移動(dòng)系統(tǒng)

2011-08-30 11:09:26

MySQL ProxyLua

2019-11-26 17:44:16

AI 數(shù)據(jù)人工智能

2023-06-27 17:50:22

2023-03-30 16:50:18

2014-04-02 10:29:12

iOS 7模糊效果

2010-01-28 09:07:50

Visual Stud

2017-03-28 12:25:36

2021-06-26 07:40:21

前端自動(dòng)化測(cè)試Jest

2016-12-08 08:25:39

QA自動(dòng)測(cè)試Angular 2

2009-12-23 16:33:34

WPF UI自動(dòng)化測(cè)試

2020-08-03 15:40:57

Web自動(dòng)化工具測(cè)試

2023-03-10 15:11:24

2021-10-18 12:01:17

iOS自動(dòng)化測(cè)試Trip
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)