【问题标题】:XCUItest: Detect current SKViewXCUItest:检测当前的 SKView
【发布时间】: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


    【解决方案1】:

    目前这是不可能的(根据 Apple 工作人员的说法)。 https://forums.developer.apple.com/thread/25019

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 2020-01-05
      • 1970-01-01
      • 2014-04-12
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多