在许多mac中运行UIAutomation脚本?

时间:2013-12-13 07:54:12

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

我可以在Mac使用中很好地创建和重播以下脚本。

  var target = UIATarget.localTarget();

  UIATarget.localTarget().delay(15);

  target.frontMostApp().mainWindow().tableViews()[0].textFields()[0].tap();

当我在另一个mac中运行上面的脚本时,它在第3行显示错误。 在更改了上面脚本的第三行之后,它正在重播。

  target.frontMostApp().mainWindow().tableViews()[1].textFields()[0].tap();

我刚将tableview的索引从0更改为1.如何在多个中实现此目的 mac系统?两个mac都有相同的xcode版本(xcode 5)和模拟器版本(6.1)和mac版本。为什么Instruments在不同的mac中采用不同的脚本API?

1 个答案:

答案 0 :(得分:1)

为了获得更一致的结果,其中一种方法可以是按名称(或其他标识符/预期内容/包含的单元格数等)访问AX元素。例如,Trouble Getting Elements by Name from UIAElementArray in UIAutomation这样的问题以及关于如何以不同方式设置元素名称的相应讨论。

例如:

var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
tableViews['TableView'].textFields()[0].tap();

var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
tableViews['TableView'].textFields.withName("TextFieldName")[0].tap();

如果使用名称不可行则可以分析表格的内容并根据右表格进行选择。例如,如果表中有一些名为“Cell name”的单元格:

var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
var tableViews = mainWindow.tableViews();
if (tableViews[0].cells().firstWithName("Cell name")) {
    tableViews[0].textFields()[0].tap();
} else if (tableViews[1].cells().firstWithName("Cell name")) {
    tableViews[1].textFields()[0].tap();
}

有关在tableView中识别单元格的更多详细信息,例如在问题UIACollectionView cells vs visibleCells中这看起来不太好但是它可以是合理的解决方法并且应该非常可靠。如果这些表格中的单元格数量已知且不同,则可以比较单元格数量以找到所需的表格。

相关问题