私はUIテストフレームワークを勉強していますWebDriverAgent facebookから。それは非常に素晴らしく役立ちます。これには、iOSのUIテストに関する知識がほとんど含まれています。iOS UI Testingの要素のlastSnapshotからの子のプロパティは常に空ですが、なぜですか?
XCTestには多くの非公開のクラスとプロパティがあります。例えば、XCUIElementはlastSnapshotという名前のプロパティを持っている、とlastSnapshotもラベル、識別子、フレーム、電気ショック療法親、子供、pathDescription、のように、多くの有用な性質を有します。
子供プロパティは、ビューのサブビューと同様に、特定の要素からすべての子要素を取得するために使用されます。しかし、私が要素のlastSnapshotから子の値を取得しようとすると、常に空になります。私は正しく、ラベル、識別子、親などのような他のプロパティの値を取得することができますが、これは数日間私に苦労します。ここでexapmleコードです:
- (void)testExample {
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *windowElement = [app.windows elementBoundByIndex:2];
XCUIElement *statusBarElement = [windowElement.query elementBoundByIndex:0];
XCUIElement *otherElement = [statusBarElement.query elementBoundByIndex:1];
XCUIElement *timeElement = [otherElement.query elementBoundByIndex:2];
[timeElement query];
[timeElement resolve];
NSLog(@"lastSnapshot = %@", timeElement.lastSnapshot);
NSLog(@"children = %@", timeElement.lastSnapshot.children);
}
WebDriverAgentをビルドする前に、XCUIElementのカテゴリを使用して要素ツリーを再帰的に作成しました。 –