2012-12-09 16 views
5

मैं xcode 4.5 में स्वचालन का उपयोग कर एक टेस्ट स्क्रिप्ट लिखने की कोशिश कर रहा हूं।UIACollectionView कोशिकाओं बनाम दृश्यमान

मेरे पास 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 को ट्वीक करने की आवश्यकता होगी। अगर हम किसी भी विचार के बारे में सोचते हैं, तो इसे संपादित करने में संकोच न करें, अगर हम थोड़ी देर में आवश्यक सेल नहीं मिला तो मैं भी एक ब्रेक जोड़ना चाहता हूं।

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

धन्यवाद: मुझे लगता है कि चाल करने के लिए लग रहे हैं TuneUp के uiautomation-ext.js के लिए एक विस्तार है, और अधिक लिखा था। बहुत अच्छा काम करता है। – phatmann

उत्तर

3

दस्तावेज़ीकरण स्पष्ट रूप से गलत है। पर UIACollectionView पर कोई विधि नहीं है। मैं सभी संग्रह दृश्य तत्वों के गुण अधिक पाशन और उनके नाम को प्रिंट करके इस पता लगा:

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

तालिका दृश्य तत्वों, दूसरे हाथ पर, cells() विधि के साथ सभी कोशिकाओं की सूची है। मैं सोच रहा हूं कि क्या वे संग्रह दृश्यों की अधिक जटिल प्रकृति के कारण ऐसा नहीं करना चुनते हैं। वास्तव में सभी संग्रह दृश्य कक्षों को लाने, उनके प्रतिनिधित्व और फ्रेम बनाने के लिए बहुत महंगा हो सकता है, और तत्वों को वापस कर सकते हैं यदि आपके पास उनमें से बहुत कुछ था। यूआई ऑटोमेशन तब होता है जब यह सभी कोशिकाओं के लिए टेबल दृश्य पूछता है। तत्वों के प्रतिनिधित्व प्राप्त करने के लिए उन्हें सभी को तत्काल और गणना की जानी चाहिए।

लेकिन, अपने बड़े प्रश्न का उत्तर देने के लिए, किसी विशिष्ट सेल पर स्क्रॉल कैसे करें। क्या आप इसे एक स्वाइप इशारा के साथ लगातार देख सकते हैं? यह करने का सबसे सुविधाजनक तरीका नहीं है और हम टेबल दृश्यों वाले गैर-दृश्य तत्वों तक स्क्रॉल करने की क्षमता से "खराब" हैं। लेकिन उपयोगकर्ता व्यवहार परीक्षण दृष्टिकोण से, एक निश्चित राशि को स्वाइप करना वह है जो उपयोगकर्ता को वैसे भी करना होगा। क्या परीक्षण को प्रतिबिंबित करने के लिए संरचित किया जा सकता है और क्या यह आपकी आवश्यकता को संबोधित करेगा?

+0

आपको इस बग को सेब में रिपोर्ट करनी चाहिए: http://bugreport.apple.com – Daniel

+0

उत्तर के लिए धन्यवाद, मैंने इसके लिए एक बग रिपोर्ट खोली है (आईडी: 12844375, लिंक: https://bugreport.apple.com/ cgi-bin/webObjects/RadarWeb.woa/4/wo/LiIXHvYJovJIBFBOjSPrR0/14.66) – marmor

+0

मैंने ड्रैग-एंड-ड्रॉप का उपयोग करके सुझाए गए अनुसार इस कार्यक्षमता को जोड़ने में कामयाब रहा है, ओपी – marmor

0

मुझे एक सामान्य फैशन में काम करने के लिए @marmor dragInsideWithOptions() बिट नहीं मिल सका।इसके बजाए, मैं वर्तमान पृष्ठ बनाम अंतिम पृष्ठ की अनुक्रमणिका प्राप्त करने के लिए संग्रह दृश्य का मूल्य() फ़ंक्शन का उपयोग कर रहा हूं, जैसा कि "पृष्ठ 3 में से 11" में है। तब मैं पृष्ठों के माध्यम से चलने के लिए संग्रह दृश्य के स्क्रॉलअप() और 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 + "'"); 
    } 
}); 
संबंधित मुद्दे