6

Xcode の「Instruments」ツールを使用して iOS アプリケーションの自動化を構築していますが、アプリで作成したエントリのラベルが正しいことを確認する必要があります。

以下にリストされているコードは、何らかの理由で、確実な合格または不合格になりません。むしろ、実行すると、ログに「問題」の警告が表示され、明示的に閉じずにテストが終了します。

自動化の実行後に AccessibilityViewer で確認できるため、作成されていることがわかっているラベル名を確認するようにテストを変更したいと考えています。

ラベルが正しければ、テストを合格として記録したいと思います。

以前UIATarget.localTarget().logElementTree()は要素ツリーをマッピングし、AccessibilityInspector を使用して、エントリが作成された後にラベルの名前を確認しました。問題は、これが正しいことを確認するための構文を取得できないように見えることです。

My Accessibility Inspector は、ラベル名が MyDogs! であることを確認しました。静的テキストの特性を持ち、{{114, 0},{166,480}} のフレームを提供します

要素ツリーを見ると、ここに貼り付けたいと思いますが、ラベルは次のパスに沿って見つかるようです。

\Target
-+
--\Application
---+
----\Window
-----+
------\TableView
-------+
--------\TableCell: name:MyDogs! rect:{0, 40},{480,166}}
---------|UIAStaticText: name:MyDogs! value:MyDogs! rect:{{0, 40},{480, 166}}
---------|UIAButton: name:story list share rect:{{439, 41},{33, 28}}

このラベルを確認する方法を誰か教えてもらえますか?

私の現在のコードは次のようになります(ただし、ラベルをチェックしていません-方法がわからないため):

var testName = "LoginCreateEntry";

//Start test logging
UIALogger.logStart(testName);

//This is supposed to target the entry that my automation has created.
//The flow goes, run the automation that creates the entry, then verify that the entry
//got created as expected and is visible to the user in the iPhone interface.

    var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].value(); 

    var entryName = "My Dogs!";

//Do a bunch of UI automation here to create my entry, which results in the entry
//appearing in the mainWindow with the label: My Dogs!

//If myEntry evaluates to true, then call this test a pass.

if (myEntry === entryName) {    
UIALogger.logMessage("My entry was created!");

    //Mark the test as a PASS
    UIALogger.logPass(testName);
}
else {

    UIALogger.logMessage("My entry was not created!");

    //Mark the test as a FAIL
    UIALogger.logFail(testName); 
    }

//End test

フィードバックやヘルプをいただければ幸いです!!

- - - - - - - - - - - - - - - - -アップデート - - - - - - - - ----------------------
ご協力ありがとうございました!実際にタイトルの値を取得したので、以下にソリューションを表示します。しかし、何をしても合格/不合格のログ機能を正しく動作させることはできません。また、この問題は他の人にも発生しています。私は激怒を得続けます

Issue: Script ended without explicting closing this test

テスト終了時のメッセージ。これは Instruments のバグだと確信しています。

これが私の更新されたテストです:

var target = UIATarget.localTarget();
var app = UIATarget.localTarget().frontMostApp();

var testName = "LoginCreateEntry";

//Start test logging
UIALogger.logStart( testName );

//Do lots of gui automation stuff here to create the entry which will appear in my app interface.
//I want to verify that the title I gave the entry matches what appears in the app interface

var window = app.mainWindow();
var tableView = window.tableViews()[0];
var tableGroup = tableView.groups()[0];
var entryName = "My Dogs!";

var myEntry = tableView.cells()[0].name(); //<-- This is what I needed!!!

UIALogger.logMessage("My Story Title: " + myEntry); //Print out entry name in log

if (myEntry === entryName) {    

    UIALogger.logMessage("My entry was created!");

    //Mark the test as a PASS
    UIALogger.logPass (testName);

} else {

    UIALogger.logMessage("My entry was not created!");

    //Mark the test as a FAIL
    UIALogger.loFails (testName); 

    }
//End test 
4

2 に答える 2

5

少なくとも2012年の夏とiOS5の時点では、accessibilityIdentifierも設定されていない限り、accessibilityLabelでUIA要素にアクセスできないことがわかりました。

そして残念ながら、その時点で(そしてXcode 4.2の時点で)、accessibilityIdentifierはコードでのみ設定でき、InterfaceBuilderでは設定できませんでした。それ以来、状況が改善したかどうかはわかりません。詳細については、このSOの質問を参照してください。

Interface Builderでアクセシビリティ識別子を設定できますか?Xcode4.2

ただし、前述したように、アプリのソースにアクセスできる場合は、automationIdentifierによるUIAアクセスを機能させることができます。(または、アクセス権を持つ誰かに影響を与えることができると思います!)

githubにプロジェクトがあり、UILabel(アプリソース内)でaccessibilityIdentifierを設定し、コードが実行しようとしているように見える方法で要素に正常にアクセスするUIAテストを作成する方法を示しています。

最初はテストファイルです。ここで、文字列「!」を表示するUILabelを見つけようとします。

https://github.com/billagee/UnicodeTapper-iphone4.2/blob/master/UnicodeTapperTests/tests.js

    // for iOS 5 - note 4 must be handled differently
    var charDisplayed = window.staticTexts()["bigCharLabel"].value();
    if (charDisplayed == "!") {
        UIALogger.logPass("Exclamation point displayed at startup");
    } else {
        UIALogger.logFail("Incorrect character displayed: " + charDisplayed);
    }

次に、ターゲットアプリのソースで、UILabelのアクセシビリティ属性を設定すると次のようになります。

// If device supports it, set accessibility identifiers for the UILabels
// in order to find them in UIAutomation easily.  Note that the
// accessibilityIdentifier can't be set in IB yet, as of Xcode 4.3.3;
// also, it's only supported in iOS 5 and up.
topBarLabel.isAccessibilityElement = YES;
bigCharLabel.isAccessibilityElement = YES;
if ([topBarLabel respondsToSelector:@selector(accessibilityIdentifier)]) {
    topBarLabel.accessibilityIdentifier = @"topBarLabel";
    bigCharLabel.accessibilityIdentifier = @"bigCharLabel";
} else {
    topBarLabel.accessibilityLabel = @"topBarLabel";
    bigCharLabel.accessibilityLabel = @"bigCharLabel";        
}

完全なソースはここにあります:

https://github.com/billagee/UnicodeTapper-iphone4.2/blob/master/UnicodeTapper/UnicodeTapperViewController.m

于 2013-03-06T06:55:28.453 に答える
5

tuneup_jsの使用をお勧めします。そのライブラリを使用すると、簡単にテスト ケースを作成し、ラベルが存在し、ラベルが等しいかどうかを確認できます。My Dogs

こんな感じで使えます

test("LoginCreateEntry", function(target,app){
    //Create Entry
    //....
    var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].name();

    //Check is Label is equal to My Dogs
    //Test "LoginCreateEntry" will fail if myEntry is not equal to My Dogs
    assertEquals(myEntry, "My Dogs");
});

ラベルの名前を取得するの.name()ではなく、使用する必要がある PS.value()

于 2013-03-06T06:41:00.663 に答える