2011-03-01 5 views
1

iOS 4.2でのプロジェクトの品質テストについては、Xcode 3.xのInstrumentsを使用してUIAutomationで作業しています。私たちはJavascriptでスクリプトを書いています。私はJavascriptを初めて使用しており、UIAutomationのドキュメントが(「これをどのように置くべきか」)、「疎」であることが判明しました。XcodeのUIAutomationとInstrumentsのJavascriptを使用したボタンオブジェクトの存在の確認

iOSアプリケーションのメインウィンドウに表示される「ビープ音」というボタンの存在を確認する方法について、Etherのある天才が私に教えてくれることを期待していますか?

また、テストスクリプト(動的Webページとは対照的に)をJavaScriptで記述するための参考資料がありますか?

ありがとうございました!

よろしく、

スティーブ・オサリバン

答えて

3

ねえ。
実際には、Appleからの文書(thisthis)が私が見つけることができる唯一のものです。
あなたの質問については想定している。もちろん、

if(UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].name() === "beep sound")) { 
    UIALogger.logPass("Buton Present"); 
} else { 
    UIALogger.logFail("Buton Not Present"); 
}; 

要素を()[0])あなたのボタンは、メインウィンドウの下のオブジェクトツリーの最初であることをしてみてください。そうでない場合は、他の要素((要素()3)を呼び出す必要があります。または、(要素(階層深くに呼び​​出す必要があります)[0] .elements()3)。
キープチェーン内のオブジェクトの1つが存在しない場合、上記のコードは失敗することに注意してくださいチェーン内のすべてのオブジェクトをチェックする必要があるかもしれませんさらに、特定のボタンが存在するだけでなく、 。この場合、上記のコードは次のように見て必要があります。

if(UAITarget.localTarget().frontMostApplication().mainWindow() && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0] && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate("name matches 'beep sound'")) { 
    if(UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].isVisible()) { 
     UIALogger.logPass("Buton Present"); 
    } else { 
     UIALogger.logFail("Buton Present, but Not Visible"); 
    } 
} else { 
    UIALogger.logFail("Buton Not Present"); 
}; 

しかし、今可読性、保守性、およびコードの-ity属性の上に苦しむだから私はトンそれをリファクタリングします。 o:

function isButtonWithPredicate (predicate) { 
    if(UAITarget.localTarget().frontMostApplication().mainWindow() && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0] && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate(predicate)) { 
    return true; 
} else { 
    throw new Error("button not found, predicate: " + predicate); 
} 

function getButtonWithPredicate (predicate) { 
    try { 
     if(isButtonWithPredicate(predicate)) { 
      return UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate(predicate); 
     } 
    } catch (error) { 
     throw new Error("getButtonWithPredicateError: " + error.message); 
    }; 
} 


var strpredicate = "name matches 'beep sound'"; 
var objButton = null; 
try{ 
    objButton = getButtonWithPredicate(strPredicate); 
    if(objButton.isVisible) { 
     UIALogger.logPass("Buton Present"); 
    }; 
} catch(error) { 
    UIALogger.logFail(error.message); 
} 

もちろん、改善することはできますが、そのアイデアを得る必要があります。ところでapple guide to predicates

P.S.

コードはメモ帳で書かれており、チェックされていないため、解析エラーが含まれている可能性があります。

関連する問題