ios9 - 如何查看应用程序当前运行在哪个屏幕?

标签 ios9 xcode-ui-testing

有没有办法直接检查 XCUIApplication 当前正在运行/在屏幕上可见的屏幕?

我希望能够通过 XCT 断言应用程序当前正在显示屏幕“X”。我在想我可能只创建一个隐藏的 UIElement 或特定于每个屏幕的按钮,然后断言该元素存在于屏幕上。不过,有没有人有更优雅或更直接的方法来做到这一点?

最佳答案

  1. 创建一个 UI 标签以引用当前屏幕。
  2. 设置该 UI 标签的 accessibilityLabel,以便您可以通过 XCUIElementQuery 找到它。
  3. 设置该 UI 标签的可访问性值,以便您可以确定应用程序所处的状态/屏幕。

在应用程序代码中... UILabel *currentScreen;

self.currentScreen.accessibilityLabel = @"Current Screen";

<insert_code_to_change_state/screen_in_app>

self.currentScreen.accessibilityValue = @"<insert_current_state/screen_of_app";

在 UI 测试代码中...

XCUIElement *currentScreen = app.staticTexts[@"Current Screen"];

<insert_code_to_navigate_to_state/screen_in_app>

XCTAssert([currentScreen.value isEqualToString: @"<insert_current_state/screen_of_app"]);

关于ios9 - 如何查看应用程序当前运行在哪个屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32893636/

相关文章:

objective-c - Objective C-iCal 不在 iOS 9 中为其创建自定义日历和新事件

swift - 如何在 Safari 中打开 url 并返回到 Xcode 7 中 UITests 下的应用程序?

Swift:如何通过运行 shell 命令重置模拟器

swift - iOS 9 中的 segueForUnwindingToViewController

swift - UILabel 的 lineBreakMode 仅当 numberOfLines 不为 1 时才有意义吗?

ios - 如何从 UI 测试中的标签检索变量数据

ios - 如何从 XCUIElementQuery UITesting 获取可见单元格计数

ios - 如何从 UITests 中访问 UITabBarItem?

ios - 如何使 iOS 通用链接在 iframe 中工作

swift - 在 Xcode 7 中构建 Parse 时出现链接错误