XCUItest:检测当前SKView
XCUItest: Detect current SKView
如何在iOS9/XCode7UI测试功能中检测当前 SKScene?
我试图在 SKScene 的 init 方法中将 SKScene 的 accessibilityIdentifier
设置为标识符字符串,但这似乎没有出现在 UI 测试中使用
XCUIElement *element =
[[[_app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0]
childrenMatchingType:XCUIElementTypeOther].element;
Question updated with a partially working hack, by adding an UILabel, below:
我将以下代码添加到我的 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])
{
}
}
这目前是不可能的(据 Apple 工作人员说)。
https://forums.developer.apple.com/thread/25019
如何在iOS9/XCode7UI测试功能中检测当前 SKScene?
我试图在 SKScene 的 init 方法中将 SKScene 的 accessibilityIdentifier
设置为标识符字符串,但这似乎没有出现在 UI 测试中使用
XCUIElement *element =
[[[_app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0]
childrenMatchingType:XCUIElementTypeOther].element;
Question updated with a partially working hack, by adding an UILabel, below:
我将以下代码添加到我的 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])
{
}
}
这目前是不可能的(据 Apple 工作人员说)。 https://forums.developer.apple.com/thread/25019