0

私はiPhone用のUITestingを試していますが、スタンフォード大学のcs193p iTunes Uクラスの講義2の簡単なrpn計算機を使用して、最初のテストを実行すると思いました。

私のJavaScriptは次のとおりです

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 /");
}

ただし、スクリプトはsin entercosを実行します/エディターログに表示されます

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に変換してから、3番目のボタンをタップしています。

そのため、ボタンをインデックス番号で呼び出すこともできますが、テキストで呼び出す方がはるかに好きです。

4

1 に答える 1

1

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

代わりに追加するだけfirstWithName()です:

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

UIAElementArrayクラスリファレンスを参照してください

于 2012-02-11T03:07:09.800 に答える