2012-12-09 2 views
5

xcode 4.5의 자동화를 사용하여 테스트 스크립트를 작성하려고합니다.UIACollectionView 셀과 visibleCells

저는 UICollectionView이며 현재 보이지 않는 셀을 클릭하고 싶습니다.

Per documentation, 나는 cells 컬렉션보기에 모든 세포를 반환 할 것으로 예상해야하고, 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을 사용해 보았습니다.하지만 셀을 가져야합니다. 셀에서 가져올 수 없기 때문에 셀을 사용해야합니다.

편집 : 조나단에 의해 제안

나는 스크롤까지 발견 된 기능을 구현했습니다. 구현 방법은 조금 다르므로 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; 
} 
+0

감사 : 나는 트릭을 할 것 같다 TuneUpuiautomation-ext.js에 대한 확장 등을 썼다. 훌륭하게 작동합니다. – phatmann

답변

3

설명서가 분명히 잘못되었습니다. UIACollectionView에는 visibleCells() 방법이 없습니다. 나는 모든 컬렉션 뷰 요소의 속성을 통해 반복하고 자신의 이름을 인쇄하여이 문제를 알아 낸 :

var target = UIATarget.localTarget(); 
var window = target.frontMostApp().mainWindow(); 
var collectionView = window.collectionViews()[0]; 
for (var i in collectionView) { 
    UIALogger.logMessage(i); 
} 

테이블보기 요소, 다른 한편으로는, cells() 방법으로 모든 셀을 나열 않습니다. 컬렉션 뷰의 훨씬 더 복잡한 특성으로 인해이 작업을 수행하지 않기로 결정한 것인지 궁금합니다. 실제로 모든 콜렉션 뷰 셀을 가져 와서 표현과 프레임을 작성하고 많은 요소가있는 경우 요소를 반환하는 것은 매우 비쌀 수 있습니다. 그것이 UI Automation이 모든 셀의 테이블 뷰를 요청할 때하는 일입니다. 그들은 요소 표현을 얻기 위해 모두 인스턴스화되고 계산되어야합니다.

그러나 더 큰 질문에 대답하려면 특정 셀로 스크롤하는 방법. 스 와이프 제스처로 꾸준히 스크롤 할 수 있습니까? 가장 편리한 방법은 아니며 테이블 뷰를 사용하여 눈에 보이지 않는 요소로 스크롤하는 기능으로 "망가졌습니다". 그러나 사용자 행동 테스트의 관점에서 보면 특정 금액을 스 와이프하는 것은 사용자가 어쨌든해야 할 일입니다. 이 사실을 반영하여 시험을 구성 할 수 있습니까?

+0

이 버그를 사과에 신고해야합니다 : http://bugreport.apple.com – Daniel

+0

답변을 주셔서 감사합니다.이 버그 보고서를 열었습니다 (ID : 12844375, 링크 : https://bugreport.apple.com/). cgi-bin/WebObjects/RadarWeb.woa/4/wo/LiIXHvYJovJIBFBOjSPrR0/14.66) – marmor

+0

드래그 앤 드롭을 사용하여 제안 된대로이 기능을 추가 할 수있었습니다. OP – marmor

0

@marmor dragInsideWithOptions() 비트가 일반 방식으로 작동하지 못했습니다.대신 collectionView의 value() 함수를 사용하여 "page 3 of 11"에서처럼 현재 페이지와 마지막 페이지의 색인을 얻습니다. 그런 다음 collectionView의 scrollUp() 및 scrollDown() 메서드를 사용하여 우리가 원하는 것을 찾을 때까지 페이지를 탐색합니다. 솔루션에 대한

function animationDelay() { 
    UIATarget.localTarget().delay(.2); 
} 

extend(UIACollectionView.prototype, { 
    /** 
    * Apple's bug in UIACollectionView.cells() -- only returns *visible* cells 
    */ 

    pageCount: function() { 
    var pageStatus = this.value(); 
    var words = pageStatus.split(" "); 
    var lastPage = words[3]; 
    return lastPage; 
    }, 

    currentPage: function() { 
    var pageStatus = this.value(); 
    var words = pageStatus.split(" "); 
    var currentPage = words[1]; 
    //var lastPage = words[3]; 
    return currentPage; 
    }, 

    scrollToTop: function() { 
    var current = this.currentPage(); 
    while (current != 1) { 
     this.scrollUp(); 
     animationDelay(); 
     current = this.currentPage(); 
    } 
    }, 

    scrollToBottom: function() { 
    var current = this.currentPage(); 
    var lastPage = this.pageCount(); 
    while (current != lastPage) { 
     this.scrollDown(); 
     animationDelay(); 
     current = this.currentPage(); 
    } 
    }, 

    cellCount: function() { 
    this.scrollToTop(); 
    var current = this.currentPage(); 
    var lastPage = this.pageCount(); 
    var cellCount = this.cells().length; 
    while (current != lastPage) { 
     this.scrollDown(); 
     animationDelay(); 
     current = this.currentPage(); 
     cellCount += this.cells().length; 
    } 
    return cellCount; 
    }, 

    currentPageCellNamed: function(name) { 
    var array = this.cells(); 
    for (var i = 0; i < array.length; i++) { 
     var cell = array[i]; 
     if (cell.name() == name) { 
      return cell; 
     } 
    } 
    return false; 
    }, 

    cellNamed: function(name) { 
    // for performance, look on the current page first 
    var foundCell = this.currentPageCellNamed(name); 
    if (foundCell != false) { 
     return foundCell; 
    } 
    if (this.currentPage() != 1) { 
     // scroll up and check out the first page before we iterate 
     this.scrollToTop(); 
     foundCell = this.currentPageCellNamed(name); 
     if (foundCell != false) { 
      return foundCell; 
     } 
    } 

    var current = this.currentPage(); 
    var lastPage = this.pageCount(); 
    while (current != lastPage) { 
     this.scrollDown(); 
     animationDelay(); 
     current = this.currentPage(); 

     foundCell = this.currentPageCellNamed(name); 
     if (foundCell != false) { 
      return foundCell; 
     } 
    } 
    return false; 
    }, 

    /** 
    * Asserts that this collection view has a cell with the name (accessibility identifier) 
    * matching the given +name+ argument. 
    */ 
    assertCellNamed: function(name) { 
    assertNotNull(this.cellNamed(name), "No collection cell found named '" + name + "'"); 
    } 
}); 
관련 문제