From ab5237a7fb76cc519e46a7aa07177f4fc76d23a9 Mon Sep 17 00:00:00 2001 From: gkmo Date: Thu, 27 Oct 2016 20:41:34 -0700 Subject: [PATCH] Fix for tables where the row automation id is composed by more than 2 strings Fix for tables where the row automation id is composed by more than 2 strings. Ex: "My table row 1". The current implementation is considering as rows only if the automation id was composed by only 1 string. Ex: "row 1" --- .../Factory/TableRowFactory.cs | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/TestStack.White/Factory/TableRowFactory.cs b/src/TestStack.White/Factory/TableRowFactory.cs index 59eb5bb6..ab2b98dd 100644 --- a/src/TestStack.White/Factory/TableRowFactory.cs +++ b/src/TestStack.White/Factory/TableRowFactory.cs @@ -1,8 +1,6 @@ -using System; using System.Collections.Generic; using System.Windows.Automation; using TestStack.White.AutomationElementSearch; -using TestStack.White.Configuration; using TestStack.White.UIItems.Actions; using TestStack.White.UIItems.TableItems; @@ -10,42 +8,52 @@ namespace TestStack.White.Factory { public class TableRowFactory { - private readonly AutomationElementFinder automationElementFinder; - private static readonly Predicate RowPredicate; - private static int result; + private readonly AutomationElementFinder automationElementFinder; - static TableRowFactory() + public TableRowFactory(AutomationElementFinder automationElementFinder) { - RowPredicate = - element => - element.Current.Name.Split(' ').Length == 2 && - // row header containes no Numbers - (int.TryParse(element.Current.Name.Split(' ')[0], out result) || - int.TryParse(element.Current.Name.Split(' ')[1], out result)); + this.automationElementFinder = automationElementFinder; } - public TableRowFactory(AutomationElementFinder automationElementFinder) + public virtual int NumberOfRows { - this.automationElementFinder = automationElementFinder; + get { return GetRowElements().Count; } } public virtual TableRows CreateRows(IActionListener actionListener, TableHeader tableHeader) { - List rowElements = GetRowElements(); + var rowElements = GetRowElements(); return new TableRows(rowElements, actionListener, tableHeader, new TableCellFactory(automationElementFinder.AutomationElement, actionListener)); } private List GetRowElements() { // this will find only first level children of out element - rows - List descendants = automationElementFinder.Children(AutomationSearchCondition.ByControlType(ControlType.Custom)); - var automationElements = new List(descendants.FindAll(RowPredicate)); + var descendants = automationElementFinder.Children(AutomationSearchCondition.ByControlType(ControlType.Custom)); + var automationElements = new List(descendants.FindAll(IsRow)); return automationElements; } - public virtual int NumberOfRows + private static bool IsRow(AutomationElement element) { - get { return GetRowElements().Count; } + var parts = element.Current.Name.Split(' '); + + if (parts.Length < 2) + { + return false; + } + + int result; + + for (var i = parts.Length - 1; i >= 0; i--) + { + if (int.TryParse(parts[i], out result)) + { + return true; + } + } + + return false; } } -} \ No newline at end of file +}