コード例 #1
0
        //parse string.
        //properties is splitted by ";"
        //eg: "id=btnG;name=google".
        public static TestProperty[] GetProperties(string str)
        {
            if (str != null && !String.IsNullOrEmpty(str.Trim()))
            {
                List <TestProperty> properties = new List <TestProperty>();
                int startIndex = 0;
                int endIndex   = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c == PropertySeparator || i == str.Length - 1)
                    {
                        if (!IsEscaped(str, i))
                        {
                            endIndex = (c == PropertySeparator ? i : i + 1);
                            string propertyStr   = str.Substring(startIndex, endIndex - startIndex);
                            int    nameEndPos    = 0;
                            int    valueStartPos = 0;
                            for (int j = 0; j < propertyStr.Length; j++)
                            {
                                if (propertyStr[j] == '=' && !IsEscaped(propertyStr, j))
                                {
                                    nameEndPos    = j;
                                    valueStartPos = j + 1;
                                    break;
                                }
                            }

                            string name  = propertyStr.Substring(0, nameEndPos).Trim();
                            string value = propertyStr.Substring(valueStartPos, propertyStr.Length - valueStartPos);
                            bool   isReg = false;
                            if (String.IsNullOrEmpty(name))
                            {
                                name = TestConstants.PROPERTY_VISIBLE;
                            }
                            else
                            {
                                if (name.StartsWith(RegFlag))
                                {
                                    name  = name.Remove(0, 1);
                                    isReg = name.StartsWith(RegFlag);
                                }
                            }

                            TestProperty p = new TestProperty(name, value, isReg);
                            properties.Add(p);

                            startIndex = endIndex + 1;
                        }
                    }
                }

                return(properties.ToArray());
            }

            return(null);
        }
コード例 #2
0
        //compare wether the source list match the des condition.
        public static bool IsListMatch(List <TestProperty> source, List <TestProperty> des, bool needSort)
        {
            //test wether the other object's identify properties is the same with this object's identify properties.
            int totalWeight = 0;

            if (source != null && des != null && source.Count == des.Count)
            {
                //sort the list before compare.
                if (needSort)
                {
                    source.Sort();
                    des.Sort();
                }

                for (int i = 0; i < source.Count; i++)
                {
                    try
                    {
                        TestProperty thisPro  = source[i];
                        TestProperty otherPro = des[i];

                        //name not match, break, return false.
                        if (!thisPro.IsNameMatch(otherPro))
                        {
                            totalWeight -= thisPro.Weight;
                        }
                        else if (thisPro.IsValueMatch(otherPro))
                        {
                            totalWeight += thisPro.Weight;
                        }

                        if (thisPro.Weight == 100)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            return(totalWeight > 0);
        }
コード例 #3
0
        public int CompareTo(object obj)
        {
            if (obj != null && obj is TestProperty)
            {
                TestProperty other = (TestProperty)obj;
                //compare name
                if (String.Compare(this._name, other._name, true) != 0)
                {
                    return(String.Compare(this._name, other._name, true));
                }
                else
                {
                    String thisValue  = this._value.ToString();
                    String otherValue = other._value.ToString();

                    //compare value
                    if (String.Compare(thisValue, otherValue) != 0)
                    {
                        return(String.Compare(thisValue, otherValue));
                    }
                    else
                    {
                        //compare weight
                        if (this._weight != other._weight)
                        {
                            return(this._weight.CompareTo(other._weight));
                        }
                        else
                        {
                            //compare regex flag.
                            return(this._isRegex.CompareTo(other._isRegex));
                        }
                    }
                }
            }

            return(1);
        }
コード例 #4
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IVisible AnyObject(TestProperty[] properties)
 {
     return AnyObjects(properties)[0];
 }
コード例 #5
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
        protected virtual TestObject[] GetMapObjects(string type, TestProperty[] properties)
        {
            try
            {
                TestException exception = null;
                if (!TryGetObjectsFromPool(type, properties, out _lastObjects, out exception))
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }

                    throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), exception.ToString()));
                }
            }
            catch (TestException)
            {
                throw;
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();

                if (properties != null && properties.Length > 0)
                {
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }
                }

                throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), ex.ToString()));
            }

            return _lastObjects;
        }
コード例 #6
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IInputable[] TextBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.TextBox, properties);
     IInputable[] tmp = new IInputable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #7
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ITable[] Tables(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Table, properties);
     ITable[] tmp = new ITable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #8
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ICheckable[] RadioBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.RadioBox, properties);
     ICheckable[] tmp = new ICheckable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #9
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ISelectable[] ListBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.ListBox, properties);
     ISelectable[] tmp = new ISelectable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #10
0
ファイル: TestProperty.cs プロジェクト: coastcdl/autotester
 public bool IsValueMatch(TestProperty other)
 {
     return this._value == other._value && this._isRegex == other._isRegex;
 }
コード例 #11
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IClickable Button(TestProperty[] properties)
 {
     return Buttons(properties)[0];
 }
コード例 #12
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IVisible[] AnyObjects(string type, TestProperty[] properties)
 {
     GetMapObjects(type, properties);
     IVisible[] tmp = new IVisible[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #13
0
 public bool IsValueMatch(TestProperty other)
 {
     return(this._value == other._value && this._isRegex == other._isRegex);
 }
コード例 #14
0
ファイル: TestProperty.cs プロジェクト: coastcdl/autotester
        //parse string.
        //properties is splitted by ";"
        //eg: "id=btnG;name=google".
        public static TestProperty[] GetProperties(string str)
        {
            if (str != null && !String.IsNullOrEmpty(str.Trim()))
            {
                List<TestProperty> properties = new List<TestProperty>();
                int startIndex = 0;
                int endIndex = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c == PropertySeparator || i == str.Length - 1)
                    {
                        if (!IsEscaped(str, i))
                        {
                            endIndex = (c == PropertySeparator ? i : i + 1);
                            string propertyStr = str.Substring(startIndex, endIndex - startIndex);
                            int nameEndPos = 0;
                            int valueStartPos = 0;
                            for (int j = 0; j < propertyStr.Length; j++)
                            {
                                if (propertyStr[j] == '=' && !IsEscaped(propertyStr, j))
                                {
                                    nameEndPos = j;
                                    valueStartPos = j + 1;
                                    break;
                                }
                            }

                            string name = propertyStr.Substring(0, nameEndPos).Trim();
                            string value = propertyStr.Substring(valueStartPos, propertyStr.Length - valueStartPos);
                            bool isReg = false;
                            if (String.IsNullOrEmpty(name))
                            {
                                name = TestConstants.PROPERTY_VISIBLE;
                            }
                            else
                            {
                                if (name.StartsWith(RegFlag))
                                {
                                    name = name.Remove(0, 1);
                                    isReg = name.StartsWith(RegFlag);
                                }
                            }

                            TestProperty p = new TestProperty(name, value, isReg);
                            properties.Add(p);

                            startIndex = endIndex + 1;
                        }
                    }
                }

                return properties.ToArray();
            }

            return null;
        }
コード例 #15
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ICheckable CheckBox(TestProperty[] propertiese)
 {
     return CheckBoxs(propertiese)[0];
 }
コード例 #16
0
ファイル: TestProperty.cs プロジェクト: coastcdl/autotester
 public bool IsMatch(TestProperty other)
 {
     return String.Compare(this._name, other._name) == 0 && this._value == other._value &&
            this._isRegex == other._isRegex && this._weight == other._weight;
 }
コード例 #17
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ISelectable DropList(TestProperty[] properties)
 {
     return DropLists(properties)[0];
 }
コード例 #18
0
 public bool IsNameMatch(TestProperty other)
 {
     return(String.Compare(this._name, other._name, true) == 0);
 }
コード例 #19
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IPicture Image(TestProperty[] properties)
 {
     return Images(properties)[0];
 }
コード例 #20
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ICheckable RadioBox(TestProperty[] properties)
 {
     return RadioBoxs(properties)[0];
 }
コード例 #21
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IPicture[] Images(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Image, properties);
     IPicture[] tmp = new IPicture[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #22
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ITable Table(TestProperty[] properties)
 {
     return Tables(properties)[0];
 }
コード例 #23
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual bool IsExist(TestProperty[] properties)
 {
     TestObject[] tmps;
     return TryGetObjects(null, properties, out tmps);
 }
コード例 #24
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IInputable TextBox(TestProperty[] properties)
 {
     return TextBoxs(properties)[0];
 }
コード例 #25
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual bool IsExist(String type, TestProperty[] properties)
 {
     TestObject[] tmps;
     return TryGetObjects(type, properties, out tmps);
 }
コード例 #26
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual bool TryGetObjects(String type, TestProperty[] properties, out TestObject[] objects)
 {
     objects = null;
     try
     {
         objects = GetMapObjects(type, properties);
         return objects != null;
     }
     catch
     {
         return false;
     }
 }
コード例 #27
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IText Label(TestProperty[] properties)
 {
     return Labels(properties)[0];
 }
コード例 #28
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
        private bool TryGetObjectsFromPool(string type, TestProperty[] properties, out TestObject[] obj, out TestException exception)
        {
            obj = null;
            exception = null;

            int currentTimeout = _timeout;
            int oriTimeout = this._objPool.SearchTimeout;
            this._objPool.SearchTimeout = currentTimeout;

            try
            {
                if (String.IsNullOrEmpty(type))
                {
                    if (properties == null || properties.Length == 0)
                    {
                        obj = this._objPool.GetAllObjects();
                    }
                    else
                    {
                        obj = this._objPool.GetObjectsByProperties(properties);
                    }
                }
                else
                {
                    obj = this._objPool.GetObjectsByType(type, properties);
                }

                return obj != null;
            }
            catch (TestException ex)
            {
                exception = ex;
                return false;
            }
            finally
            {
                this._objPool.SearchTimeout = oriTimeout;
            }
        }
コード例 #29
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IText[] Labels(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Label, properties);
     IText[] tmp = new IText[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #30
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IVisible AnyObject(string type, TestProperty[] properties)
 {
     return AnyObjects(type, properties)[0];
 }
コード例 #31
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IClickable Link(TestProperty[] properties)
 {
     return Links(properties)[0];
 }
コード例 #32
0
ファイル: TestProperty.cs プロジェクト: coastcdl/autotester
        public static bool TryGetProperties(string str, out TestProperty[] properties)
        {
            bool res = false;
            properties = null;
            if (str != null && !String.IsNullOrEmpty(str.Trim()) && str.IndexOf("=") > 0)
            {
                try
                {
                    properties = GetProperties(str);
                    return properties != null;
                }
                catch
                {
                    res = false;
                }
            }

            return res;
        }
コード例 #33
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual IClickable[] Links(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Link, properties);
     IClickable[] tmp = new IClickable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
コード例 #34
0
ファイル: TestProperty.cs プロジェクト: coastcdl/autotester
 public bool IsNameMatch(TestProperty other)
 {
     return String.Compare(this._name, other._name, true) == 0;
 }
コード例 #35
0
ファイル: TestObjectMap.cs プロジェクト: coastcdl/autotester
 public virtual ISelectable ListBox(TestProperty[] properties)
 {
     return ListBoxs(properties)[0];
 }
コード例 #36
0
ファイル: TestObjectMap.cs プロジェクト: zergmk2/autotester-1
 protected virtual TestObject[] GetMapObjects(string type, String description)
 {
     TestProperty[] properties = TestProperty.GetProperties(description);
     return GetMapObjects(type, properties);
 }
コード例 #37
0
 public bool IsMatch(TestProperty other)
 {
     return(String.Compare(this._name, other._name) == 0 && this._value == other._value &&
            this._isRegex == other._isRegex && this._weight == other._weight);
 }