【发布时间】:2016-02-02 15:45:42
【问题描述】:
如何在 iOS9/XCode7 UItesting 功能中检测当前的 SKScene?
我尝试将 SKScene 的 accessibilityIdentifier 设置为 SKScene 的 init 方法中的标识符字符串,但这似乎没有显示在 UI 测试中使用
XCUIElement *element =
[[[_app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0]
childrenMatchingType:XCUIElementTypeOther].element;
通过在下面添加 UILabel,使用部分有效的 hack 更新了问题:
我将以下代码添加到我的 SKScene 中
-(void)didMoveToView:(SKView *)view
{
// This is not detected by the test case.
self.accessibilityLabel = @"SceneMenu";
self.accessibilityValue = @"anything";
self.isAccessibilityElement = true;
// This is detected by the test case.
self.currentScene = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.size.width, 25)];
[self.view addSubview:_currentScene];
self.currentScene.accessibilityLabel = @"SceneMenu2";
}
然后我可以在我的 UI 测试用例中检测到“SceneMenu2”,但我无法检测到“SceneMenu”。怎么会?这是我的测试用例:
-(bool)sceneMenuIsShown
{
return [_app.otherElements containingType:XCUIElementTypeStaticText identifier:@"SceneMenu2"].count == 1;
}
- (void)testExample
{
while (![self sceneMenuIsShown])
{
}
}
【问题讨论】:
标签: sprite-kit ios9 coded-ui-tests