我正在尝试使用 xcode 4.5 中的自动化编写测试脚本。
我有一个UICollectionView
我想单击一些当前不可见的单元格。
根据文档 http://developer.apple.com/library/ios/#documentation/UIAutomation/Reference/UIACollectionViewClassReference/UIACollectionViews/UIACollectionViews.html,我应该期待cells
回来all集合视图中的单元格,以及visibleCells
仅返回当前可见的。
相反,我看到的是单元格仅返回当前可见的单元格,并且调用visibleCells会停止脚本'undefined' is not a function (evaluating 'collection.visibleCells()')
var target = UIATarget.localTarget();
var collection = target.frontMostApp().mainWindow().collectionViews()[0];
UIALogger.logMessage("Looking in collection: " + collection);
UIALogger.logMessage("Cells: " + collection.cells() + " length " + collection.cells().length);
UIALogger.logMessage("Visible cells: " + collection.visibleCells());
上面的代码返回正确的UICollectionView
,第二条日志行打印:
Cells: [object UIAElementArray] length 12
尽管我在集合视图中有 100 个项目,但第三条日志行使脚本崩溃。
这是文档/UIACollectionView 错误吗?
有什么想法如何让自动化滚动,直到看到名称为“我的单元格”的单元格?
我尝试过使用someCell.scrollToVisible
,但我需要有细胞才能做到这一点,但我没有,因为我无法从细胞中获取它。
EDIT:
正如乔纳森所建议的,我已经实现了滚动直到找到的功能。
它有点特定于实现,所以你可能需要调整isCellWithName
。
我还希望添加一个中断,以防我们在 while 循环中找不到所需的单元格,如果有人有想法,请随意编辑它。
function isCellWithName(cell, name) {
return (cell.staticTexts()[0].name() == name);
}
function getCellWithName(array, name) {
for (var i = 0; i < array.length; i++) {
if (isCellWithName(array[i], name)) {
return array[i];
}
}
return false;
}
function scrollToName(collection, name) {
var found = getCellWithName(collection.cells(), name);
while (found === false) {
collection.dragInsideWithOptions({startOffset:{x:0.2, y:0.99}, endOffset:{x:0.2, y:0},duration:1.0});
found = getCellWithName(collection.cells(), name);
}
return found;
}