我正在研究UI測試框架WebDriverAgent來自facebook。這非常棒,樂於助人。它幾乎包含iOS UI測試的所有知識。iOS UI中元素的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類來遞歸元素樹: –