【发布时间】:2017-10-09 09:48:41
【问题描述】:
我正在研究来自 facebook 的 UI 测试框架 WebDriverAgent。它非常棒而且很有帮助。几乎囊括了iOS UI测试的所有知识。
XCTest 有许多非公开的类和属性。例如,XCUIElement 有一个名为 lastSnapshot 的属性,lastSnapshot 也有很多有用的属性,如 label、identifier、frame、parent 、儿童、pathDescription等。问题来了:
children 属性用于从某个元素中获取所有子元素,就像视图中的子视图一样。但是当我试图从元素的 lastSnapshot 中获取 children 的值时,它总是为空的。虽然我可以正确地获取标签、标识符、父级等其他属性的值。这确实困扰了我好几天。这是示例代码:
- (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的一个类来递归元素树:
标签: ios children xcode-ui-testing