【问题标题】:Read the value of a UILabel in Automation template of Instruments in Xcode在 Xcode 中的 Instruments 自动化模板中读取 UILabel 的值
【发布时间】:2016-04-11 13:12:45
【问题描述】:

我编写了以下脚本来点击 UI 上的按钮。每次按下都会增加 UILabel 的整数值。我希望在我的脚本中读取 UILabel 的值。我怎样才能做到这一点?我是 Instruments 中这个自动化工具的新手。

var target = UIATarget.localTarget();
var appName = target.frontMostApp().mainWindow().name;
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
target.frontMostApp().mainWindow().buttons()["Increment"].tap();

【问题讨论】:

  • 无法直接帮助您解决问题。但如果您这样做是为了测试,我建议您尝试新的 UI 测试框架,它是 Apple 的 XCTest 的一部分。您可能会发现它比旧的 UI 自动化工具更易于使用。
  • 我认为 XCTest 是用于单元测试的。我不知道您可以使用 XCTest 进行 UI 测试。
  • XCTest 已显着增强,支持启动应用程序和询问其界面。现在在项目中使用它后,我认为它与我在 Frank 或 Calabash 中编写测试的方式非常相似,但没有 Cucumber BDD 前端。苹果仍然可以将大量功能打包到其中。但总的来说,我会说这是一个可行的选择。

标签: ios xcode ios-ui-automation xcode-instruments


【解决方案1】:

首先确保您为该 UILabel 分配了可访问性标识符。

您可以通过代码做到这一点:

self.myLabel.accessibilityIdentifier = @"uniqueId";

或通过故事板:

要获取标签值,请在 UIAutomation 脚本中使用以下行:

target.frontMostApp().mainWindow().staticTexts()["uniqueId"].value();

【讨论】:

    猜你喜欢
    • 2016-12-15
    • 2013-11-10
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2014-08-17
    • 2013-12-22
    • 2016-03-07
    • 2019-02-27
    相关资源
    最近更新 更多