如何使用UIAutomation進行iOS 自動化測試(Part II)
3. 經驗分享(讓你生活變得更簡單)
類庫Tune-up介紹
現在你應該基本上知道如何編寫測試程式碼了。但你慢慢地會發現,你會經常寫到一些重複的,冗餘的,黏糊糊的程式碼,像下面一樣:
1 2 3 |
var target
= UIATarget.localTarget();
var app
= target.frontMostApp();
var window
= app.mainWindow();
|
這也是為什麼我們會用到一個小的Javascript類庫來簡化我們寫的UIAutomation測試的原因。你可以去
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#import
"tuneup/tuneup.js"
test( "Test
1" ,
function (target,
app) {
var window
= app.mainWindow();
app.logElementTree();
//--
select the elements
UIALogger.logMessage(
"Select
the first tab" );
var tabBar
= app.tabBar();
var selectedTabName
= tabBar.selectedButton().name();
if (selectedTabName
!= "First" )
{
tabBar.buttons()[ "First" ].tap();
}
//--
tap on the text fiels
UIALogger.logMessage(
"Tap
on the text field now" );
var recipeName
= "Unusually
Long Name for a Recipe" ;
window.textFields()[0].setValue(recipeName);
target.delay(
2 );
//--
tap on the text fiels
UIALogger.logMessage(
"Dismiss
the keyboard" );
app.logElementTree();
app.keyboard().buttons()[ "return"
|