2012-02-11 15 views
0

私はiPhone用のUITestingを試しています。最初のテストを実行するには、スタンフォードのcs193p iTunes Uクラスの講義2の単純なrpn電卓を使用すると思いました。スクリプトが罪を実行しかしiphone UITestingボタン番号

var target = UIATarget.localTarget(); 

target.frontMostApp().mainWindow().buttons()["3"].tap(); 
target.frontMostApp().mainWindow().buttons()["Enter"].tap(); 
target.frontMostApp().mainWindow().buttons()["4"].tap(); 
target.frontMostApp().mainWindow().buttons()["/"].tap(); 

var display = target.frontMostApp().mainWindow().staticTexts()[1].value(); 
if (display == "0.75") { 
    UIALogger.logPass("3 E 4 /"); 
} else { 
    UIALogger.logFail("3 E 4 /"); 
} 

次のように

私のjavascriptのは、ある編集者のCoS/ が、それはそう何とか楽器を

target.frontMostApp().mainWindow().buttons()[3].tap(); 
target.frontMostApp().mainWindow().buttons()["Enter"].tap(); 
target.frontMostApp().mainWindow().buttons()[4].tap(); 
target.frontMostApp().mainWindow().buttons()["/"].tap(); 

を示しているログに私の文字列「3」に変換されて入力してください3番目のボタンをタップします。

私はインデックス番号でボタンを呼び出すことができましたが、テキストで呼び出すことを好むでしょう。

答えて

1

UIAElementArrayにアクセスするために角かっこを使用すると、数値がインデックスとして扱われるため、制限があります。 8-(

代わりにちょうどfirstWithName()を追加します。

target.frontMostApp().mainWindow().buttons().firstWithName("3").tap(); 

UIAElementArray Class Reference

を参照してください。
関連する問題