2012-01-31 15 views
5

मुझे एक विनफॉर्म एप्लिकेशन में एक ग्रिड (फ्लेक्सग्रिड, कंपोनेंटऑन से) मिला है और मैं सेल के कॉलम इंडेक्स और उसके मान को देखते हुए उस ग्रिड में एक सेल ढूंढने की कोशिश कर रहा हूं।कोडेडयूआई: सेल इतनी धीमी क्यों खोज रही है?

मैंने ग्रिड के माध्यम से लूप को नीचे विस्तार विधि लिखा है और उस सेल को ढूंढ लिया है।

मैं उस विधि को उस ग्रिड पर परीक्षण कर रहा हूं जिसमें 6 कॉलम और 64 पंक्तियां हैं। मेरे कोड के लिए सही सेल (जो अंतिम पंक्ति पर था) को खोजने में 10 मिनट लग गए।

क्या कोई तरीका है कि मैं अपना एल्गोरिदम बढ़ा सकता हूं?

नोट: मैं भी TopLevelWindow को PlayBack.PlayBackSetting.SmartMatchOption स्थापित करने की कोशिश की है, लेकिन यह कुछ भी बदलने नहीं लगता है ...

धन्यवाद!

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue) 
    { 

     int count = table.GetChildren().Count; 
     for (int rowIndex = 0; rowIndex < count; rowIndex++) 
     { 
      WinRow row = new WinRow(table); 
      WinCell cell = new WinCell(row); 
      row.SearchProperties.Add(WinRow.PropertyNames.RowIndex, rowIndex.ToString()); 
      cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 

      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      if (cell.Exists) 
       return cell; 
     } 

     return new WinCell(); 
    } 

संपादित

मैं नीचे की तरह बनना मेरी विधि (उदा। मैं winrow अब और का उपयोग नहीं करते) को संशोधित किया, इस तेजी से 3x चारों ओर हो रहा है। इसे अभी भी 3 पंक्तियों और 6 कॉलम वाली तालिका में सेल खोजने के लिए 7 सेकंड की आवश्यकता है, इसलिए यह अभी भी धीमा है ...

मैं इस उत्तर को अन्य लोगों को सुझाव देने के लिए समय के बाद स्वीकार कर दूंगा कुछ बेहतर

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 
     Playback.PlaybackSettings.SmartMatchOptions = Microsoft.VisualStudio.TestTools.UITest.Extension.SmartMatchOptions.None; 
     int count = table.GetChildren().Count; 
     for (int rowIndex = 0; rowIndex < count; rowIndex++) 
     { 
      WinCell cell = new WinCell(table); 

      cell.SearchProperties.Add(WinRow.PropertyNames.RowIndex, rowIndex.ToString()); 
      cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 


      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      if (cell.Exists) 
       return cell; 
     } 

     return new WinCell(); 
    } 

संपादित # 2: मैं अनुसार @ एंड्री के सुझाव FindMatchingControls उपयोग करने की कोशिश की है, और मैं लगभग वहाँ (c.ColumnIndex) कर रहा हूँ, कि सेल के स्तंभ अनुक्रमणिका नीचे कोड को छोड़कर गलत मूल्य है ..

public static WinCell FindCellByColumnAndValue2(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 

     WinRow row = new WinRow(table); 
     //Filter rows containing the wanted value 
     row.SearchProperties.Add(new PropertyExpression(WinRow.PropertyNames.Value, strCellValue, PropertyExpressionOperator.Contains)); 
     var rows = row.FindMatchingControls(); 
     foreach (var r in rows) 
     { 
      WinCell cell = new WinCell(r); 
      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      //Filter cells with the wanted value in the current row 
      var controls = cell.FindMatchingControls(); 
      foreach (var ctl in controls) 
      { 
       var c = ctl as WinCell; 
       if (c.ColumnIndex == colIndex)//ERROR: The only cell in my table with the correct value returns a column index of 2, instead of 0 (being in the first cell) 
        return c; 
      } 
     } 
     return new WinCell(); 
    } 
+0

विक्रेता से संपर्क करें। – leppie

+0

मैं सहमत हूं कि [यूआई ऑटोमेशन परीक्षण] (http://social.msdn.microsoft.com/Forums/da/vsautotest/threads) एमएसडीएन मंचों के अनुभाग में वे आमतौर पर कोडित यूआई प्रश्नों के लिए काफी व्यापक उत्तर प्रदान करते हैं। –

+0

@leppie: हाँ, मैंने अपने मंच पर एक संदेश पोस्ट किया है, मैं बस उत्तर देने का इंतजार कर रहा हूं – David

उत्तर

6

मैं बाल नियंत्रण के माध्यम से प्रत्यक्ष लूपिंग करने का सुझाव दूंगा - मेरे अनुभव के अनुसार कोडित यूआई में जटिल खोज क्रिएटोरिया के साथ खोज नियंत्रण अक्सर धीमा काम करता है।

संपादित करें:

प्रदर्शन में सुधार करने के लिए यह बेहतर है उनकी गिनती तालिका के बच्चों और पंक्तियों के माध्यम से पाशन दूर करने के लिए। जब पंक्ति संख्या के बिना नियंत्रण पाने के अलावा अपवाद से बचने के लिए आप निम्न में FindMatchingControls विधि का उपयोग कर सकते हैं, जैसे:

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 
     Playback.PlaybackSettings.SmartMatchOptions = Microsoft.VisualStudio.TestTools.UITest.Extension.SmartMatchOptions.None; 

     WinCell cell = new WinCell(table); 
     cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 
     cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 

     UITestControlCollection foundControls = cell.FindMatchingControls(); 
     if (foundControls.Count > 0) 
     { 
      cell = foundControls.List[0]; 
     } 
     else 
     { 
      cell = null; 
     } 

     return cell; 
    } 

जब तालिका फ़ील्ड को सीधे तालिका में खोज की जाएगी तब वह तालिका में बच्चे नियंत्रण की गिनती के लिए समय बचेगा। for लूप के बिना खोज भी पंक्ति संख्या के प्रत्येक पुनरावृत्ति के लिए फ़ील्ड की खोज के लिए समय बचाएगा जो मेल नहीं खाता है।

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

+0

मान लें कि टेबल का उपयोग करने का मतलब है। गेटचिल्डेन(), यह भी है मेरे लिए धीमा :( – David

+1

हाँ, मैंने पहले से ही कोशिश की थी, लेकिन मुझे निम्न त्रुटि मिल रही है सिस्टम। ऑर्ग्यूमेंट अपवाद: नियंत्रण के लिए खोज कंटेनर के रूप में कोई पंक्ति निर्दिष्ट नहीं की गई थी। 'कॉलम इंडेक्स' का उपयोग करके सेल नियंत्रण की खोज करने के लिए ', आपको पंक्ति को कंटेनर तत्व के रूप में निर्दिष्ट करना होगा या सेल की खोज संपत्ति में' रोइंडेक्स 'जोड़ना होगा। पैरामीटर नाम: सर्चप्रॉपर्टीज यही कारण है कि मैं अभी भी पंक्तियों का उपयोग कर रहा हूं – David

+0

@ डेविड क्या आपने केवल पंक्ति उदाहरण के साथ खोज करने की कोशिश की है निर्दिष्ट - बिना किसी पंक्ति संख्या के? –

संबंधित मुद्दे